Repository navigation
Expand file tree
/
Copy pathgraph.py
More file actions
90 lines (73 loc) · 3.07 KB
/
Copy pathgraph.py
File metadata and controls
90 lines (73 loc) · 3.07 KB
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
import re
import os
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from collections import defaultdict
import statistics
directory = "./wrk" # Replace with the actual directory path
requests_sec = defaultdict(list)
transfers_sec = defaultdict(list)
mean_requests = {}
mean_transfers = {}
def plot(kind='', title='', ylabel='', means=None):
# Sort the labels and requests_sec lists together based on the requests_sec values
labels = []
values = []
# silly, I know
for k, v in means.items():
labels.append(k)
values.append(v)
# sort the labels and value lists
labels, values = zip(*sorted(zip(labels, values), key=lambda x: x[1], reverse=True))
# Plot the graph
plt.figure(figsize=(10, 6)) # Adjust the figure size as needed
bars = plt.bar(labels, values)
plt.xlabel("Subject")
plt.ylabel(ylabel)
plt.title(title)
plt.xticks(rotation=45) # Rotate x-axis labels for better readability
# Display the actual values on top of the bars
for bar in bars:
yval = bar.get_height()
plt.text(bar.get_x() + bar.get_width() / 2, yval, f'{yval:,.2f}', ha='center', va='bottom')
plt.tight_layout() # Adjust the spacing of the graph elements
png_name = f"{directory}/{kind.lower()}_graph.png"
plt.savefig(png_name) # Save the graph as a PNG file
print(f"Generated: {png_name}")
if __name__ == '__main__':
if not os.path.isdir(".git"):
print("Please run from root directory of the repository!")
print("e.g. python wrk/graph.py")
import sys
sys.exit(1)
# Iterate over the files in the directory
for filename in os.listdir(directory):
if filename.endswith(".perflog"):
label = os.path.splitext(filename)[0]
file_path = os.path.join(directory, filename)
with open(file_path, "r") as file:
lines = file.readlines()
for line in lines:
# Extract the Requests/sec value using regular expressions
match = re.search(r"Requests/sec:\s+([\d.]+)", line)
if match:
requests_sec[label].append(float(match.group(1)))
match = re.search(r"Transfer/sec:\s+([\d.]+)", line)
if match:
value = float(match.group(1))
if 'KB' in line:
value *= 1024
elif 'MB' in line:
value *= 1024 * 1024
value /= 1024.0 * 1024
transfers_sec[label].append(value)
# calculate means
for k, v in requests_sec.items():
mean_requests[k] = statistics.mean(v)
for k, v in transfers_sec.items():
mean_transfers[k] = statistics.mean(v)
# save the plots
plot(kind='req_per_sec', title='Requests/sec Comparison',
ylabel='requests/sec', means=mean_requests)
plot(kind='xfer_per_sec', title='Transfer/sec Comparison',
ylabel='transfer/sec [MB]', means=mean_transfers)