./funcinterval -p 181 vfs_read
# time the interval of mm_vmscan_direct_reclaim_begin tracepoint
./funcinterval t:vmscan:mm_vmscan_direct_reclaim_begin
+ # time the interval of c:malloc used by top every 3 seconds
+ ./funcinterval -p `pidof -s top` -i 3 c:malloc
+ # time /usr/local/bin/python main function
+ ./funcinterval /usr/local/bin/python:main
"""
parser = argparse.ArgumentParser(
description="Time interval and print latency as a histogram",
parts = args.pattern.split(':')
if len(parts) == 1:
- attach_type = "function"
+ attach_type = "kprobe function"
pattern = args.pattern
+elif len(parts) == 2:
+ attach_type = "uprobe function"
+ elf = BPF.find_library(parts[0]) or BPF.find_exe(parts[0])
+ if not elf:
+ bail("Can't find elf binary %s" % elf)
+ pattern = parts[1]
elif len(parts) == 3:
attach_type = "tracepoint"
pattern = ':'.join(parts[1:])
if len(parts) == 1:
b.attach_kprobe(event=pattern, fn_name="trace_func_entry")
matched = b.num_open_kprobes()
+elif len(parts) == 2:
+ # sym_re is regular expression for symbols
+ b.attach_uprobe(name = elf, sym_re = pattern, fn_name = "trace_func_entry",
+ pid = args.pid or -1)
+ matched = b.num_open_uprobes()
elif len(parts) == 3:
b.attach_tracepoint(tp=pattern, fn_name="trace_func_entry")
matched = b.num_open_tracepoints()
time. In our case, mmc-cmdqd is slower than block layer.
+# ./funcinterval -p `pidof -s top` c:malloc -i 3
+Tracing uprobe function for "malloc"... Hit Ctrl-C to end.
+
+ nsecs : count distribution
+ 0 -> 1 : 0 | |
+ 2 -> 3 : 0 | |
+ 4 -> 7 : 0 | |
+ 8 -> 15 : 0 | |
+ 16 -> 31 : 0 | |
+ 32 -> 63 : 0 | |
+ 64 -> 127 : 0 | |
+ 128 -> 255 : 0 | |
+ 256 -> 511 : 0 | |
+ 512 -> 1023 : 0 | |
+ 1024 -> 2047 : 0 | |
+ 2048 -> 4095 : 0 | |
+ 4096 -> 8191 : 7 |************************* |
+ 8192 -> 16383 : 11 |****************************************|
+ 16384 -> 32767 : 4 |************** |
+ 32768 -> 65535 : 1 |*** |
+ 65536 -> 131071 : 1 |*** |
+ 131072 -> 262143 : 1 |*** |
+ 262144 -> 524287 : 0 | |
+ 524288 -> 1048575 : 0 | |
+ 1048576 -> 2097151 : 0 | |
+ 2097152 -> 4194303 : 0 | |
+ 4194304 -> 8388607 : 1 |*** |
+
+
+ nsecs : count distribution
+ 0 -> 1 : 0 | |
+ 2 -> 3 : 0 | |
+ 4 -> 7 : 0 | |
+ 8 -> 15 : 0 | |
+ 16 -> 31 : 0 | |
+ 32 -> 63 : 0 | |
+ 64 -> 127 : 0 | |
+ 128 -> 255 : 0 | |
+ 256 -> 511 : 0 | |
+ 512 -> 1023 : 0 | |
+ 1024 -> 2047 : 0 | |
+ 2048 -> 4095 : 0 | |
+ 4096 -> 8191 : 8 |******************************** |
+ 8192 -> 16383 : 10 |****************************************|
+ 16384 -> 32767 : 4 |**************** |
+ 32768 -> 65535 : 1 |**** |
+ 65536 -> 131071 : 1 |**** |
+ 131072 -> 262143 : 1 |**** |
+ 262144 -> 524287 : 0 | |
+ 524288 -> 1048575 : 0 | |
+ 1048576 -> 2097151 : 0 | |
+ 2097152 -> 4194303 : 0 | |
+ 4194304 -> 8388607 : 1 |**** |
+
+Time the interval of libc's malloc for top utility every 3 seconds.
+
+# ./funcinterval /usr/local/bin/python:main
+Tracing uprobe function for "main"... Hit Ctrl-C to end.
+^C
+ nsecs : count distribution
+ 0 -> 1 : 0 | |
+ 2 -> 3 : 0 | |
+ 4 -> 7 : 0 | |
+ 8 -> 15 : 0 | |
+ 16 -> 31 : 0 | |
+ 32 -> 63 : 0 | |
+ 64 -> 127 : 0 | |
+ 128 -> 255 : 0 | |
+ 256 -> 511 : 0 | |
+ 512 -> 1023 : 0 | |
+ 1024 -> 2047 : 0 | |
+ 2048 -> 4095 : 0 | |
+ 4096 -> 8191 : 0 | |
+ 8192 -> 16383 : 0 | |
+ 16384 -> 32767 : 0 | |
+ 32768 -> 65535 : 0 | |
+ 65536 -> 131071 : 0 | |
+ 131072 -> 262143 : 0 | |
+ 262144 -> 524287 : 0 | |
+ 524288 -> 1048575 : 0 | |
+ 1048576 -> 2097151 : 0 | |
+ 2097152 -> 4194303 : 0 | |
+ 4194304 -> 8388607 : 0 | |
+ 8388608 -> 16777215 : 0 | |
+ 16777216 -> 33554431 : 0 | |
+ 33554432 -> 67108863 : 0 | |
+ 67108864 -> 134217727 : 0 | |
+ 134217728 -> 268435455 : 0 | |
+ 268435456 -> 536870911 : 1 |****************************************|
+ 536870912 -> 1073741823 : 1 |****************************************|
+1073741824 -> 2147483647 : 1 |****************************************|
+2147483648 -> 4294967295 : 1 |****************************************|
+Detaching...
+
+Time the interal of python's main function.
+
USAGE message:
# ./funcinterval -h
./funcinterval -p 181 vfs_read
# time the interval of mm_vmscan_direct_reclaim_begin tracepoint
./funcinterval t:vmscan:mm_vmscan_direct_reclaim_begin
+ # time the interval of c:malloc used by top every 3 seconds
+ ./funcinterval -p `pidof -s top` -i 3 c:malloc
+ # time /usr/local/bin/python main function
+ ./funcinterval /usr/local/bin/python:main