Tracing/profiling instructions

前端 未结 5 1845
渐次进展
渐次进展 2020-12-28 20:46

I\'d like to statistically profile my C code at the instruction level. I need to know how many additions, multiplications, divisions, etc I\'m performing.

This is no

5条回答
  •  不思量自难忘°
    2020-12-28 21:14

    The Linux tool perf will give you a good deal of profiling information; specifically, perf annotate will give you per-instruction relative counts.

    It is possible to drill down to the instruction level with perf annotate. For that, you need to invoke perf annotate with the name of the command to annotate. All the functions with samples will be disassembled and each instruction will have its relative percentage of samples reported:
    perf record ./noploop 5
    perf annotate -d ./noploop
    
    ------------------------------------------------
     Percent |   Source code & Disassembly of noploop.noggdb
    ------------------------------------------------
             :
             :
             :
             :   Disassembly of section .text:
             :
             :   08048484 
    : 0.00 : 8048484: 55 push %ebp 0.00 : 8048485: 89 e5 mov %esp,%ebp [...] 0.00 : 8048530: eb 0b jmp 804853d 15.08 : 8048532: 8b 44 24 2c mov 0x2c(%esp),%eax 0.00 : 8048536: 83 c0 01 add $0x1,%eax 14.52 : 8048539: 89 44 24 2c mov %eax,0x2c(%esp) 14.27 : 804853d: 8b 44 24 2c mov 0x2c(%esp),%eax 56.13 : 8048541: 3d ff e0 f5 05 cmp $0x5f5e0ff,%eax 0.00 : 8048546: 76 ea jbe 8048532 [...]

提交回复
热议问题