Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5105 Discussions

Finding hotspot within a #define statement

Detlef_S_
Beginner
1,046 Views

We are using a #define statement, which would produce sometimes up to 100 lines of code.

Vtune just treats it as one line, but I would love to find hotspots within the detailed lines produced.

Is there an easy way to do so?

thanks! 

0 Kudos
8 Replies
Peter_W_Intel
Employee
1,046 Views

For example, you have a macro define for one function, actually C/C++ preprocessor of compiler will expand it then parse it, then build it. So all function lines always are located at macro definition which is one line (many lines with `\`).

I suspect that you may use preprocessor to generate medium files which expand all, such as macros and include files, then you use compiler to build these medium files (treat them as source files), VTune Amplifier may locate at right source lines with performance data. 

0 Kudos
Detlef_S_
Beginner
1,046 Views

Thanks for the reply,

the situation is not too different from a function call I think. The code is always in one line as well. What makes it a little more difficult is, that we give code to a macro parameter...

I will give gcc option -save-temps a chance folowing your advice:)

0 Kudos
TimP
Honored Contributor III
1,046 Views

Options like -debug inline-debug-info may be needed also, as would be the case when inline functions are employed in place of macros.

I think where Peter said medium the more usual term is intermediate, but his meaning was understood.

0 Kudos
Peter_W_Intel
Employee
1,046 Views

Thanks to Tim. Correct me that "intermediate" is right terminology in stead of "medium":-)

0 Kudos
Detlef_S_
Beginner
1,046 Views

Thanks for your suggestions!

I did use -save-temps now, and I get the .ii intermediate file. But I can not convince vtune to use it?!

In the documentation of vtune I find only very little information on.ii files. More or less I only find, that they are supported....

In the source display of vtune I would expect .ii file to be an additional choice to .cc and assembly display?!

Thanks for any ideas:) 

0 Kudos
Vitaly_S_Intel
Employee
1,046 Views

Hi Detlef S.,

Unfortunately VTune currently can't attribute performance metrics on lines of C macroses through that should be possible to do for gcc if debug info generated in DWARF.

I guess Peter meant to run preprocessor on source file manually, replace original file by preprocessed one in your source tree, recompile your application and rerun analysis.

0 Kudos
Peter_W_Intel
Employee
1,046 Views

@Vitaly

Thank you to clarify again.

@Detlef

Here is a simple example:

# g++ -E -P primes.cpp > primes.pre.cpp
# g++ -g primes.pre.cpp -openmp -o primes -lpthread

Now you can use VTune Amplifier XE to collect data, and primes.pre.cpp will be treated in source in VTune report.

My colleague Feilong Huang (compiler guy) told me, that "-P" is important to remove all source line info with original source file in primes.pre.cpp.

 

0 Kudos
Detlef_S_
Beginner
1,046 Views

Thank you very much!

As my project is quite large this approch is a little unhandy. More important: gcc preprocesor puts the whole define in one line again, so that you would again get only one number. 

Therefor you would have to add a search/replace to introduce line breaks...

I used the following for now: turned on -save-temps, compiled. Now I got .ii filed with unroled macros additionaly to the normal compiled executable. I took the unroled macro, where I suspected the hot spot from the previous vtunes run where I got a number for the line.

I made a search replace to break the .ii line into multi lines and replaced the macro in the .cc file with this by hand. now rcompile and rund vtune again, and there you are.

Thanks so much for your help!

0 Kudos
Reply