472,967 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,967 software developers and data experts.

how to identify the number of calls of a fuction

Hi,
Can you tell me is there some procedure to calculate the number of
calls of a function during run time?
How to insert a counter and how to increment it? and possibly which
function have called it how many times?

Thanks
Regards
Mayank Jain
+919818390836

Aug 7 '07 #1
8 1502
co***************@gmail.com wrote:
Can you tell me is there some procedure to calculate the number of
calls of a function during run time?
Yes, it's called "call counter". You place

unsigned my_function_counter;

right before the function, in the global scope. Then the very first
statement in the function should be

++my_function_counter;

and then at the end of your program you simply print the counter out.
How to insert a counter and how to increment it? and possibly which
function have called it how many times?
Ah... Which function... You need a profiler. Just use the proper
tool for the job.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 7 '07 #2
Erik Wikström wrote:
[..]
BTW: A bit off-topic but, is there any good, free profiler for
windows.
BTW, a bit off-topic, but, wouldn't it be too much to ask to use
proper punctuation? You know, like the question mark I put after
I asked a question...

"Good" and "free" rarely coexist in a characterisation of a piece
of software, especially when development tools are concerned.
Just get a trial version of AQtime, you get two weeks of use, it
should be enough to learn the tool and to improve the performance
of your program. Then buy it. Don't get cheap when tools are
concerned. A good tool is worth every penny.
This seems to be one of those where you can only get two out
of three. Either it's good but not free, free but not good, or not
for windows.
Yep.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 7 '07 #3
Victor Bazarov wrote:
co***************@gmail.com wrote:
>Can you tell me is there some procedure to calculate the number of
calls of a function during run time?

Yes, it's called "call counter". You place

unsigned my_function_counter;

right before the function, in the global scope. Then the very first
statement in the function should be

++my_function_counter;

and then at the end of your program you simply print the counter out.
Why not a static variable inside the function?
--
SM
rot13 for email
Aug 7 '07 #4
Shadowman wrote:
Victor Bazarov wrote:
>co***************@gmail.com wrote:
>>Can you tell me is there some procedure to calculate the number of
calls of a function during run time?

Yes, it's called "call counter". You place

unsigned my_function_counter;

right before the function, in the global scope. Then the very first
statement in the function should be

++my_function_counter;

and then at the end of your program you simply print the counter out.

Why not a static variable inside the function?
How would you print it out?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 7 '07 #5
On Aug 7, 9:23 pm, Shadowman <funqbjzna...@pbzpnfg.argwrote:
Victor Bazarov wrote:
contactmayankj...@gmail.com wrote:
Can you tell me is there some procedure to calculate the number of
calls of a function during run time?
Yes, it's called "call counter". You place
unsigned my_function_counter;
right before the function, in the global scope. Then the very first
statement in the function should be
++my_function_counter;
and then at the end of your program you simply print the counter out.

Why not a static variable inside the function?
you will have to either return that variable by value or store it in a
global variable before return in which case simply using a global is
more efficient.

regards,
FM.

Aug 7 '07 #6
On Aug 7, 8:21 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
contactmayankj...@gmail.com wrote:
Can you tell me is there some procedure to calculate the number of
calls of a function during run time?

Yes, it's called "call counter". You place

unsigned my_function_counter;

right before the function, in the global scope. Then the very first
statement in the function should be

++my_function_counter;

and then at the end of your program you simply print the counter out.
How to insert a counter and how to increment it? and possibly which
function have called it how many times?

Ah... Which function... You need a profiler. Just use the proper
tool for the job.

V
you can also get a pointer to caller as an argument of the callee
which is then stored in a container:

typedef std::pair<void(*)(void),std::stringmypair;

inline std::vector< mypair >& call_map(){
static std::vector< mypair data;
return data;
};

void callee(void (* mycaller)(void),std::string caller_name){

call_map().push_back(mypair(mycaller,caller_name)) ;
...//go on
};

void caller(void){
callee(&caller,"caller");

};

void print(const mypair& mp){
//do some printing on mp
};

int main (void){
caller();
std::cout<<"callee count="<<call_map().size()<<endl;
std::for_each(call_map().begin(),call_map.end(),pr int);
return 0;
};

regards,
FM.

Aug 7 '07 #7
On Aug 7, 7:58 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Erik Wikström wrote:
[..]
BTW: A bit off-topic but, is there any good, free profiler for
windows.
"Good" and "free" rarely coexist in a characterisation of a piece
of software, especially when development tools are concerned.
I tend to agree, although there are notable exceptions,
precisely in the domain of development tools: g++ and gprof.
Also, regrettably "good" and "commercial" rarely coexist either.

Logically, commercial software has definite advantages: the
additional leverage over employees can't hurt (although abusing
it is not the best way to get the process to work).
Practically, hackers seem to abound in both commercial and free
software, and even acceptable quality is the exception for both.
And leverage or not, some non-commercial operations, like g++,
have managed to implement a fairly good development
process---better, at any rate, than that in most commercial
organizations.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 8 '07 #8
On Aug 7, 7:16 pm, "contactmayankj...@gmail.com"
<contactmayankj...@gmail.comwrote:
Can you tell me is there some procedure to calculate the number of
calls of a function during run time?
How to insert a counter and how to increment it? and possibly which
function have called it how many times?
It's implementation dependent, but any good compiler should have
an option to do this automatically, writing the results out to a
file at the end of execution. (With g++, for example, the
option is -pg. And the output is written in a binary format, so
you need an additional tool, gprof, to read it. On the other
hand, you get a lot more than just the counts of how many times
each function has been called.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
11
by: Yelena Varshal via AccessMonster.com | last post by:
Hello, I have a problem with one of msaccess.exe API calls that work on my desctop but does not work on the laptop from within MS ACCESS. There is a lot of differences between 2 computers...
3
by: srinithi | last post by:
1.write a program to identify whether a character entered by a user is a vowel or a consonant? 2.write a program to identify whether the number entered by user is even or odd? 3.write a program to...
1
by: =?Utf-8?B?RFdhdHNvbkNyeXBLZXk=?= | last post by:
I need to be able to monitor a file and identify which processes have accessed them. Kind of like Windows Filemon does. The FileSystemWatcher doesn't seem to provide this information, and I can't...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.