Last active
April 12, 2021 23:03
-
-
Save tomdottom/b017244a221f8076c4b0adc6feeeb921 to your computer and use it in GitHub Desktop.
A quick script to convert JMeter log XML files to CSV file. Tries to create csv in same column order as jmeter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Python version of https://gist.github.com/tonycoco/661615 | |
import csv | |
import sys | |
import untangle | |
usage = ''' | |
Usage: | |
python foo.py source_xml_file target_csv_file | |
''' | |
try: | |
xml_file = sys.argv[1] | |
csv_file = sys.argv[2] | |
except IndexError: | |
print(usage) | |
sys.exit(1) | |
# http://jmeter.apache.org/usermanual/listeners.html#attributes | |
name_map = dict([ | |
('ts', 'timeStamp'), | |
('t', 'elapsed'), | |
('lb', 'label'), | |
('rc', 'responseCode'), | |
('rm', 'responseMessage'), | |
('tn', 'threadName'), | |
('dt', 'dataType'), | |
('s', 'success'), | |
('by', 'bytes'), | |
('ng', 'grpThreads'), | |
('na', 'allThreads'), | |
('lt', 'Latency'), | |
('it', 'IdleTime') | |
]) | |
obj = untangle.parse(xml_file) | |
samples = [ | |
{name_map.get(k, k):v for k, v in sample._attributes.items()} | |
for sample in obj.testResults.httpSample | |
] | |
#fieldnames = samples[0].keys() + ['failureMessage'] | |
fieldnames = [ | |
'timeStamp','elapsed','label','responseCode', | |
'responseMessage','threadName','dataType','success', | |
'failureMessage','bytes','grpThreads','allThreads','Latency','IdleTime'] | |
with open(csv_file, 'w+') as fd: | |
writer = csv.DictWriter(fd, fieldnames) | |
writer.writeheader() | |
writer.writerows(samples) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment