-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu-latency-plot
executable file
·118 lines (91 loc) · 3.82 KB
/
cpu-latency-plot
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
#!/usr/bin/env python3
# The MIT License (MIT)
# Copyright (c) 2022 Nicolas Viennot
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without
# limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following
# conditions:
# The above copyright notice and this permission notice
# shall be included in all copies or substantial portions
# of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# This file was originally part of core-to-core-latency by Nicolas Viennot.
#
# Modifications have been made to this file by the cpu-latency project.
#
# The modified version is licensed under the MIT License.
# See the LICENSE file in the root directory of this source tree for more information.
import matplotlib.pyplot as plt
from matplotlib import colormaps as cmaps
import numpy as np
import sys, getopt
from pathlib import Path
def main(argv):
inputfile = None
outputfile = None
title = None
help = 'plot -i <csvfile> -o <outputfile> -t <title>'
try:
opts, args = getopt.getopt(argv,"hi:o:t:",["ifile=","ofile=","title="])
for opt, arg in opts:
if opt == '-h':
print(help)
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = Path(arg)
elif opt in ("-o", "--ofile"):
outputfile = arg
elif opt in ("-t", "--title"):
title = arg
except getopt.GetoptError as err:
print(err) # will print something like "option -a not recognized"
print(help)
sys.exit(2)
if inputfile is None:
print (help)
sys.exit()
if not outputfile:
outputfile = inputfile.with_suffix('.png')
data = np.genfromtxt(inputfile, delimiter=",")
if (np.isnan(data[np.triu_indices(data.shape[0], 1)]).all()):
data = np.tril(data) + np.tril(data).transpose()
vmin = np.nanmin(data)
vmax = np.nanmax(data)
black_at = (vmin+3*vmax)/4
isnan = np.isnan(data)
plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = False
plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True
figsize = np.array(data.shape)*0.3 + np.array([6,1])
fig, ax = plt.subplots(figsize=figsize, dpi=130)
fig.patch.set_facecolor('w')
plt.imshow(np.full_like(data, 0.7), vmin=0, vmax=1, cmap = 'gray')
plt.imshow(data, cmap = cmaps['viridis'], vmin=vmin, vmax=vmax)
fontsize = 9 if vmax >= 100 else 10
for (i,j) in np.ndindex(data.shape):
t = "" if isnan[i,j] else f"{m[i,j]:.1f}" if vmax < 10.0 else f"{data[i,j]:.0f}"
c = "w" if data[i,j] < black_at else "k"
plt.text(j, i, t, ha="center", va="center", color=c, fontsize=fontsize)
plt.xticks(np.arange(data.shape[1]), labels=[f"{i+1}" for i in range(data.shape[1])], fontsize=9)
plt.yticks(np.arange(data.shape[0]), labels=[f"CPU {i+1}" for i in range(data.shape[0])], fontsize=9)
plt.tight_layout()
title = "{}Core-to-core latency".format(f"{title}\n" if title else "")
plt.title(f"{title}\n" +
f"Min={vmin:0.1f}ns Median={np.nanmedian(data):0.1f}ns Max={vmax:0.1f}ns",
fontsize=11, linespacing=1.5)
plt.savefig(outputfile, bbox_inches='tight')
plt.figure()
if __name__ == "__main__":
main(sys.argv[1:])