benchmark.h

Go to the documentation of this file.
00001 /*
00002  * $Id: benchmark.h 825 2007-02-16 13:04:16Z bastian $
00003  *
00004  * Benchmarking module for Kamailio
00005  *
00006  * Copyright (C) 2007 Collax GmbH
00007  *                    (Bastian Friedrich <bastian.friedrich@collax.com>)
00008  * Copyright (C) 2007 Voice Sistem SRL
00009  *
00010  * This file is part of Kamailio, a free SIP server.
00011  *
00012  * Kamailio is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version
00016  *
00017  * Kamailio is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 /*! \file
00029  * \brief Benchmark :: Module Core
00030  *
00031  * \ingroup benchmark
00032  * - \ref benchmark.c
00033  * - Module: benchmark
00034  */
00035 
00036 
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 /* nano seconds */
00049 typedef struct timespec bm_timeval_t;
00050 #else
00051 /* micro seconds */
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;    /* Current timer run */
00061    long long calls;     /* Number of runs of this timer */
00062    long long sum;       /* Accumulated runtime of this timer */
00063    long long last_sum;     /* Accumulated runtime since last logging */
00064    long long last_max;     /* Minimum in current period (between
00065                         granularity) */
00066    long long last_min;     /* Maximum ... */
00067    long long global_max;   /* Global minimum, since start */
00068    long long global_min;   /* ...    maximum ... */
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 /* _BENCHMARK_MOD_H_ */

Generated on Thu May 17 12:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6