-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_probe.py
executable file
·56 lines (46 loc) · 1.25 KB
/
user_probe.py
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
56
#!/usr/bin/python
#
# disksnoop.py Trace block device I/O: basic version of iosnoop.
# For Linux, uses BCC, eBPF. Embedded C.
#
# Written as a basic example of tracing latency.
#
# Copyright (c) 2015 Brendan Gregg.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 11-Aug-2015 Brendan Gregg Created this.
from __future__ import print_function
from bcc import BPF, USDT
from bcc.utils import printb
from time import sleep
import sys
REQ_WRITE = 1 # from include/linux/blk_types.h
pid = int(sys.argv[1])
print("Probes for PID: %d" % pid)
u = USDT(pid = pid)
u.enable_probe(probe="sleep_trace", fn_name="trace_on_market_data")
# load BPF program
code="""
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
struct result_t {
u32 seq_num;
};
BPF_PERF_OUTPUT(events);
void trace_on_market_data(struct pt_regs *ctx) {
struct result_t data = {};
bpf_usdt_readarg(1, ctx, &data.seq_num);
events.perf_submit(ctx, &data, sizeof(data));
}
"""
b = BPF(text=code, usdt_contexts=[u])
#b.trace_print()
def print_data(cpu, data, size):
e = b["events"].event(data)
print("SleepTrace: Seq: %d %-5d" % (e.seq_num, cpu))
b["events"].open_perf_buffer(print_data)
while True:
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
b["events"].clear()