forked from andikleen/pmu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_metrics.py
191 lines (174 loc) · 5.76 KB
/
linux_metrics.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
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
#
# basic linux software metrics
#
# for most of these it would be much nicer to measure durations, but
# perf stat doesn't support that
#
from __future__ import print_function
import os, sys
class CS:
name = "Context switches"
desc = " Number of context switches between threads or processes on a CPU."
nogroup = True
subplot = "Scheduler"
def compute(self, EV):
self.val = EV("cs", 1)
self.thresh = self.val > 0
class MinorFaults:
name = "Minor faults"
desc = " Page faults not leading to disk IO, such as allocation of memory."
nogroup = True
subplot = "Faults"
def compute(self, EV):
self.val = EV("minor-faults", 1)
self.thresh = self.val > 0
class MajorFaults:
name = "Major faults"
desc = """
Page faults leading to disk IO, such as loading executable text or do mmap'ed IO."""
nogroup = True
subplot = "Faults"
def compute(self, EV):
self.val = EV("major-faults", 1)
self.thresh = self.val > 0
class Migrations:
name = "Migrations"
desc = " Number of thread/process migrations to another CPU."
nogroup = True
subplot = "Scheduler"
def compute(self, EV):
self.val = EV("migrations", 1)
self.thresh = self.val > 0
# The events below require trace points, so typically root.
class BadEV(Exception):
pass
def C(ev):
if not os.path.exists("/sys/kernel/debug/tracing/events" + ev.replace(":", "/")):
raise BadEV()
return ev
class Syscalls:
name = "Syscalls"
desc = " Number of syscalls, not including vsyscalls such as gettimeofday."
nogroup = True
subplot = "OS metrics"
def compute(self, EV):
try:
self.val = EV(C("raw_syscalls:sys_enter"), 1)
except BadEV:
self.val = 0
self.thresh = self.val > 0
class Interrupts:
name = "Interrupts"
desc = """
Number of interrupts, including NMIs, excluding exceptions. These are interrupts caused by hardware,
typically to indicate IO. This includes performance counter sampling interrupts."""
nogroup = True
subplot = "Interrupts"
# can overcount with shared vectors
def compute(self, EV):
try:
self.val = EV(C("irq:irq_handler_entry"), 1) + EV(C("nmi:nmi_handler"), 1)
except BadEV:
self.val = 0
self.thresh = self.val > 0
# XXX on older kernels will not count TLB flushes, when they still had an
# own vector
class IPIs:
name = "IPIs"
desc = """
Number of inter-processor-interrupts (IPIs). These are caused by software, for example to flush TLBs,
finish IOs on the originating CPU, flush per CPU software caches (such as slab allocator caches)
or force reschedules."""
nogroup = True
subplot = "Interrupts"
# can overcount with shared vectors
def compute(self, EV):
try:
self.val = (EV(C("irq_vectors:call_function_entry"), 1) +
EV(C("irq_vectors:call_function_single_entry"), 1) +
EV(C("irq_vectors:reschedule_entry"), 1))
except BadEV:
self.val = 0
self.thresh = self.val > 0
class Workqueues:
name = "Workqueues"
desc = " Work queue item executions. These are tasks executed by the kernel in the background."
nogroup = True
subplot = "Interrupts"
def compute(self, EV):
try:
self.val = EV(C("workqueue:workqueue_execute_start"), 1)
except BadEV:
self.val = 0
self.thresh = self.val > 0
class BlockIOs:
name = "BlockIOs"
desc = " Block IOs issued. This counts the number of block IO requests inserted into a queue."
nogroup = True
subplot = "IO"
def compute(self, EV):
try:
self.val = EV(C("block:block_rq_insert"), 1)
except BadEV:
self.val = 0
self.thresh = self.val > 0
class NetworkTX:
name = "NetworkTX"
desc = " Network packets send to a network device. Aggregated (TSO/GRO) packets are counted as single packets."
nogroup = True
subplot = "IO"
def compute(self, EV):
try:
self.val = EV(C("net:net_dev_start_xmit"), 1)
except BadEV:
self.val = 0
self.thresh = self.val > 0
class NetworkRX:
name = "NetworkRX"
desc = " Network packets received from a network device. Aggregated (GRO) packets are counted as single packets."
nogroup = True
subplot = "IO"
def compute(self, EV):
try:
self.val = (EV(C("net:netif_rx"), 1) +
EV(C("net:netif_receive_skb"), 1) +
EV(C("net:napi_gro_receive_entry"), 1) +
EV(C("net:napi_gro_frags_entry"), 1))
except BadEV:
self.val = 0
self.thresh = self.val > 0
# trace events
# sched stats? (non perf)
# yield percentage
# % sched to idle
# ttw local vs remote
# wait for cpu time
# sched wakeup
# sched iowait
# filemap add to page cache
# compaction begin
# page_alloc
# start reclaim
# XXX large page alloc
# intel_gpu_freq_change
# XXX gpu
# kvm:kvm_exit
warned = False
class Setup:
def __init__(self, r):
r.force_metric(CS())
r.force_metric(MinorFaults())
r.force_metric(MajorFaults())
r.force_metric(Migrations())
global warned
if os.path.exists("/sys/kernel/debug/tracing/events"):
r.force_metric(Syscalls())
r.force_metric(Interrupts())
r.force_metric(IPIs())
r.force_metric(Workqueues())
r.force_metric(BlockIOs())
r.force_metric(NetworkTX())
r.force_metric(NetworkRX())
elif sys.argv[0].find("toplev") >= 0 and "--import" not in sys.argv and not warned:
warned = True
print("Need to be root for trace point Linux software metrics.", file=sys.stderr)