-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_data.py
74 lines (55 loc) · 1.84 KB
/
plot_data.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
import json
class LineDataScope:
def __init__(self, file):
self.file = file
self.append = False
def result(self, num_threads, t_avg, t_min, t_max):
if self.append:
self.file.write(',')
self.file.write(f"[{num_threads},{t_avg},{t_min},{t_max}]")
self.append = True
def queue_op_stats_result(self, num_threads, t, n, enqueue_stats_succ, enqueue_stats_fail, dequeue_stats_succ, dequeue_stats_fail):
if self.append:
self.file.write(',')
self.file.write(f'{{ "num": {num_threads}, "t": {t}, "n": {n}, "stats": [')
def write_queue_op_stats(stats):
self.file.write(f"[{stats.num_operations},{stats.t_total},{stats.t_min},{stats.t_max}]")
write_queue_op_stats(enqueue_stats_succ)
self.file.write(',')
write_queue_op_stats(enqueue_stats_fail)
self.file.write(',')
write_queue_op_stats(dequeue_stats_succ)
self.file.write(',')
write_queue_op_stats(dequeue_stats_fail)
self.file.write('] }')
self.append = True
class LineDataWriter:
def __init__(self, file, params):
self.file = file
self.params = params
def __enter__(self):
params = { 'device': f'{self.params.device}-{self.params.platform}' }
for key, value in self.params.properties.items():
params[key] = value
self.file.write(f'{{ "params": {json.dumps(params)}, "results": [')
return LineDataScope(self.file)
def __exit__(self, exc_type, exc_value, traceback):
self.file.write("] }")
class Scope:
def __init__(self, file):
self.file = file
self.first = True
def line_data(self, params):
if not self.first:
self.file.write(",\n")
self.first = False
return LineDataWriter(self.file, params)
class Writer:
def __init__(self, file, var_name):
self.file = file
self.var_name = var_name
def __enter__(self):
self.file.write(f"[")
return Scope(self.file)
def __exit__(self, exc_type, exc_value, traceback):
self.file.write("\n]\n")