Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Last active December 10, 2024 16:26
Show Gist options
  • Save samueleresca/9c46655d335fa0ba5ad2a48536ab874c to your computer and use it in GitHub Desktop.
Save samueleresca/9c46655d335fa0ba5ad2a48536ab874c to your computer and use it in GitHub Desktop.
tracepoint:sched:sched_switch
{
$prev_pid = args->prev_pid;
$next_pid = args->next_pid;
$prev_state = args->prev_state;
// Record on-CPU time for previous task
if (has_key(@start, $prev_pid))
{
@cpu[comm, $prev_pid] = sum(nsecs - @start[$prev_pid]);
}
// Start timing for next thread
@start[$next_pid] = nsecs;
// Calculate run queue time when thread gets scheduled
if (has_key(@wakeup_ts, $next_pid))
{
@runq[comm, $next_pid] = sum(nsecs - @wakeup_ts[$next_pid]);
delete(@wakeup_ts, $next_pid);
}
}
tracepoint:sched:sched_wakeup,
tracepoint:sched:sched_wakeup_new
{
// Track wakeup time
@wakeup_ts[tid] = nsecs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment