File: cpu_throttle.stp

package info (click to toggle)
systemtap 4.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,260 kB
  • sloc: cpp: 77,147; ansic: 61,828; xml: 49,277; exp: 42,244; sh: 11,046; python: 2,772; perl: 2,252; tcl: 1,305; makefile: 1,086; lisp: 105; java: 102; awk: 101; asm: 91; sed: 16
file content (47 lines) | stat: -rwxr-xr-x 1,486 bytes parent folder | download | duplicates (5)
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
#! /usr/bin/env stap
# Copyright (C) 2018 Red Hat, Inc.
# Written by William Cohen <wcohen@redhat.com>
#
# cpu_throttle.stp provides total milliseconds each Intel x86
# processor performance is restricted due to power or thermal
# constraints formatted for consumption by prometheus.
# The data is read from /proc/systemtap/*/cpu_throttle.stp
#
# Run the script with:
#   stap cpu_throttle.stp
#
# control-c to exit data collection

global throttled_time, throttled_state

probe begin {
    // Make sure there is an instance in the throttled_time
    throttled_time[0] = 0
}

probe kprobe.function("therm_throt_process") {
    now = gettimeofday_ns()
    // just started throttling
    if (ulong_arg(1) && !(cpu() in throttled_state)) {
        throttled_state[cpu()] = now
    }
    // just ending throttling
    if (!ulong_arg(1) && cpu() in throttled_state) {
        throttled_time[cpu()] += now - throttled_state[cpu()]
        delete throttled_state[cpu()]
    }
}

probe prometheus {
    now = gettimeofday_ns()
    $value .= "# HELP cpu_throttle_time accumulated time process is performance limited in ms.\n"
    $value .= "# TYPE cpu_throttle_time counter\n"
    foreach (cpu in throttled_time){
      k = throttled_time[cpu]
      // add in any existing throttled time
      if (cpu in throttled_state)
          k += now - throttled_state[cpu]
          k /= 1000000 // scale from ns to ms
      $value .= "cpu_throttle_time{cpu=\"".sprint(cpu)."\"} ".sprint(k)."\n"
    }
}