/usr/bin/skel_extract is in libadios-bin 1.13.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #! /usr/bin/python
import argparse
import xml.dom.minidom
import sys
#import skel_settings
def parse_command_line():
parser = argparse.ArgumentParser (description='Extract data from specified skel output file')
parser.add_argument ('skel_output', metavar='Skel result', help='file to extract data from')
parser.add_argument ('-d', dest='dest', help='file to place the results in')
parser.add_argument ('-s', dest='select', help='measurement(s) to extract (default = *)')
parser.add_argument ('-r', dest='ranks', default='0', help='Use -r all to include measurements from all ranks for just one iteration.')
parser.add_argument ('-R', dest='generate_R', action="store_true", default=False, help='Extract into a form to be read by R.')
return parser.parse_args()
# By default, print all data for rank 0 as one line, repeat for each iteration
def extract (skel_output, dest, select, ranks):
doc = xml.dom.minidom.parse (skel_output)
if dest == None or dest == '':
outfile = sys.stdout
else:
outfile = open (dest, 'w')
if select == None or select == '':
select = '*'
keys = doc.getElementsByTagName('adios_timing')[0].getAttribute('keys').split(',')
tempkeys = []
for key in keys:
tempkeys.append (key.strip())
keys = tempkeys
if select == '*':
selected_fields = keys
else:
selected_fields = select.split(',')
# check the selected fields
for field in selected_fields:
if not field in keys:
print 'Invalid selection, field ' + field
return
#Print the header
header = ''
for field in selected_fields:
header = header + field
header = header +','
header = header.rstrip (',')
outfile.write (header + '\n')
for st in doc.getElementsByTagName ('adios_timing'):
#Print the data
for proc in st.getElementsByTagName('proc'):
if proc.getAttribute ('id') == '0' or ranks == 'all':
data = ''
vals = proc.getAttribute ('vals').split(',')
for field in selected_fields:
data = data + vals[keys.index(field)].strip() + ','
data = data.rstrip (',') + '\n'
outfile.write (data)
if ranks == 'all':
break
outfile.close ()
# Hilde's function for extracting to a format understood by the R script
def extract_R (skel_output, select, ranks, iteration):
doc = xml.dom.minidom.parse (skel_output)
#if dest == None or dest == '':
# outfile = sys.stdout
#else:
outfile = open (skel_output+".txt", 'w')
#runval=dest.split('.')[0].split('_')[1]
#outfile.write ("runid = " +runval +'\n')
if select == None or select == '':
select = '*'
method = doc.getElementsByTagName('adios_timing')[0].getAttribute('method')
keys = doc.getElementsByTagName('adios_timing')[0].getAttribute('keys').split(',')
tempkeys = []
for key in keys:
tempkeys.append (key.strip())
keys = tempkeys
numcores= doc.getElementsByTagName('adios_timing')[0].getAttribute('cores')
if select == '*':
selected_fields = keys
else:
selected_fields = select.split(',')
# check the selected fields
for field in selected_fields:
if not field in keys:
print 'Invalid selection, field ' + field
return
#Print the header
header = ''
for field in selected_fields:
header = header + field
header = header +' '
header = "Iteration "+"Core "+header.rstrip (' ')
outfile.write (method + '\n')
outfile.write (numcores +'\n')
outfile.write (header + '\n')
# Replacing iter with the iteration argument passed in
iter = 0
for st in doc.getElementsByTagName ('adios_timing'):
#Print the data
for proc in st.getElementsByTagName('proc'):
if proc.getAttribute ('id') == '0':
iter = iter +1
data = ''
core = proc.getAttribute ('id')
vals = proc.getAttribute ('vals').split(',')
for field in selected_fields:
data = data + vals[keys.index(field)].strip(',') + ' '
data = str(iteration)+" "+ core +" "+ data.rstrip (' ') + '\n'
outfile.write (data)
if ranks == 'all':
break
outfile.close ()
def parse_iteration (filename):
#assume filename ends with .xml
if not filename.endswith (".xml"):
print "Warning: filename does not meet expectations, should end with .xml"
filename = filename [:-4]
iteration = filename.rsplit ("_", 1)[1]
print iteration
return iteration
def main ():
args = parse_command_line()
if (args.generate_R):
iteration = parse_iteration (args.skel_output)
extract_R (args.skel_output, args.select, args.ranks, iteration)
else:
extract (args.skel_output, args.dest, args.select, args.ranks)
if __name__ == "__main__":
main()
|