-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_life_histo.bt
executable file
·50 lines (50 loc) · 1.07 KB
/
task_life_histo.bt
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
#!/usr/bin/env bpftrace
#include <linux/sched.h>
#include <signal.h>
BEGIN {
if ( $# != 1 )
{
printf("First argument must be the task name.\n");
exit();
}
}
tracepoint:sched:sched_waking
/ strcontains(args->comm, str($1)) /
{
@wake_time[args->pid] = nsecs;
}
tracepoint:sched:sched_switch
{
$time = nsecs;
if ( strcontains(args->next_comm, str($1)) )
{
@schedule[args->next_pid] = $time;
if ( @wake_time[args->next_pid] != 0 )
{
@wake_time_histogram_us = hist(($time - @wake_time[args->next_pid])/1000);
@wake_time[args->next_pid]=0;
}
else
{
if ( @leave_time[args->next_pid] != 0 )
{
@off_cpu_histogram_us = hist(($time - @leave_time[args->next_pid])/1000);
}
}
}
if ( strcontains(args->prev_comm, str($1)) )
{
if ( @schedule[args->prev_pid] != 0 )
{
$slice_time = ($time - @schedule[args->prev_pid])/1000;
@slice_time_histogram_us = hist($slice_time);
@leave_time[args->prev_pid]=$time;
}
}
}
END
{
clear(@schedule);
clear(@wake_time);
clear(@leave_time);
}