Sunday, June 24, 2007

Using Aspect C to Profile PBXT

Since our goal is to find a tool for profiling while we don't want to change/modify the existing code. So we chooses the Aspect-oriented C tool as the profiling language.

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.

long pbxt_profile_pread_access_time;
long pbxt_profile_pread_freq;

int around(): execution(int pread(...)) {
struct timeval start_time;
struct timeval end_time;

int val = proceed();

pbxt_profile_pread_access_time +=
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.