-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_graph_gen.py
102 lines (80 loc) · 2.82 KB
/
search_graph_gen.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
96
97
98
99
100
101
102
#!/usr/bin/env python3
# from optparse import OptionParser
import argparse
import math
import re
import json
import matplotlib.pyplot as plt
def parse_file(f):
stats = dict()
lines = f.readlines()
tot_items = 0
# We suppose that the benchark log has a spdlog format ending with %v
pattern = r"(\{.*\})$"
prog = re.compile(pattern)
for l in lines:
line = l.strip('\n\t')
# print(line)
m = prog.search(line)
if m is None:
continue
json_data = json.loads(m.group(0))
# print(json_data)
# name = json_data['message']
items = json_data['items']
time = float(json_data['time'])
time_per_item = float(json_data['time/item'])
if items in stats:
old_sum = stats[items]["sum"]
old_square_sum = stats[items]["square_sum"]
counter = stats[items]["counter"]
min_v = stats[items]["min"]
max_v = stats[items]["max"]
else:
old_sum = 0
old_square_sum = 0
counter = 0
min_v = 1e9
max_v = 0
stats[items] = dict()
stats[items]["sum"] = old_sum+time_per_item
stats[items]["square_sum"] = old_square_sum + \
time_per_item*time_per_item
stats[items]["counter"] = counter+1
stats[items]["min"] = min(min_v, time_per_item)
stats[items]["max"] = max(max_v, time_per_item)
tot_items = tot_items + items
return (stats, tot_items)
def compute_mean_var(stats):
res = {}
for key in stats:
res[key] = {}
res[key]["mean"] = stats[key]["sum"] / \
stats[key]["counter"]
res[key]["dev"] = math.sqrt(
stats[key]["square_sum"]/stats[key]["counter"] - res[key]["mean"]*res[key]["mean"])
res[key]["min"] = stats[key]["min"]
res[key]["max"] = stats[key]["max"]
return res
def plot_stats(stats):
sorted_list = sorted(stats.keys())
vals = [stats[k]["mean"] for k in sorted_list]
plt.plot(sorted_list, vals)
plt.xscale('log')
plt.show()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Process a search benchmark file.')
parser.add_argument("-i", "--input", dest="in_file", nargs=1,
required=True, help="Input file", type=argparse.FileType('r'))
# parser.add_argument("-o", "--out", dest="out_file", nargs=1,
# required=True, help="Output file", type=argparse.FileType('w'))
args = parser.parse_args()
print("Parsing {0}".format(
args.in_file[0].name))
(stats, tot_items) = parse_file(args.in_file[0])
print("Compute statistics one {0} items".format(tot_items))
stats2 = compute_mean_var(stats)
print("Plot statistics")
plot_stats(stats2)
print("Done")