Skip to content

Instantly share code, notes, and snippets.

@iiska
Created October 24, 2012 12:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save iiska/3945903 to your computer and use it in GitHub Desktop.
Save iiska/3945903 to your computer and use it in GitHub Desktop.
Convert sample.jtl to csv
#! /usr/bin/env python
from xml.etree import ElementTree
from xml.sax.handler import ContentHandler
from xml.sax import parse
import csv
class Converter(ContentHandler):
def __init__(self, csv_filename):
self.output_file = open(csv_filename, 'w')
self.csv_writer = csv.DictWriter(self.output_file, ['lb','s', 'ec', 'hn', 'in', 'dt', 'by', 'na', 'ts', 'ng', 'tn', 'lt', 't', 'rc', 'sc', 'rm'])
def __del__(self):
self.output_file.close()
def startDocument(self):
self.csv_writer.writeheader()
def startElement(self, name, attrs):
if name == 'httpSample':
adict = {}
for name in attrs.getNames():
adict[name] = attrs.getValue(name)
self.csv_writer.writerow(adict)
def main(filename):
parse(filename, Converter("%s.csv" % (filename)))
if __name__ == '__main__':
import sys
#try:
main(sys.argv[1])
#except:
# print("\nUsage: %s input_file" % (sys.argv[0]))
# print("\n Input file should contain http samples created by JMeter in JTL format.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment