I need to analyze some c code with functions and I want to get the exact number of instructions of different function in c code. I have no idea. Thanks.
Asked
Active
Viewed 51 times
0
-
What are you trying to measure? Code size, performance, other...? – simonc Jun 05 '13 at 13:17
-
**you should add objective**...C instruction? ..it may be user-defined but..Do you need to classify codes (because you taged profiling)? – Grijesh Chauhan Jun 05 '13 at 13:18
-
Do you mean you want to profile it? Just compile it with the `-pg` flags, run the app and then run `gprof ./name_of_app gmon.out`. Or if you want to see the assembly language behind it, compile with the `-S` flag. Not sure if either of this is what you want but hopefully it's something in the right direction. – Nobilis Jun 05 '13 at 13:22
-
I want to get accurate execution time of functions. And I need to shift the most time-consuming part into hardware. The reason I need the exact number of instructions is to set the boundary to my dedicated hardware logic which is used to count the number of cycles the function executed. The dedicated hardware logic is attached to the system bus and can track the information of the program counter signal in CPU. – henry Jun 05 '13 at 13:26
-
Gprof is not accurate. – henry Jun 05 '13 at 13:26
-
And Gprof is some kind of intrusive method. It affects the distribution of execution time. Gprof can not provide a good decision for my design. – henry Jun 05 '13 at 13:37
1 Answers
0
If you're talking about assembly instructions, this is pretty easy:
Make a small C program with main. Immediately in main, call your desired function. Compile with the gcc -c option (outputs an object file). Open up your object f ile (.o) in a text editor. Look for t he call function (This is the call into the function). Start counting the lines until you hit a return (ret) instruction.
There you go! Of course, your compiler will probably optimize this object code so it might be a little more complex, but this is probably a really easy way to do it.

KrisSodroski
- 2,796
- 3
- 24
- 39