C- Measure the number of read records caused by a function
I want to check the number of read records made by a function. says my c program has two functions that are called separately from main (), both functions provide some kind of read activity (or system calls for I / O operations). Now I want to make a comparative analysis of both functions from an I / O point of view.
Please help, thanks
source to share
Write wrappers around the I / O functions so that you increment the counter when you call the wrapper, for example:
void custom_read(int *counter) {
*counter++;
real_read();
}
/* ... */
int read_counter = 0;
custom_read(&read_counter);
custom_read(&read_counter);
...
custom_read(&read_counter);
source to share
It is essentially a mixture of code coverage analysis, trace trace trace, and profiling.
The tools used are very OS dependent, but the general idea is the same:
You use a call graph generator to find all the code paths that trigger the function you want to parse. Then you use the profiler to count the function calls with another function (you can, for example, filter all the events on which the function foo
calls the function bar
). You can now use code coverage analysis to see the distribution of CPU cycles spent on areas of code.
source to share