How to keep track of call statistics? C++

Posted by tf.rz on Stack Overflow See other posts from Stack Overflow or by tf.rz
Published on 2012-07-02T21:14:19Z Indexed on 2012/07/02 21:15 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

I'm working on a project that delivers statistics to the user. I created a class called Dog, And it has several functions. Speak, woof, run, fetch, etc.

I want to have a function that spits out how many times each function has been called. I'm also interested in the constructor calls and destructor calls as well.

I have a header file which defines all the functions, then a separate .cc file that implements them. My question is, is there a way to keep track of how many times each function is called?

I have a function called print that will fetch the "statistics" and then output them to standard output. I was considering using static integers as part of the class itself, declaring several integers to keep track of those things. I know the compiler will create a copy of the integer and initialize it to a minimum value, and then I'll increment the integers in the .cc functions.

I also thought about having static integers as a global variable in the .cc. Which way is easier? Or is there a better way to do this?

Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about c++

Related posts about class