modules_k/seas/statistics.h

00001 /* $Id$
00002  *
00003  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
00004  *
00005  * This file is part of Kamailio, a free SIP server.
00006  *
00007  * Kamailio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version
00011  *
00012  * Kamailio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License 
00018  * along with this program; if not, write to the Free Software 
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #include <sys/time.h>
00023 #include <time.h>
00024 #include "../../hashes.h"/* for TABLE_ENTRIES define*/
00025 #include "../../locking.h"/* for TABLE_ENTRIES define*/
00026 #include "../../modules/tm/h_table.h"/* for struct cell*/
00027 #define STATS_CELLS 50
00028 #define UAS_T 0
00029 #define UAC_T 1
00030 
00037 struct statscell
00038 {
00040    char type;
00042    union {
00043       struct {
00044          struct timeval as_relay;
00045          struct timeval event_sent;
00046          struct timeval action_recvd;
00047       } uas;
00048       struct {
00049          struct timeval action_recvd;
00050          struct timeval event_sent;
00051          struct timeval action_reply_sent;
00052       } uac;
00053    }u;
00054 };
00055 
00057 struct statstable
00058 {
00059    gen_lock_t *mutex;
00060    unsigned int dispatch[15];
00061    unsigned int event[15];
00062    unsigned int action[15];
00063    unsigned int started_transactions;
00064    unsigned int finished_transactions;
00065    unsigned int received_replies;
00066    unsigned int received;
00067 };
00068 
00069 extern struct statstable *seas_stats_table;
00070 
00074 struct statstable* init_seas_stats_table(void);
00075 inline int stop_stats_server(void);
00076 inline void destroy_seas_stats_table(void);
00080 void serve_stats(int fd);
00081 int start_stats_server(char *socket);
00082 inline int print_stats_info(int f,int sock);
00086 inline void as_relay_stat(struct cell *t);
00087 inline void event_stat(struct cell *t);
00088 inline void action_stat(struct cell *t);
00089 inline void stats_reply(void);
00090 #define receivedplus() \
00091    do{ \
00092       lock_get(seas_stats_table->mutex); \
00093       seas_stats_table->received++; \
00094       lock_release(seas_stats_table->mutex); \
00095    }while(0)