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

Counting function calls

petersen__Kenni_dine
4,464 Views

Is there a simple way to make vtune (2019) count the number of times a function has been called?

0 Kudos
12 Replies
JananiC_Intel
Moderator
4,464 Views

Hi,

Thanks for reaching out.

For your information,vtune will let you know the time spent in each function but it will not have the count of function calls.For more information refer the below comment

https://software.intel.com/en-us/forums/vtune/topic/856379#comment-1958661 

0 Kudos
Vladimir_R_Intel
Employee
4,464 Views

Hi,

you can use ITT tasks or counters for that. https://software.intel.com/content/www/us/en/develop/documentation/vtune-help/top/api-support/instrumentation-and-tracing-technology-apis/instrumentation-and-tracing-technology-api-reference/counters-api.html

0 Kudos
petersen__Kenni_dine
4,464 Views

Thanks for quick answers. My problem is that i have a very large program with several 100s of functions that are called depending on a rather complicated tree of control structures, and the functions are often called several 1000 times. I am profiling two different runs with slightly different input. I would expect identical output, despite the different input. My suspicion is that that somewhere during the run, an erroneous control statement leads to a wrong function being called.

I thought a useful and simple proxy to look at in order to identify how the two runs differ would be to look at the # times the different functions have been called as this seems to be standard output of other profilers, but I suppose this is perhaps not possible by default for vtune? I tried to activate the instrument-functions option during compilation, but I was unable to see any change of the results presented by vtune, and I was also unable to find relevant documentation for this.

Anyways, is there a good, alternative way to analyse a situation like mine where I need to compare two almost identical runs and figure out where they differ? In this particular case, it would help me a lot if I know e.g. the order of the functions called. Of course, I could manually modify the code to track this information, but would it not be a somewhat standard thing to track by a profiler such as vtune?

Thanks.

0 Kudos
McCalpinJohn
Honored Contributor III
4,464 Views

The traditional way to count function calls and record their calling trees is with "gprof".

With gcc compilers, you add "-pg" to the compile and link statements.  Upon execution, the program produces a "gmon.out" file which can be processed by "gprof" to see the time spent in each function, with attribution of the function calls up the relevant calling tree.

With Intel compilers, the "-p" option sets up for the same sort of analysis.

Both gcc and Intel compilers support the "-finstrument-functions" compiler option.  This causes the compiler to emit code on entry and exit to every function, which calls a user-provided routine and passes pointers to the current routine and its caller.  These can be used to count function invocations, build calling stacks, install performance counter instrumentation, etc.  The main disadvantage of this approach is that it disables function inlining.  If you call lots of tiny functions, this can lead to a significant performance penalty.   For both gcc and Intel compilers, you can add 

__attribute__((__no_instrument_function__))

to a function to prevent it from being instrumented (and allow it to be inlined).

0 Kudos
petersen__Kenni_dine
4,464 Views

Thanks, Dr. Bandwidth

It seems that this option is not available for the Windows version of the compiler. Unfortunately, I am stuck with Windows. Does this mean that the function calls calls cannot be instrumented?

0 Kudos
McCalpinJohn
Honored Contributor III
4,464 Views

I am afraid I can't help with Windows questions -- I have not had a windows machine in over five years, and never had a good compiler on one anyway....

0 Kudos
JananiC_Intel
Moderator
4,464 Views

Hi,

Thanks for the update.

Could you let us know which Vtune version you are using?

If it is before 2019 u4 we had call count option but the latest version of Vtune doesn’t have this feature.You can also try Intel Advisor for this.

 

 

 

0 Kudos
petersen__Kenni_dine
4,464 Views

Janani: I use version 2019 update 6. I also have Intel Advisor 2019. Is there way to show see a function count using Intel Advisor?

Thanks

PS: Also thank you, Dr. Bandwidth for looking into this.

0 Kudos
JananiC_Intel
Moderator
4,457 Views

Hi,

Thanks for the update.

Kindly follow the procedures mentioned in the below link and let us know the updates.

https://software.intel.com/content/www/us/en/develop/documentation/advisor-user-guide/top/survey-trip-counts-flops-and-roofline-analyses/trip-counts-analysis.html



JananiC_Intel
Moderator
4,440 Views

Hi,

Has this issue been resolved?Could you give us an update?


0 Kudos
Zakhar_M_Intel1
Employee
4,434 Views

As Janani already mentioned, there is a dedicated tool to do Call Counts computations.

This is "Intel Advisor TripCounts" analysis. Note that this provides you with exact (precise) loops tripcount and loops/function call counts data.

In order to obtain this data you have to first run Advisor Survey analysis and afterwards Run Advisor TripCounts (FLOP and Tripcounts check-boxes ON at the workflow). The same can be done via command line.

See below:

 

callcounts.png

Regards

Zakhar 

JananiC_Intel
Moderator
4,365 Views

Hi,

We are closing the case assuming that your issue got resolved.Please raise a new thread in case of any further issues.

Thanks.


0 Kudos
Reply