-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathmlock.bt
executable file
·51 lines (46 loc) · 1.18 KB
/
mlock.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
#!/usr/local/bin/bpftrace
/*
* mlock - Show mutex lock times and kernel stacks.
*
* See BPF Performance Tools, Chapter 14, for an explanation of this tool.
*
* Copyright (c) 2019 Brendan Gregg.
* Licensed under the Apache License, Version 2.0 (the "License").
* This was originally created for the BPF Performance Tools book
* published by Addison Wesley. ISBN-13: 9780136554820
* When copying or porting, include this comment.
*
* 14-Mar-2019 Brendan Gregg Created this.
*/
BEGIN
{
printf("Tracing mutex_lock() latency, Ctrl-C to end.\n");
}
kprobe:mutex_lock,
kprobe:mutex_lock_interruptible
/$1 == 0 || pid == $1/
{
@lock_start[tid] = nsecs;
@lock_addr[tid] = arg0;
}
kretprobe:mutex_lock
/($1 == 0 || pid == $1) && @lock_start[tid]/
{
@lock_latency_ns[ksym(@lock_addr[tid]), kstack(5), comm] =
hist(nsecs - @lock_start[tid]);
delete(@lock_start[tid]);
delete(@lock_addr[tid]);
}
kretprobe:mutex_lock_interruptible
/retval == 0 && ($1 == 0 || pid == $1) && @lock_start[tid]/
{
@lock_latency_ns[ksym(@lock_addr[tid]), kstack(5), comm] =
hist(nsecs - @lock_start[tid]);
delete(@lock_start[tid]);
delete(@lock_addr[tid]);
}
END
{
clear(@lock_start);
clear(@lock_addr);
}