These definitions can be used to trace threaded applications. Add ENTER; at the beginning and END; at the end of any functions you wish to trace. You will get prints when the function is entered and exited along with a microsecond timestamp and thread id. Note that printf() isn't probably the best function to use, for instance in Android I used ALOGD. #c #trace #debug #time
#include <time.h>
unsigned long us_time()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
}
#define ENTER printf("%ld enter %s (%d)\n", us_time(), __FUNCTION__, gettid())
#define EXIT printf("%ld exit %s (%d)\n", us_time(), __FUNCTION__, gettid())