我想用fedora中的Kprobe对malloc系统调用进行计数。我知道malloc不是一个系统调用,它是在用户空间实现的,但如果可能的话,我想用kprobe来计算malloc。
我必须给Kprobe的系统调用的名称是什么?例如,对于do_work:
kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("do_fork");发布于 2017-11-08 21:02:32
使用kprobes是不可能的,因为正如您所说的,malloc不是系统调用。
但是,您可以使用USDT来跟踪用户空间进程。The bcc tools包含一个使用uobjnew的示例。它跟踪给定进程中的对象分配情况:
$ ./uobjnew -h
usage: uobjnew.py [-h] [-l {java,ruby,c}] [-C TOP_COUNT] [-S TOP_SIZE] [-v]
pid [interval]
Summarize object allocations in high-level languages.
positional arguments:
pid process id to attach to
interval print every specified number of seconds
optional arguments:
-h, --help show this help message and exit
-l {java,ruby,c}, --language {java,ruby,c}
language to trace
-C TOP_COUNT, --top-count TOP_COUNT
number of most frequently allocated types to print
-S TOP_SIZE, --top-size TOP_SIZE
number of largest types by allocated bytes to print
-v, --verbose verbose mode: print the BPF program (for debugging
purposes)
examples:
./uobjnew -l java 145 # summarize Java allocations in process 145
./uobjnew -l c 2020 1 # grab malloc() sizes and print every second
./uobjnew -l ruby 6712 -C 10 # top 10 Ruby types by number of allocations
./uobjnew -l ruby 6712 -S 10 # top 10 Ruby types by total sizehttps://stackoverflow.com/questions/14476325
复制相似问题