-
Notifications
You must be signed in to change notification settings - Fork 10
/
genAggregateRepsTimesPercentilesReports.py
executable file
·94 lines (85 loc) · 3.11 KB
/
genAggregateRepsTimesPercentilesReports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python
#
################################################################################
# Description: transposes a aggregate response times CSV file into a CSV file
# where percentiles are colums.
#
# Example input aggregate response times CSV file:
# Percentiles,GET PATH
# 50.0,7188.0
# 60.0,7300.0
# 70.0,7452.0
# 80.0,7749.0
# 90.0,8299.0
# 95.0,8836.0
#
# Example output file (output filename GETPATHRespTimesPercentiles.csv)
# 50.0,60.0,70.0,80.0,90.0,95.0
# 7188.0,7300.0,7452.0,7749.0,8299.0,8836.0
#
# Please notice that it took the second column name and used it as the filename
# of the output file.
#
# The input file is generated by jmeter-ec2.sh script from a CSV file that is
# generated using the Reporter tool available in the CMRRunner.
# "java -Djava.awt.headless=true -jar CMDRunner.jar --tool Reporter \
# --generate-csv ResponseTimesPercentiles.csv --input-jtl result_file.jtl \
# --plugin-type ResponseTimesPercentiles"
#
################################################################################
__author__ = 'nixCraft + Janusz Kowalczyk'
import csv
import sys, getopt
import re
# Store input and output file names
ifile='aggregatedResponseTimesPercentiles.csv'
ofolder='./'
debug=False
# Read command line args
myopts, args = getopt.getopt(sys.argv[1:],"i:o:d")
###############################
# o == option
# a == argument passed to the o
###############################
for o, a in myopts:
if o == '-i':
ifile=a
elif o == '-o':
ofolder=a
elif o == '-d':
debug=True
print "Debug mode - enabled"
else:
print("Usage: %s -i input_csv_file -o output_folder [-d true/fale] to enable debug" % sys.argv[0])
# Display input and output file name passed as the args
print ("Input file : %s and output folder: %s" % (ifile,ofolder) )
##############################
# process given CSV report
#############################
with open(ifile, 'rb') as csvfile:
# open csv file
reader = csv.reader(csvfile, delimiter=',', skipinitialspace=True)
# get the header, will be used for generating output filenames
header = reader.next()
# use zip() to return a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables
# http://docs.python.org/2/library/functions.html#zip
cols = zip(*reader)
# iterate over all header apart from the first one
# which contains percentile values
for idx,val in enumerate(header[1:]):
# leave only alphanumerics in the filename
outputFile=re.sub("[^a-zA-Z0-9]", "", val)
filename=ofolder+outputFile+"RespTimesPercentiles.csv"
rep=""
# transform list of headers into a formatted string
hdr = ','.join(cols[0])
# transform list of values into a formatted string
vals = ','.join(cols[idx+1])
# build output string
rep = hdr + "\n" + vals
print "Saving response times percentiles report from " + val + " column to ---> ",filename
if debug:
print rep
# save reports in separate files
with open(filename, 'w') as f:
f.write(rep)