Last active
May 28, 2020 08:53
-
-
Save alwaysR9/cf9aeadfc533d43b2b28c8dc2847e93e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env stap | |
# usage: | |
# stap tools/offcpu-cost.stp -x ${pid} -D MAXSKIPPED=1000000 -t -v -w -T 1 | |
global MAX_PROBE_NUM = 10000 # max context-switch number | |
global cur_probe_num = 0 | |
global begin_sleep_time | |
global delta | |
probe kernel.function("finish_task_switch@kernel/sched/core.c") { | |
#target_pid = strtol(@1, 10) | |
if (pid() != target()) next | |
if (cur_probe_num >= MAX_PROBE_NUM) next | |
begin_sleep_time[$prev->pid] = gettimeofday_us() | |
if (!begin_sleep_time[tid()]) | |
next | |
elapse = gettimeofday_us() - begin_sleep_time[tid()] | |
stack = sprint_ubacktrace() | |
delta[stack] += elapse | |
begin_sleep_time[tid()] = 0 | |
cur_probe_num += 1 | |
} | |
probe end { | |
n = 0 | |
foreach (stack in delta-) { | |
if (n < 10) { | |
printf("%d\n%s\n===============\n\n", delta[stack], stack) | |
} | |
n += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment