0

I want to profile a specific function in a large piece of code using Intel Pin. I have compiled my code with -O3, so I cannot access the debug symbols. I'm compiling my code using the following command: gcc -O3 -march=native -pedantic -o bin/baseline_main baseline_main/main.c.

I have written a pin tool to track branches and count them. The tool looks at the instructions and if an instruction is a branch instruction, it adds a call to increment a counter. At the end of the profiling period, the tools simply prints out the branch instruction count.

If I run this tools with a simple C code with no branches, I still get a branch count of 25950. The code which gave me this number is shown below. I suppose that this count is not zero due to the code being executed by my OS's loader. I want to know if I can somehow tell the pin tool to only instrument the main function and to ignore the rest of the execution.

#include <stdio.h>
#include <stdbool.h>                                                                                                                                           

int main()
{
        volatile bool x = false;
        volatile int y = 0;
        return 0;
}
Setu
  • 180
  • 8
  • Use `-O3 -g`. Including symbol names is not mutually exclusive with optimization. – Peter Cordes Feb 01 '23 at 17:59
  • @PeterCordes I have two follow up questions. 1: Wouldn't adding -g disable certain optimizations? 2. How can I detect labels in my pin tool? – Setu Feb 02 '23 at 02:45
  • No effect on code-gen. Did you look at the linked duplicates (scroll up to the top of the page)? The one about `-O2` and `-g` covers that in a comment on the top answer. As for symbols in PIN, the other duplicate cover that, I think. I'm not very familiar with PIN tools, but those look like they're basically doing the same thing, or would be easy to adapt. – Peter Cordes Feb 02 '23 at 02:52

0 Answers0