From f47b81a4b1f8471dc2242e362cde9d45354a8411 Mon Sep 17 00:00:00 2001 From: zhaoyao73 Date: Wed, 30 Jun 2021 13:15:26 -0400 Subject: [PATCH] add uprobe support in funcinterval (#3512) add uprobe support in funcinterval Signed-off-by: Yao Zhao --- man/man8/funcinterval.8 | 8 +++ tools/funcinterval.py | 17 +++++- tools/funcinterval_example.txt | 100 +++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) diff --git a/man/man8/funcinterval.8 b/man/man8/funcinterval.8 index 89a4a7b4..8a603998 100755 --- a/man/man8/funcinterval.8 +++ b/man/man8/funcinterval.8 @@ -73,6 +73,14 @@ Time process 181 only: Time the interval of mm_vmscan_direct_reclaim_begin tracepoint: # .B funcinterval t:vmscan:mm_vmscan_direct_reclaim_begin +.TP +Time the interval of c:malloc used by top every 3 seconds: +# +.B funcinterval -p `pidof -s top` -i 3 c:malloc +.TP +Time /usr/local/bin/python main function: +# +.B funcinterval /usr/local/bin/python:main .SH FIELDS .TP necs diff --git a/tools/funcinterval.py b/tools/funcinterval.py index baac73c9..097649f4 100755 --- a/tools/funcinterval.py +++ b/tools/funcinterval.py @@ -33,6 +33,10 @@ examples = """examples: ./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", @@ -69,8 +73,14 @@ def bail(error): 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:]) @@ -140,6 +150,11 @@ b = BPF(text=bpf_text) 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() diff --git a/tools/funcinterval_example.txt b/tools/funcinterval_example.txt index 8f3f8cbe..b3fea3e9 100755 --- a/tools/funcinterval_example.txt +++ b/tools/funcinterval_example.txt @@ -124,6 +124,102 @@ throughput testing, by those results you know which layer has a slower interval 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 @@ -161,3 +257,7 @@ examples: ./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 -- 2.34.1