#!/usr/bin/python
"""
Description : Split JTL file into a Simple Data Writer Log
by : Oliver Erlewein (c)2008 - hacked by infernix to convert to SDW log instead of CSV
Date : 04.02.2008 - 24-3-2008
Lang : Python 2.4+
JMeter JTL field contents:
Attribute & Content
by Bytes
de Data encoding
dt Data type
ec Error count (0 or 1, unless multiple samples are aggregated)
hn Hostname where the sample was generated
lb Label
lt Latency = time to initial response (milliseconds) - not all samplers support this
na Number of active threads for all thread groups
ng Number of active threads in this group
rc Response Code (e.g. 200)
rm Response Message (e.g. OK)
s Success flag (true/false)
sc Sample count (1, unless multiple samples are aggregated)
t Elapsed time (milliseconds)
tn Thread Name
ts timeStamp (milliseconds since midnight Jan 1, 1970 UTC)
"""
import sys
import string
import re
import datetime
import time
startTime = time.time()
cnt = 0
cnt2 = 0
failCnt = 0
reCompile = re.compile("\s([^\s]*?)=\"(.*?)\"")
delimiterCharacterOut = ","
def writeCSVLine(line):
x = reCompile.findall(line)
a = dict((row[0], row[1]) for row in x)
try:
b = a['ts'] + "," + a['t'] + "," + a['lb'] + "," + a['rc'] + "," + a['rm'] + "," + a['tn'] + "," + a['dt'] + "," + a['s'] + "," + a['by'] + "," + a['by'] + "\n"
except:
return -1
o.write(b)
return 1
print "Splitting JTL file"
try:
runArgv = sys.argv # Save the command line
jtlInfile = str(sys.argv[1]) # Name of JTL input file
cvsOutfile = str(sys.argv[2]) # Name of CVS output file
reFilter = str(sys.argv[3]) # Filter the labels (lb) for the filter
except:
print "Error: Input format: