Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

c - Tracing/profiling instructions

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 not your usual run of the mill code profiling requirement. I'm an algorithm developer and I want to estimate the cost of converting my code to hardware implementations. For this, I'm being asked the instruction call breakdown during run-time (parsing the compiled assembly isn't sufficient as it doesn't consider loops in the code).

After looking around, it seems VMware may offer a possible solution, but I still couldn't find the specific feature that will allow me to trace the instruction call stream of my process.

Are you aware of any profiling tools which enable this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I eventually used a trivial yet effective solution.

  1. Configured GDB to display the disassembly of the next instruction (every time it stops) by invoking:

display/i $pc

  1. Configured a simple gdb script that breaks in the function I need to analyze and proceeds to step instruction by instruction: set $i=0 break main run while ($i<100000) si set $i = $i + 1 end quit

  2. Executed gdb with my script dumping output into a log file:

    gdb -x script a.out > log.txt

  3. Analyzed the log to count specific instruction calls.

Crude, but it works...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...