modules/benchmark/benchmark.h
16c91670
 /*
  * $Id: benchmark.h 825 2007-02-16 13:04:16Z bastian $
  *
9b64b9f3
  * Benchmarking module for Kamailio
16c91670
  *
  * Copyright (C) 2007 Collax GmbH
  *                    (Bastian Friedrich <bastian.friedrich@collax.com>)
  * Copyright (C) 2007 Voice Sistem SRL
  *
27642a08
  * This file is part of Kamailio, a free SIP server.
16c91670
  *
27642a08
  * Kamailio is free software; you can redistribute it and/or modify
16c91670
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
27642a08
  * Kamailio is distributed in the hope that it will be useful,
16c91670
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16c91670
  *
  */
 
92c2e59d
 /*! \file
  * \brief Benchmark :: Module Core
  *
  * \ingroup benchmark
  * - \ref benchmark.c
  * - Module: benchmark
  */
 
 
16c91670
 #ifndef _BENCHMARK_MOD_H_
 #define _BENCHMARK_MOD_H_
 
 #include <sys/time.h>
 #include <time.h>
 
 #include "benchmark_api.h"
 
 #define BM_NAME_LEN	32
 
 #ifdef BM_CLOCK_REALTIME
 /* nano seconds */
 typedef struct timespec bm_timeval_t;
 #else
 /* micro seconds */
 typedef struct timeval bm_timeval_t;
 #endif
 
 typedef struct benchmark_timer
 {
 	char name[BM_NAME_LEN];
 	unsigned int id;
 	int enabled;
 	bm_timeval_t *start;    /* Current timer run */
21698992
 	unsigned long long calls;		/* Number of runs of this timer */
 	unsigned long long sum;			/* Accumulated runtime of this timer */
 	unsigned long long last_sum;	/* Accumulated runtime since last logging */
 	unsigned long long last_max;	/* Minimum in current period (between
16c91670
 							   granularity) */
21698992
 	unsigned long long last_min;	/* Maximum ... */
 	unsigned long long global_max;	/* Global minimum, since start */
 	unsigned long long global_min;	/* ...    maximum ... */
16c91670
 	struct benchmark_timer *next;
 } benchmark_timer_t;
 
452f3223
 static inline int bm_get_time(bm_timeval_t *t)
16c91670
 {
 #ifdef BM_CLOCK_REALTIME
 	if(clock_gettime(CLOCK_REALTIME, t)!=0)
 #else
 	if(gettimeofday(t, NULL))
 #endif
 	{
 		LM_ERR("error getting current time\n");
 		return -1;
 	}
 
 	return 0;
 }
 
452f3223
 static inline unsigned long long bm_diff_time(bm_timeval_t *t1, bm_timeval_t *t2)
16c91670
 {
 	unsigned long long tdiff;
 
d9b009ef
 	tdiff = t2->tv_sec - t1->tv_sec;
 
16c91670
 #ifdef BM_CLOCK_REALTIME
 	tdiff = tdiff*1000000000 + t2->tv_nsec - t1->tv_nsec;
 #else
 	tdiff = tdiff*1000000 + t2->tv_usec - t1->tv_usec;
 #endif
 
 	return tdiff;
 }
 
 #endif /* _BENCHMARK_MOD_H_ */