2013-01-23 7 views
1

페도라의 Kprobe를 사용하여 malloc 시스템 호출을 계산하고 싶습니다. malloc은 시스템 호출이 아니며 사용자 공간에 구현되어 있지만 가능한 경우 kprobe를 사용하여 malloc을 계산하려고합니다.커널 커널에서 kprobe를 사용하여 malloc을 계산할 수 있습니까

Kprobe에 제공해야하는 시스템 호출의 이름은 무엇입니까? do_work 예를 들어 : 당신이 말한대로, malloc는 시스템 호출되지 않습니다 때문에이 Kprobes를 불가능

kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("do_fork"); 
+2

'malloc'은 시스템 호출이 아닙니다. GNU Glibc 라이브러리에서는'mmap'과'sbrk' 시스템 콜을 사용하여 구현됩니다. 아마도 사용자 응용 프로그램에서'valgrind'를 사용하기를 원할지도 모릅니다. 커널 자체는'kmalloc'과 관련된 커널 기능을 사용하여 동적 메모리 (커널 내부, 응용 프로그램 제외)를 할당하고 있습니다. –

+0

그리고'pmap'을 사용할 수도 있고, pid 1234의 프로세스는'/ proc/1234/status'와'/ proc/1234/maps' 등을 들여다 봅니다. –

답변

0

.

그러나 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 size