forked from andikleen/pmu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_metrics.py
158 lines (143 loc) · 4.89 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
#
# basic linux software metrics
#
# for most of these it would be much nicer to measure durations, but
# perf stat doesn't support that
#
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 Syscalls:
name = "Syscalls"
desc = " Number of syscalls, not including vsyscalls such as gettimeofday."
nogroup = True
subplot = "OS metrics"
def compute(self, EV):
self.val = EV("raw_syscalls:sys_enter", 1)
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):
self.val = EV("irq:irq_handler_entry", 1) + EV("nmi:nmi_handler", 1)
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):
self.val = (EV("irq_vectors:call_function_entry", 1) +
EV("irq_vectors:call_function_single_entry", 1) +
EV("irq_vectors:reschedule_entry", 1))
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):
self.val = EV("workqueue:workqueue_execute_start", 1)
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):
self.val = EV("block:block_rq_insert", 1)
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):
self.val = EV("net:net_dev_start_xmit", 1)
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):
self.val = (EV("net:netif_rx", 1) +
EV("net:netif_receive_skb", 1) +
EV("net:napi_gro_receive_entry", 1) +
EV("net:napi_gro_frags_entry", 1))
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
class Setup:
def __init__(self, r):
r.metric(CS())
r.metric(MinorFaults())
r.metric(MajorFaults())
r.metric(Migrations())
if os.path.exists("/sys/kernel/debug/tracing/events"):
r.metric(Syscalls())
r.metric(Interrupts())
r.metric(IPIs())
r.metric(Workqueues())
r.metric(BlockIOs())
r.metric(NetworkTX())
r.metric(NetworkRX())
elif sys.argv[0].find("toplev") >= 0:
print >>sys.stderr, "Need to be root for trace point Linux software metrics."