The basic idea is to maintain the profiling code separately, and then use Aspect C to weave the code into the original code automatically. For instance, if we are going to profile the I/O function pread, we can write the below code according Aspect specification. Then every time when pread is called, it will be executed.
#include
long pbxt_profile_pread_access_time;
long pbxt_profile_pread_freq;
int around(): execution(int pread(...)) {
struct timeval start_time;
struct timeval end_time;
gettimeofday(&start_time,NULL);
int val = proceed();
gettimeofday(&end_time,NULL);
pbxt_profile_pread_access_time +=
(end_time.tv_sec-start_time.tv_sec)*1000000+
(end_time.tv_usec-start_time.tv_usec);
pbxt_profile_pread_freq ++;
return val;
}
The limitation of Aspect C is that it only works for pure C code, and thus it cannot profile our C++ code. So I am also trying to use Aspect C++ for profiling the C++ part.
No comments:
Post a Comment