Created
October 24, 2012 12:56
-
-
Save iiska/3945903 to your computer and use it in GitHub Desktop.
Convert sample.jtl to csv
This file contains hidden or 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 | |
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