| 1 |
#!/usr/bin/python |
| 2 |
# |
| 3 |
# This example shows how to capture latency between a dlm_lock() kernel |
| 4 |
# call for DLM_LOCK_EX requests with flag DLM_LKF_NOQUEUE and the ast |
| 5 |
# response. |
| 6 |
# |
| 7 |
# You will probably see two line peaks, one in case of that the current |
| 8 |
# node is the lock master and another one which requires network |
| 9 |
# communication. There is currently no way to filter them out, so the |
| 10 |
# second peak is interessting to get an idea what time it takes to |
| 11 |
# call dlm_lock() and get a response back. |
| 12 |
|
| 13 |
from bcc import BPF |
| 14 |
|
| 15 |
import threading |
| 16 |
|
| 17 |
b = BPF(text=""" |
| 18 |
#include <uapi/linux/ptrace.h> |
| 19 |
#include <uapi/linux/dlm.h> |
| 20 |
|
| 21 |
BPF_HASH(start, u32); |
| 22 |
BPF_HISTOGRAM(dist, u64); |
| 23 |
|
| 24 |
#define DLM_HASH(args) (args->ls_id ^ args->lkb_id) |
| 25 |
|
| 26 |
TRACEPOINT_PROBE(dlm, dlm_lock_start) |
| 27 |
{ |
| 28 |
u64 ts = bpf_ktime_get_ns(); |
| 29 |
u32 hash = DLM_HASH(args); |
| 30 |
|
| 31 |
if (args->flags & DLM_LKF_NOQUEUE && |
| 32 |
args->mode == DLM_LOCK_EX) |
| 33 |
start.update(&hash, &ts); |
| 34 |
|
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
TRACEPOINT_PROBE(dlm, dlm_lock_end) |
| 39 |
{ |
| 40 |
u32 hash = DLM_HASH(args); |
| 41 |
|
| 42 |
if (args->error != 0) |
| 43 |
start.delete(&hash); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
TRACEPOINT_PROBE(dlm, dlm_ast) |
| 49 |
{ |
| 50 |
u32 hash = DLM_HASH(args); |
| 51 |
u64 *tsp, delta; |
| 52 |
|
| 53 |
tsp = start.lookup(&hash); |
| 54 |
if (tsp != 0) { |
| 55 |
start.delete(&hash); |
| 56 |
delta = bpf_ktime_get_ns() - *tsp; |
| 57 |
|
| 58 |
if (args->sb_status != 0) |
| 59 |
return 0; |
| 60 |
|
| 61 |
dist.increment(bpf_log2l(delta)); |
| 62 |
} |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
""") |
| 67 |
|
| 68 |
print("Tracing... Hit Ctrl-C anytime to end.") |
| 69 |
|
| 70 |
forever = threading.Event() |
| 71 |
try: |
| 72 |
forever.wait() |
| 73 |
except KeyboardInterrupt: |
| 74 |
print() |
| 75 |
|
| 76 |
print("log2 histogram") |
| 77 |
print("--------------") |
| 78 |
b["dist"].print_log2_hist("ns") |