Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00037 #ifndef _BENCHMARK_MOD_H_
00038 #define _BENCHMARK_MOD_H_
00039
00040 #include <sys/time.h>
00041 #include <time.h>
00042
00043 #include "benchmark_api.h"
00044
00045 #define BM_NAME_LEN 32
00046
00047 #ifdef BM_CLOCK_REALTIME
00048
00049 typedef struct timespec bm_timeval_t;
00050 #else
00051
00052 typedef struct timeval bm_timeval_t;
00053 #endif
00054
00055 typedef struct benchmark_timer
00056 {
00057 char name[BM_NAME_LEN];
00058 unsigned int id;
00059 int enabled;
00060 bm_timeval_t *start;
00061 unsigned long long calls;
00062 unsigned long long sum;
00063 unsigned long long last_sum;
00064 unsigned long long last_max;
00065
00066 unsigned long long last_min;
00067 unsigned long long global_max;
00068 unsigned long long global_min;
00069 struct benchmark_timer *next;
00070 } benchmark_timer_t;
00071
00072 inline int bm_get_time(bm_timeval_t *t)
00073 {
00074 #ifdef BM_CLOCK_REALTIME
00075 if(clock_gettime(CLOCK_REALTIME, t)!=0)
00076 #else
00077 if(gettimeofday(t, NULL))
00078 #endif
00079 {
00080 LM_ERR("error getting current time\n");
00081 return -1;
00082 }
00083
00084 return 0;
00085 }
00086
00087 inline unsigned long long bm_diff_time(bm_timeval_t *t1, bm_timeval_t *t2)
00088 {
00089 unsigned long long tdiff;
00090
00091 tdiff = t1->tv_sec - t1->tv_sec;
00092
00093 #ifdef BM_CLOCK_REALTIME
00094 tdiff = tdiff*1000000000 + t2->tv_nsec - t1->tv_nsec;
00095 #else
00096 tdiff = tdiff*1000000 + t2->tv_usec - t1->tv_usec;
00097 #endif
00098
00099 return tdiff;
00100 }
00101
00102 #endif