问题描述:

I want to check number of read writes made by a function.lets say my c program has two functions which are called separately from main() , both function provides some read write activity (Or system calls for IO operations). Now i want to make comparative analysis of both functions in terms of IO.

Please help , Thanks

网友答案:

Write wrappers around IO functions, such that you increment a counter when the wrapper is called, e.g.:

void custom_read(int *counter) {
  *counter++;
  real_read();
}

/* ... */

int read_counter = 0;
custom_read(&read_counter);
custom_read(&read_counter);
...
custom_read(&read_counter);
网友答案:

This is essentially a mixture of code coverage analysis, call graph tracing and profiling.

The tools to use depend strongly on the OS, 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 analyze. Next you use a profiler, to count the invocations of functions by another function (you can for example filter all the events where a function foo calls function bar). Now you can use the code coverage analysis to see the distribution of CPU cycles spent on the areas of the code.

网友答案:

You'll need to wrap the read and write functions, and replace the read and write functions with the wrappers in your target program.

相关阅读:
Top