Debian Codegraph @

testsuite/systemtap.examples/general/cpu_throttle.stp

raw
1 #! /usr/bin/env stap
2 # Copyright (C) 2018 Red Hat, Inc.
3 # Written by William Cohen <[email protected]>
4 #
5 # cpu_throttle.stp provides total milliseconds each Intel x86
6 # processor performance is restricted due to power or thermal
7 # constraints formatted for consumption by prometheus.
8 # The data is read from /proc/systemtap/*/cpu_throttle.stp
9 #
10 # Run the script with:
11 # stap cpu_throttle.stp
12 #
13 # control-c to exit data collection
14
15 global throttled_time, throttled_state
16
17 probe begin {
18 // Make sure there is an instance in the throttled_time
19 throttled_time[0] = 0
20 }
21
22 probe kprobe.function("therm_throt_process") {
23 now = gettimeofday_ns()
24 // just started throttling
25 if (ulong_arg(1) && !(cpu() in throttled_state)) {
26 throttled_state[cpu()] = now
27 }
28 // just ending throttling
29 if (!ulong_arg(1) && cpu() in throttled_state) {
30 throttled_time[cpu()] += now - throttled_state[cpu()]
31 delete throttled_state[cpu()]
32 }
33 }
34
35 probe prometheus {
36 now = gettimeofday_ns()
37 $value .= "# HELP cpu_throttle_time accumulated time process is performance limited in ms.\n"
38 $value .= "# TYPE cpu_throttle_time counter\n"
39 foreach (cpu in throttled_time){
40 k = throttled_time[cpu]
41 // add in any existing throttled time
42 if (cpu in throttled_state)
43 k += now - throttled_state[cpu]
44 k /= 1000000 // scale from ns to ms
45 $value .= "cpu_throttle_time{cpu=\"".sprint(cpu)."\"} ".sprint(k)."\n"
46 }
47 }