Skip to content

Commit 0ce5add

Browse files
compact the disksnoop.py example
Signed-off-by: varun-r-mallya <[email protected]>
1 parent d0e2360 commit 0ce5add

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

BCC-Examples/disksnoop.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from vmlinux import struct_request, struct_pt_regs
2-
from pythonbpf import bpf, section, bpfglobal, compile, map
1+
from ctypes import c_int32, c_int64, c_uint64
2+
3+
from vmlinux import struct_pt_regs, struct_request
4+
5+
from pythonbpf import bpf, bpfglobal, compile, map, section
36
from pythonbpf.helper import ktime
47
from pythonbpf.maps import HashMap
5-
from ctypes import c_int64, c_uint64, c_int32
6-
7-
# Constants
8-
REQ_WRITE = 1 # from include/linux/blk_types.h
98

109

1110
@bpf
@@ -17,24 +16,15 @@ def start() -> HashMap:
1716
@bpf
1817
@section("kprobe/blk_mq_end_request")
1918
def trace_completion(ctx: struct_pt_regs) -> c_int64:
20-
# Get request pointer from first argument
2119
req_ptr = ctx.di
2220
req = struct_request(ctx.di)
23-
# Print: data_len, cmd_flags, latency_us
2421
data_len = req.__data_len
2522
cmd_flags = req.cmd_flags
26-
# Lookup start timestamp
2723
req_tsp = start.lookup(req_ptr)
2824
if req_tsp:
29-
# Calculate delta in nanoseconds
3025
delta = ktime() - req_tsp
31-
32-
# Convert to microseconds for printing
3326
delta_us = delta // 1000
34-
3527
print(f"{data_len} {cmd_flags:x} {delta_us}\n")
36-
37-
# Delete the entry
3828
start.delete(req_ptr)
3929

4030
return c_int64(0)

0 commit comments

Comments
 (0)