5 #include <sys/time.h> //getrusage, gettimeofday
6 #include <sys/resource.h>
12 struct timeval __g_timeofday_start
, __g_timeofday_end
, __g_timeofday_diff
,\
13 __g_resource_usage_tmp
,__g_resource_usage_other_time
;
14 struct rusage __g_resource_usage
;
16 #define G_TIMER_START \
17 gettimeofday(&__g_timeofday_start,NULL)
21 getrusage(RUSAGE_SELF, &__g_resource_usage);\
22 gettimeofday(&__g_timeofday_end,NULL);\
23 timersub(&__g_timeofday_end,&__g_timeofday_start,&__g_timeofday_diff);\
24 timersub(&__g_timeofday_diff,&__g_resource_usage.ru_utime,&__g_resource_usage_tmp);\
25 timersub(&__g_resource_usage_tmp,&__g_resource_usage.ru_stime,&__g_resource_usage_other_time);\
28 #define __G_TIMER_PRINT(__sustype__) \
29 fprintf(stderr,"\n--------------------------------------------------------------------------------\n"\
30 "Resource Usage Measures:\n"\
31 " User: %ld."__sustype__"(s), System: %ld."__sustype__"(s). Real: %ld."__sustype__"(s).\n"\
32 " Sleep: %ld."__sustype__"(s). Block I/O times: %ld/%ld. MaxRSS: %ld kiB.\n"\
33 " Wait(s): %ld(nvcsw) + %ld(nivcsw). "\
34 "Page Fault(s): %ld(minflt) + %ld(majflt).\n",\
35 __g_resource_usage.ru_utime.tv_sec, __g_resource_usage.ru_utime.tv_usec,\
36 __g_resource_usage.ru_stime.tv_sec, __g_resource_usage.ru_stime.tv_usec,\
37 __g_timeofday_diff.tv_sec, __g_timeofday_diff.tv_usec,\
38 __g_resource_usage_other_time.tv_sec, __g_resource_usage_other_time.tv_usec,\
39 __g_resource_usage.ru_inblock, __g_resource_usage.ru_oublock,\
40 __g_resource_usage.ru_maxrss,\
41 __g_resource_usage.ru_nvcsw, __g_resource_usage.ru_nivcsw,\
42 __g_resource_usage.ru_minflt, __g_resource_usage.ru_majflt)
45 #define G_TIMER_PRINT __G_TIMER_PRINT("%06ld")
47 #define G_TIMER_PRINT __G_TIMER_PRINT("%06d")
49 # error "Unknown compiler !"