Counting function calls

  • Thread starter thorsten.schilling
  • Start date
T

thorsten.schilling

Hello,

does anybody know a "tool" or an easy method to measure the count of
function/member function calls? I just would like some kind of
statistic or raw numbers, how often a specific function is called.

Best regards,
T. Schilling
 
D

David Côme

Hello,

does anybody know a "tool" or an easy method to measure the count of
function/member function calls? I just would like some kind of
statistic or raw numbers, how often a specific function is called.

Best regards,
T. Schilling

static variable into the function with incrementation like this:
#include <iostream>

void foo(void)
{
static int num;
std::cout<<num<<std::endl;
num++;
}

int main(void)
{
foo();
foo();
}
 
T

thorsten.schilling

David said:
static variable into the function with incrementation like this:
#include <iostream>

void foo(void)
{
static int num;
std::cout<<num<<std::endl;
num++;
}

int main(void)
{
foo();
foo();
}

Hello,

yes, that is the obvious solution. But in a program with roughly
approximated 2000 functions it would be extremly intensive to change
every function to that style, or I would say impossible depicted in
hours of work. I am looking more for some debugger function, e.g. in
gdb, which tells me the count of the calls the functions recieved
after a successfull program run.

Best regards,
T. Schilling
 
E

Erik Wikström

Hello,

does anybody know a "tool" or an easy method to measure the count of
function/member function calls? I just would like some kind of
statistic or raw numbers, how often a specific function is called.

Seems to me like something a profiler should should be able to do.
 
M

Marc

yes, that is the obvious solution. But in a program with roughly
approximated 2000 functions it would be extremly intensive to change
every function to that style, or I would say impossible depicted in
hours of work. I am looking more for some debugger function, e.g. in
gdb, which tells me the count of the calls the functions recieved
after a successfull program run.

What you need is a profile of your program. If you are using g++, compile
and link it with flag -pg enabled (not sure if this also implies -g). Then,
run your program as usual. When you finish, you will notice a new file
named gmon.out. This contains all the information the profiler was able to
collect. You can see this information with gprof NAME_OF_YOUR_PROGRAM, or
using a graphical viewer, like kprof.

You can see how many times every function was called, how many time it took,
and some other useful stuff.

Marc
 
R

red floyd

Hello,

does anybody know a "tool" or an easy method to measure the count of
function/member function calls? I just would like some kind of
statistic or raw numbers, how often a specific function is called.

It's called a "Profiler". It's toolset dependent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top