-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneocortix_jmeter_histogram.py
95 lines (80 loc) · 3.62 KB
/
neocortix_jmeter_histogram.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
95
# -*- coding: utf-8 -*-
import pandas as pd
import glob
import numpy as np
import matplotlib.pyplot as plt
import os
'''
This function filters out all the rows for which the label column does not match a given value (i.e GetDistribution).
And saves "elapsed" value for rows that do match the specified label text(transaction name) into a csv.
'''
LOCATION = os.getcwd()
TRANSACTION_NAME = 'HTTP Request' #replace the transaction name with your transaction name
def extract_latency_data():
FILE_TO_WRITE =""
for file in os.listdir(LOCATION):
try: #extract latency data from csv files that begin with TestPlan_
if file.startswith("TestPlan_") and file.endswith(".csv"):
FILE_TO_WRITE = "new_"+os.path.basename(file)
df = pd.read_csv(file)
x = []
x = df.loc[df['label'] == TRANSACTION_NAME] #filter out all the rows for which the label column does not contain value GetDistribution
with open(FILE_TO_WRITE,'w') as fwrite:
fwrite.write('elapsed_time_'+FILE_TO_WRITE+'\n')
for item in range(len(x)):
fwrite.write('%s\n' %x['elapsed'].values[item])
else:
continue
except Exception as e:
raise e
'''
Note glob.glob() is not case sensitive in Windows OS.
Make sure the files that need to be merged have unique names from other file.
https://jdhao.github.io/2019/06/24/python_glob_case_sensitivity/
'''
def merge_latency_data():
try:
files = glob.glob("./new_TestPlan_results_*.csv") #extract_data function generates csv files that start with new_TestPlan_results
dataframes = [pd.read_csv(p) for p in files]
merged_dataframe = pd.concat(dataframes, axis=1)
merged_dataframe.to_csv("./responsetime_histogram.csv", index=False)
except Exception as e:
raise e
'''
This function iterates through all the columns in the responsetime_histogram file
and generate histogram for all of them. It also plots the average response time for all.
Note: comment out the code that plots mean on the graph if not required.
'''
def generate_histogram():
#for testing purpose use the file responsetime_histogram provided
FILE = "./responsetime_histogram.csv" #replace with your file name
try:
df = pd.read_csv(FILE) # read the file
#default histogram settings
plt.figure(figsize=(12,8))
kwargs = dict(histtype='step', stacked=False, alpha=0.6, fill=True, bins=2000)
plt.xlim(0,3000)
plt.xlabel('Response Time (ms)')
plt.ylabel('Frequency')
plt.grid(axis="x", color="black", alpha=.8, linewidth=0.2, linestyle=":")
plt.grid(axis="y", color="black", alpha=.8, linewidth=0.2, linestyle=":")
y_upper=0.1 # set the default y distance for the text for mean
x_upper=1 # set the default x distance for the text for mean
for col in df.columns:
plt.hist(df[col],**kwargs)
'''Disable the below code if you don't want to display mean value for each chart.
'''
plt.axvline(np.mean(df[col]), color='r', linestyle='dashed', linewidth=0.5)
min_ylim, max_ylim = plt.ylim()
plt.text(np.mean(df[col])*x_upper, max_ylim*y_upper, 'μ: {:.2f}'.format(np.mean(df[col])))
y_upper=y_upper + 0.04
x_upper=x_upper+ 0.002
plt.savefig('histogram.png')
except Exception as e:
raise e
def main():
extract_latency_data()
merge_latency_data()
generate_histogram()
if __name__ == "__main__":
main()