2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
* Authors : Benjamin GAUTHIER - 24 Mar 2004
20
* From Hewlett Packard Company.
28
#define TIME_LENGTH 32
29
#define DEFAULT_FILE_NAME (char*)"dumpFile"
30
#define DEFAULT_EXTENSION (char*)".csv"
32
#define MAX_REPARTITION_HEADER_LENGTH 1024
33
#define MAX_REPARTITION_INFO_LENGTH 1024
34
#define MAX_CHAR_BUFFER_SIZE 256
46
__________________________________________________________________________
49
__________________________________________________________________________
53
* This class provides some means to compute and display statistics.
54
* This is a singleton class.
61
* This struct is used for repartition table
62
* border max is the max value allow for this range
63
* nbInThisBorder is the counter of value in this range
65
typedef struct _T_dynamicalRepartition
67
unsigned int borderMax;
68
unsigned long nbInThisBorder;
69
} T_dynamicalRepartition;
76
E_CREATE_OUTGOING_CALL,
77
E_CREATE_INCOMING_CALL,
79
E_CALL_SUCCESSFULLY_ENDED,
83
E_ADD_RESPONSE_TIME_DURATION,
84
E_FAILED_CANNOT_SEND_MSG,
85
E_FAILED_MAX_UDP_RETRANS,
86
E_FAILED_UNEXPECTED_MSG,
87
E_FAILED_CALL_REJECTED,
88
E_FAILED_CMD_NOT_SENT,
89
E_FAILED_REGEXP_DOESNT_MATCH,
90
E_FAILED_REGEXP_HDR_NOT_FOUND,
99
// Cumulative counters
100
CPT_C_IncomingCallCreated,
101
CPT_C_OutgoingCallCreated,
102
CPT_C_SuccessfulCall,
105
CPT_C_NbOfCallUsedForAverageCallLength,
106
CPT_C_AverageCallLength,
107
CPT_C_NbOfCallUsedForAverageResponseTime,
108
CPT_C_AverageResponseTime,
109
CPT_C_FailedCallCannotSendMessage,
110
CPT_C_FailedCallMaxUdpRetrans,
111
CPT_C_FailedCallUnexpectedMessage,
112
CPT_C_FailedCallCallRejected,
113
CPT_C_FailedCallCmdNotSent,
114
CPT_C_FailedCallRegexpDoesntMatch,
115
CPT_C_FailedCallRegexpHdrNotFound,
119
// Periodic Display counter
120
CPT_PD_IncomingCallCreated, // must be first (RESET_PD_COUNTER macro)
121
CPT_PD_OutgoingCallCreated,
122
CPT_PD_SuccessfulCall,
124
CPT_PD_NbOfCallUsedForAverageCallLength,
125
CPT_PD_AverageCallLength,
126
CPT_PD_NbOfCallUsedForAverageResponseTime,
127
CPT_PD_AverageResponseTime,
128
CPT_PD_FailedCallCannotSendMessage,
129
CPT_PD_FailedCallMaxUdpRetrans,
130
CPT_PD_FailedCallUnexpectedMessage,
131
CPT_PD_FailedCallCallRejected,
132
CPT_PD_FailedCallCmdNotSent,
133
CPT_PD_FailedCallRegexpDoesntMatch,
134
CPT_PD_FailedCallRegexpHdrNotFound,
135
CPT_PD_OutOfCallMsgs,
136
CPT_PD_AutoAnswered, // must be last (RESET_PD_COUNTER)
138
// Periodic logging counter
139
CPT_PL_IncomingCallCreated, // must be first (RESET_PL_COUNTER macro)
140
CPT_PL_OutgoingCallCreated,
141
CPT_PL_SuccessfulCall,
143
CPT_PL_NbOfCallUsedForAverageCallLength,
144
CPT_PL_AverageCallLength,
145
CPT_PL_NbOfCallUsedForAverageResponseTime,
146
CPT_PL_AverageResponseTime,
147
CPT_PL_FailedCallCannotSendMessage,
148
CPT_PL_FailedCallMaxUdpRetrans,
149
CPT_PL_FailedCallUnexpectedMessage,
150
CPT_PL_FailedCallCallRejected,
151
CPT_PL_FailedCallCmdNotSent,
152
CPT_PL_FailedCallRegexpDoesntMatch,
153
CPT_PL_FailedCallRegexpHdrNotFound,
154
CPT_PL_OutOfCallMsgs,
155
CPT_PL_AutoAnswered, // must be last (RESET_PL_COUNTER)
164
* Get the single instance of the class.
166
* Only one instance of CStat exists in the component. This
167
* instance is automatically created the first time the instance()
170
* @return the single instance of the CStat class.
172
static CStat* instance ();
175
* Delete the single instance of the class.
177
* Only one instance of CStat exists in the component. This
178
* instance is deleted when the close method is called.
183
* ComputeStat Methods are used to modify counter value
184
* It's the main interface to update counter
186
* @return 0 if the action is known
189
int computeStat (E_Action P_action);
190
int computeStat (E_Action P_action, unsigned long P_value);
193
* GetStat Method is used to retrieve a counter value
195
* @return the counter value
197
unsigned long GetStat (E_CounterName P_counter);
202
* This method converts a struct timeval parameter into a printable string
203
* in the format given in parameter.
206
* @return a pointer on a static string containing formated time
208
char* formatTime (struct timeval* P_tv);
211
* setRepartitionCallLength
212
* - set the unsigned int table passed in parameter as the repartition table
213
* for call length. This is done by calling the initRepartition methode on
214
* the M_CallLengthRepartition variable.
215
* - set the char* list of int (must be separeted with coma as the
216
* repartition table for call length
217
* This is done by calling the createIntegerTable to transform the char*
218
* list into unsigned int list. Then the initRepartition methode is
219
* call with the created unsigned int list and the M_CallLengthRepartition
222
* setRepartitionResponseTime
223
* Same than setRepartitionCallLength with the variable
224
* M_ResponseTimeRepartition variableinstead of M_CallLengthRepartition
227
void setRepartitionCallLength (unsigned int* repartition, int nombre);
228
void setRepartitionCallLength (char * liste);
229
void setRepartitionResponseTime (unsigned int* repartition, int nombre);
230
void setRepartitionResponseTime (char * liste);
232
/* define the file name to use to dump statistic in file */
233
void setFileName (char * name);
234
void setFileName (char * name, char * extension);
237
* Display data periodically updated on screen.
239
void displayData (FILE *f);
240
void displayStat(FILE *f);
241
void displayRepartition(FILE *f);
245
* Dump data periodically in the file M_FileName
250
* initialize the class variable member
259
* Made private because this is a singleton class.
266
* Made private because this is a singleton class.
270
static CStat* M_instance;
271
unsigned long M_counters[E_NB_COUNTER];
272
T_dynamicalRepartition* M_ResponseTimeRepartition;
273
T_dynamicalRepartition* M_CallLengthRepartition;
274
int M_SizeOfResponseTimeRepartition;
275
int M_SizeOfCallLengthRepartition;
276
struct timeval M_startTime;
277
struct timeval M_pdStartTime;
278
struct timeval M_plStartTime;
280
bool M_headerAlreadyDisplayed;
282
ofstream* M_outputStream;
284
unsigned long long M_C_sumCallLength;
285
unsigned long long M_C_sumResponseTime;
286
unsigned long long M_PD_sumCallLength;
287
unsigned long long M_PD_sumResponseTime;
288
unsigned long long M_PL_sumCallLength;
289
unsigned long long M_PL_sumResponseTime;
293
* This methode is used to create the repartition table with a table of
294
* unsigned int the reparition is created like following, with Vi the given
301
* So the repartition table have the size n+1 if the given table has a size
303
void initRepartition(unsigned int* repartition, int nombre,
304
T_dynamicalRepartition ** tabRepartition, int* nbTab);
308
* this method try to create a table of unsigned int with the list of char*
309
* passed in parameters
310
* if it succed, it's return true (1)
311
* else it's return false (0)
313
int createIntegerTable(char * P_listeStr,
314
unsigned int ** listeInteger,
319
* this method check if the char* passed in parameter in really a list of
320
* integer separated with comma.
321
* if yes, it's return true (1)
322
* else, it's return false (0)
324
int isWellFormed(char * P_listeStr, int * nombre);
328
* The methode look for the place to set the value passed in parameter
329
* Once found, the associeted counter is incremented
331
void updateRepartition( T_dynamicalRepartition* tabRepart,
333
unsigned long value);
337
* Display the repartition passed in parameter at the screen
339
void displayRepartition(FILE *f,
340
T_dynamicalRepartition * tabRepartition,
345
* return a string with the range description of the given repartition
347
char* sRepartitionHeader(T_dynamicalRepartition * tabRepartition,
349
char* P_repartitionName);
353
* return a string with the number of value in the differente range of the
356
char* sRepartitionInfo(T_dynamicalRepartition * tabRepartition,
360
* UpdateAverageCounter
361
* This methode compute the real moyenne with the passed value on the given
364
void updateAverageCounter(E_CounterName P_AverageCounter,
365
E_CounterName P_NbOfCallUsed,
366
unsigned long long* P_sum,
367
unsigned long P_value);
370
* computeDiffTimeInMs.
372
* This method calculates elaped time in ms
374
* @param tf = final date
375
* @param ti = initial date
377
* @return number of ms between the 2 dates
379
long computeDiffTimeInMs (struct timeval* tf, struct timeval* ti);
384
* This converts an unsigned long containing a number of ms
385
* into a string expressing the same value in format HH:MM:SS.
389
* @return a pointer on a static string containing formated time
391
char* msToHHMMSS (unsigned long P_ms);
396
* This converts an unsigned long containing a number of ms
397
* into a string expressing the same value in format HH:MM:SS:mmm.
401
* @return a pointer on a static string containing formated time
403
char* msToHHMMSSmmm (unsigned long P_ms);
408
* To prevent public copy ctor usage: no implementation
410
CStat (const CStat&);
415
* To prevent public operator= usage: no implementation
417
CStat& operator=(const CStat&);