-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_latency.bt
55 lines (49 loc) · 1.14 KB
/
msg_latency.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
51
52
53
54
55
#!/usr/bin/env bpftrace
/*
* msg_latency.bt
*
* Show how much time a message sent by msgsnd() spent in the queue
* before being received by msgrcv()
*
* For Linux, uses bpftrace, eBPF.
*
* 2024-05-01 [email protected] https://aivarsk.com
*/
// If you have complaints about this, install bpftrace-dbgsym
// https://github.com/bpftrace/bpftrace/issues/2168#issuecomment-1230499942
BEGIN
{
printf("PID COMM MSQID TIME(ns)\n");
}
// Start of sending the message
kfunc:do_msgsnd
{
@start[tid] = nsecs;
}
// Store the time of msgsnd() with the message
kretfunc:load_msg
/@start[tid]/
{
@msgs[retval] = @start[tid];
delete(@start[tid]);
}
// Just store the msqid for later
kfunc:do_msgrcv
{
@msqid[tid] = args->msqid;
}
// Retrieve the time of msgsnd() from the message
kfunc:store_msg
/@msgs[args->msg]/
{
@start[tid] = @msgs[args->msg];
delete(@msgs[args->msg]);
}
// Print some info for successful msgrcv()
kretfunc:do_msgrcv
/@start[tid] && @msqid[tid]/
{
printf("%-8d %-16s %-8d %lld\n", pid, comm, @msqid[tid], nsecs - @start[tid]);
delete(@start[tid]);
delete(@msqid[tid]);
}