t_stats.h

00001 /*
00002  *
00003  * $Id$
00004  *
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of ser, a free SIP server.
00009  *
00010  * ser is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * For a license to use the ser software under conditions
00016  * other than those described here, or to purchase support for this
00017  * software, please contact iptel.org by e-mail at the following addresses:
00018  *    info@iptel.org
00019  *
00020  * ser is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License 
00026  * along with this program; if not, write to the Free Software 
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  */
00029 
00030 
00031 #ifndef _T_STATS_H
00032 #define _T_STATS_H
00033 
00034 /* if defined even more stats are produced */
00035 #define TM_MORE_STATS
00036 
00037 #include "defs.h"
00038 
00039 #include "../../rpc.h"
00040 #include "../../pt.h"
00041 
00042 
00043 typedef unsigned long stat_counter;
00044 
00045 struct t_proc_stats {
00046         /* number of transactions in wait state */
00047         stat_counter waiting;
00048         /* number of server transactions */
00049         stat_counter transactions;
00050         /* number of UAC transactions (part of transactions) */
00051         stat_counter client_transactions;
00052         /* number of transactions which completed with this status */
00053         stat_counter completed_3xx, completed_4xx, completed_5xx, 
00054                 completed_6xx, completed_2xx;
00055         stat_counter replied_locally;
00056         stat_counter deleted;
00057 #ifdef TM_MORE_STATS
00058         /* number of created transactions */
00059         stat_counter t_created;
00060         /* number of freed transactions */
00061         stat_counter t_freed;
00062         /* number of transactions for which free was deleted */
00063         stat_counter delayed_free;
00064 #endif /* TM_MORE_STATS */
00065 };
00066 
00067 union t_stats{
00068         struct t_proc_stats s;
00069         char _pad[256]; /* pad at least to cache line size 
00070                             athlon=64, p4=128, some sparcs=256 */
00071 };
00072 extern union t_stats *tm_stats;
00073 
00074 #ifdef TM_MORE_STATS 
00075 inline void static t_stats_created(void)
00076 {
00077         /* keep it in process's piece of shmem */
00078         tm_stats[process_no].s.t_created++;
00079 }
00080 
00081 inline void static t_stats_freed(void)
00082 {
00083         /* keep it in process's piece of shmem */
00084         tm_stats[process_no].s.t_freed++;
00085 }
00086 
00087 inline void static t_stats_delayed_free(void)
00088 {
00089         /* keep it in process's piece of shmem */
00090         tm_stats[process_no].s.delayed_free++;
00091 }
00092 #else /* TM_MORE_STATS  */
00093 /* do nothing */
00094 #define t_stats_created()  do{}while(0)
00095 #define t_stats_freed()  do{}while(0)
00096 #define t_stats_delayed_free()  do{}while(0)
00097 
00098 #endif /* TM_MORE_STATS */
00099 
00100 inline void static t_stats_new(int local)
00101 {
00102         /* keep it in process's piece of shmem */
00103         tm_stats[process_no].s.transactions++;
00104         if(local) tm_stats[process_no].s.client_transactions++;
00105 }
00106 
00107 inline void static t_stats_wait(void)
00108 {
00109         /* keep it in process's piece of shmem */
00110         tm_stats[process_no].s.waiting++;
00111 }
00112 
00113 inline void static t_stats_deleted( int local )
00114 {
00115         tm_stats[process_no].s.deleted++;
00116 }
00117 
00118 inline static void update_reply_stats( int code ) {
00119         if (code>=600) {
00120                 tm_stats[process_no].s.completed_6xx++;
00121         } else if (code>=500) {
00122                 tm_stats[process_no].s.completed_5xx++;
00123         } else if (code>=400) {
00124                 tm_stats[process_no].s.completed_4xx++;
00125         } else if (code>=300) {
00126                 tm_stats[process_no].s.completed_3xx++;
00127         } else if (code>=200) {
00128                 tm_stats[process_no].s.completed_2xx++;
00129         }
00130 }
00131 
00132 
00133 inline void static t_stats_replied_locally(void)
00134 {
00135         tm_stats[process_no].s.replied_locally++;
00136 }
00137 
00138 
00139 
00140 int init_tm_stats(void);
00141 int init_tm_stats_child(void);
00142 void free_tm_stats(void);
00143 
00144 void tm_rpc_stats(rpc_t* rpc, void* c);
00145 
00146 void tm_rpc_hash_stats(rpc_t* rpc, void* c);
00147 
00148 typedef int (*tm_get_stats_f)(struct t_proc_stats *all);
00149 int tm_get_stats(struct t_proc_stats *all);
00150 
00151 #endif