forked from open-edge-platform/edge-ai-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_time_series.py
More file actions
246 lines (193 loc) · 6.88 KB
/
plot_time_series.py
File metadata and controls
246 lines (193 loc) · 6.88 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2025 Intel Corporation
import argparse
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument("--logfiles", nargs='*', help="Directory path of the log file.",
type=str)
parser.add_argument("--start", nargs='?', help="Start cycle.",
type=int, default=0)
parser.add_argument("--end", nargs='?', help="End cycle.",
type=int, default=0)
parser.add_argument("--lat", action='store_true', help="Latency statistics.")
parser.add_argument("--dcm", action='store_true', help="DCM statistics.")
parser.add_argument("--cac", action='store_true', help="Cache statistics.")
parser.add_argument("--exe", action='store_true', help="Execution time statistics.")
parser.add_argument("--ins", action='store_true', help="Instruction count statistics.")
def main():
args = parser.parse_args()
print("Loading logfiles...: {}".format(args.logfiles))
x_list = []
t_list = []
if (len(args.logfiles) > 0):
for logfile in args.logfiles:
if (logfile != ""):
x = []
t = []
count = 0
with open(logfile) as fp:
for line in fp:
count += 1
x.append(count/1000.0)
t.append(int(line.strip()))
x_list.append(x)
t_list.append(t)
#for i in range(0, len(x)):
# print("Time {}: {}".format(x[i], t[i]))
print("Loaded {} files.".format(len(args.logfiles)))
# Latency data processing
if (args.lat):
print("Processing latency data...")
x = []
t = []
if len(x_list) == 0 or len(t_list) == 0:
print("Warning: Empty data.")
return
if len(x_list[0]) == 0 or len(t_list[0]) == 0:
print("Warning: Empty data.")
return
x = x_list[0].copy()
t = t_list[0].copy()
if (args.start >= len(x)):
print("Warning: start cycle {} exceeds max lenth {}.".format(args.start, len(x_list[0])))
return
x = x[args.start:-1]
t = t[args.start:-1]
fig, ax = plt.subplots()
ax.plot(x, t, label="Latency")
print("Min: {}, Avg: {}, Max: {}".format(min(t), sum(t)/len(t), max(t)))
ax.set(xlabel='time (s)', ylabel='latency (ns)',
title='Benchmark Test')
ax.grid()
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='upper right')
fig.set_tight_layout(True)
fig.savefig("lat-series.png")
# Cache data processing
if (args.cac):
print("Processing cache data...")
x = []
t = []
if len(x_list) == 0 or len(t_list) == 0:
print("Warning: Empty data.")
return
if len(x_list[0]) == 0 or len(t_list[0]) == 0:
print("Warning: Empty data.")
return
x = x_list[0].copy()
t = t_list[0].copy()
if (args.start >= len(x)):
print("Warning: start cycle {} exceeds max lenth {}.".format(args.start, len(x_list[0])))
return
x = x[args.start:-1]
t = t[args.start:-1]
fig, ax = plt.subplots()
ax.plot(x, t, label="Cache")
print("Min: {}, Avg: {}, Max: {}".format(min(t), sum(t)/len(t), max(t)))
ax.set(xlabel='time (s)', ylabel='Cache Miss',
title='Benchmark Test')
ax.grid()
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='upper right')
fig.set_tight_layout(True)
fig.savefig("cac-series.png")
# DCM data processing
if (args.dcm):
print("Processing dcm data...")
x = []
t = []
if len(x_list) == 0 or len(t_list) == 0:
print("Warning: Empty data.")
return
if len(x_list[0]) == 0 or len(t_list[0]) == 0:
print("Warning: Empty data.")
return
x = x_list[0].copy()
t = t_list[0].copy()
if (args.start >= len(x)):
print("Warning: start cycle {} exceeds max lenth {}.".format(args.start, len(x_list[0])))
return
x = x[args.start:-1]
t = t[args.start:-1]
index = 0
for i in range(len(t)):
# Start statistics from the cycle when DCM < 10us
if t[i] >= 10000:
index = i + 1
print("DCM start from cycle {}".format(index + args.start))
x = x[index:-1]
t = t[index:-1]
fig, ax = plt.subplots()
ax.plot(x, t, label="DCM")
print("Min: {}, Avg: {}, Max: {}".format(min(t), sum(t)/len(t), max(t)))
ax.set(xlabel='time (s)', ylabel='dcm (ns)',
title='Benchmark Test')
ax.grid()
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='upper right')
fig.set_tight_layout(True)
fig.savefig("dcm-series.png")
# Execution time data processing
if (args.exe):
print("Processing execution time data...")
if len(x_list) < 3 or len(t_list) < 3:
print("Warning: not enough logfiles, need 3 logfiles.")
return
if len(x_list[0]) == 0 or len(x_list[1]) == 0 or len(x_list[2]) == 0:
print("Warning: empty data in one log file.")
return
if len(x_list[0]) != len(x_list[1]) or len(x_list[0]) != len(x_list[2]):
print("Warning: length of three logs not the same.")
return
x = x_list[0].copy()
t = [0] * len(x_list[0])
for i in range(len(x_list[0])):
t[i] = t_list[0][i] + t_list[1][i] + t_list[2][i]
if (args.start >= len(x)):
print("Warning: start cycle {} exceeds max lenth {}.".format(args.start, len(x_list[0])))
return
x = x[args.start:-1]
t = t[args.start:-1]
fig, ax = plt.subplots()
ax.plot(x, t, label="Execution Time")
print("Min: {}, Avg: {}, Max: {}".format(min(t), sum(t)/len(t), max(t)))
ax.set(xlabel='time (s)', ylabel='execution (ns)',
title='Benchmark Test')
ax.grid()
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='upper right')
fig.set_tight_layout(True)
fig.savefig("exe-series.png")
# Instruction count data processing
if (args.ins):
print("Processing instruction count data...")
x = []
t = []
if len(x_list) == 0 or len(t_list) == 0:
print("Warning: Empty data.")
return
if len(x_list[0]) == 0 or len(t_list[0]) == 0:
print("Warning: Empty data.")
return
x = x_list[0].copy()
t = t_list[0].copy()
if (args.start >= len(x)):
print("Warning: start cycle {} exceeds max lenth {}.".format(args.start, len(x_list[0])))
return
x = x[args.start:-1]
t = t[args.start:-1]
fig, ax = plt.subplots()
ax.plot(x, t, label="Instruction Count")
print("Min: {}, Avg: {}, Max: {}".format(min(t), sum(t)/len(t), max(t)))
ax.set(xlabel='time (s)', ylabel='count',
title='Benchmark Test')
ax.grid()
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc='upper right')
fig.set_tight_layout(True)
fig.savefig("ins-series.png")
if __name__ == "__main__":
main()