5 #include <sys/time.h> //getrusage, gettimeofday
6 #include <sys/resource.h>
8 struct timeval __g_timeofday_start
, __g_timeofday_end
, __g_timeofday_diff
,\
9 __g_resource_usage_tmp
,__g_resource_usage_other_time
;
10 struct rusage __g_resource_usage
;
12 #define G_TIMER_START \
13 gettimeofday(&__g_timeofday_start,NULL)
17 getrusage(RUSAGE_SELF, &__g_resource_usage);\
18 gettimeofday(&__g_timeofday_end,NULL);\
19 timersub(&__g_timeofday_end,&__g_timeofday_start,&__g_timeofday_diff);\
20 timersub(&__g_timeofday_diff,&__g_resource_usage.ru_utime,&__g_resource_usage_tmp);\
21 timersub(&__g_resource_usage_tmp,&__g_resource_usage.ru_stime,&__g_resource_usage_other_time);\
24 #define G_TIMER_PRINT \
25 fprintf(stderr,"\n--------------------------------------------------------------------------------\n"\
26 "Resource Usage Measures:\n"\
27 " User: %ld.%06ld(s), System: %ld.%06ld(s). Real: %ld.%06ld(s).\n"\
28 " Sleep: %ld.%06ld(s). Block I/O times: %ld/%ld. MaxRSS: %ld kiB.\n"\
29 " Wait(s): %ld(nvcsw) + %ld(nivcsw). "\
30 "Page Fault(s): %ld(minflt) + %ld(majflt).\n",\
31 __g_resource_usage.ru_utime.tv_sec, __g_resource_usage.ru_utime.tv_usec,\
32 __g_resource_usage.ru_stime.tv_sec, __g_resource_usage.ru_stime.tv_usec,\
33 __g_timeofday_diff.tv_sec, __g_timeofday_diff.tv_usec,\
34 __g_resource_usage_other_time.tv_sec, __g_resource_usage_other_time.tv_usec,\
35 __g_resource_usage.ru_inblock, __g_resource_usage.ru_oublock,\
36 __g_resource_usage.ru_maxrss,\
37 __g_resource_usage.ru_nvcsw, __g_resource_usage.ru_nivcsw,\
38 __g_resource_usage.ru_minflt, __g_resource_usage.ru_majflt)