3
from __future__ import absolute_import, division, print_function, unicode_literals
11
def parse_command_line():
12
parser = argparse.ArgumentParser (description='Extract data from specified skel output file')
13
parser.add_argument ('skel_output', metavar='Skel result', help='file to extract data from')
14
parser.add_argument ('-d', dest='dest', help='file to place the results in')
15
parser.add_argument ('-s', dest='select', help='measurement(s) to extract (default = *)')
16
parser.add_argument ('-r', dest='ranks', default='0', help='Use -r all to include measurements from all ranks for just one iteration.')
17
parser.add_argument ('-R', dest='generate_R', action="store_true", default=False, help='Extract into a form to be read by R.')
18
return parser.parse_args()
23
# By default, print all data for rank 0 as one line, repeat for each iteration
24
def extract (skel_output, dest, select, ranks):
26
doc = xml.dom.minidom.parse (skel_output)
27
if dest == None or dest == '':
30
outfile = open (dest, 'w')
32
if select == None or select == '':
35
keys = doc.getElementsByTagName('adios_timing')[0].getAttribute('keys').split(',')
38
tempkeys.append (key.strip())
43
selected_fields = keys
45
selected_fields = select.split(',')
47
# check the selected fields
48
for field in selected_fields:
50
print('Invalid selection, field ' + field)
55
for field in selected_fields:
56
header = header + field
59
header = header.rstrip (',')
60
outfile.write (header + '\n')
62
for st in doc.getElementsByTagName ('adios_timing'):
65
for proc in st.getElementsByTagName('proc'):
66
if proc.getAttribute ('id') == '0' or ranks == 'all':
68
vals = proc.getAttribute ('vals').split(',')
69
for field in selected_fields:
70
data = data + vals[keys.index(field)].strip() + ','
71
data = data.rstrip (',') + '\n'
80
# Hilde's function for extracting to a format understood by the R script
81
def extract_R (skel_output, select, ranks):
83
doc = xml.dom.minidom.parse (skel_output)
84
#if dest == None or dest == '':
85
# outfile = sys.stdout
87
outfile = open (skel_output+".txt", 'w')
88
#runval=dest.split('.')[0].split('_')[1]
89
#outfile.write ("runid = " +runval +'\n')
91
if select == None or select == '':
97
method = doc.getElementsByTagName('adios_timing')[0].getAttribute('method')
99
keys = doc.getElementsByTagName('adios_timing')[0].getAttribute('keys').split(',')
102
tempkeys.append (key.strip())
106
numcores= doc.getElementsByTagName('adios_timing')[0].getAttribute('cores')
109
selected_fields = keys
111
selected_fields = select.split(',')
113
# check the selected fields
114
for field in selected_fields:
115
if not field in keys:
116
print('Invalid selection, field ' + field)
121
for field in selected_fields:
122
header = header + field
125
header = "Iteration "+"Core "+header.rstrip (' ')
126
outfile.write (method + '\n')
127
outfile.write (numcores +'\n')
128
outfile.write (header + '\n')
131
for st in doc.getElementsByTagName ('adios_timing'):
134
for proc in st.getElementsByTagName('proc'):
135
if proc.getAttribute ('id') == '0':
138
core = proc.getAttribute ('id')
139
vals = proc.getAttribute ('vals').split(',')
140
for field in selected_fields:
141
data = data + vals[keys.index(field)].strip(',')
142
data = str(iter)+" "+ core +" "+ data.rstrip (' ') + '\n'
157
args = parse_command_line()
158
if (args.generate_R):
159
extract_R (args.skel_output, args.select, args.ranks)
161
extract (args.skel_output, args.dest, args.select, args.ranks)
165
if __name__ == "__main__":