~ubuntu-branches/ubuntu/utopic/sip-tester/utopic

« back to all changes in this revision

Viewing changes to .pc/enable-gsl.patch/stat.hpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Paul Belanger, Mark Purcell
  • Date: 2011-11-03 21:56:17 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20111103215617-nnxicj1oto9e8ix5
Tags: 1:3.2-1
[ Paul Belanger ]
* New Upstream Release (Closes: #623915).
* Switch to dpkg-source 3.0 (quilt) format
* Building with PCAP play.
* Switch back to Debhelper.
* debian/patches/spelling-error-in-binary: Fix lintian warning

[ Mark Purcell ]
* Drop pabs from Uploaders: at his request
* fix debhelper-overrides-need-versioned-build-depends
* fix description-synopsis-starts-with-article

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
 *
 
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.
 
11
 *
 
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
 
15
 *
 
16
 *  Authors : Benjamin GAUTHIER - 24 Mar 2004
 
17
 *            Joseph BANINO
 
18
 *            Olivier JACQUES
 
19
 *            Richard GAYRAUD
 
20
 *            From Hewlett Packard Company.
 
21
 *           
 
22
 */
 
23
 
 
24
#ifndef __STAT_H__
 
25
#define __STAT_H__
 
26
 
 
27
 
 
28
#define TIME_LENGTH 64
 
29
#define DEFAULT_FILE_NAME (char*)"dumpFile"
 
30
#define DEFAULT_EXTENSION (char*)".csv"
 
31
 
 
32
#define MAX_CHAR_BUFFER_SIZE          1024
 
33
 
 
34
#include <ctime> 
 
35
#include <sys/time.h> 
 
36
#include <time.h> 
 
37
#include <iostream>
 
38
#include <fstream>
 
39
#include <stdio.h>
 
40
 
 
41
#ifdef HAVE_GSL
 
42
#include <gsl/gsl_rng.h>
 
43
#include <gsl/gsl_randist.h>
 
44
#include <gsl/gsl_cdf.h>
 
45
#endif
 
46
 
 
47
#include "variables.hpp"
 
48
 
 
49
using namespace std;
 
50
 
 
51
/*
 
52
__________________________________________________________________________
 
53
 
 
54
              C S t a t    C L A S S
 
55
__________________________________________________________________________
 
56
*/
 
57
 
 
58
  /**
 
59
   * This class provides some means to compute and display statistics.
 
60
   * This is a singleton class.
 
61
   */
 
62
 
 
63
class CStat {
 
64
public:
 
65
 
 
66
  /* 
 
67
   * This struct is used for repartition table
 
68
   * border max is the max value allow for this range
 
69
   * nbInThisBorder is the counter of value in this range
 
70
   */
 
71
  typedef struct _T_dynamicalRepartition
 
72
  {
 
73
    unsigned int  borderMax;
 
74
    unsigned long nbInThisBorder; 
 
75
  } T_dynamicalRepartition; 
 
76
 
 
77
  typedef struct _T_value_rtt 
 
78
  {
 
79
    double  date ;
 
80
    int  rtd_no ;
 
81
    double  rtt  ;
 
82
  } T_value_rtt, *T_pValue_rtt ; 
 
83
 
 
84
  /**
 
85
   * Actions on counters
 
86
   */
 
87
  enum E_Action
 
88
  {
 
89
    E_NO_ACTION,
 
90
    E_CREATE_OUTGOING_CALL,
 
91
    E_CREATE_INCOMING_CALL,
 
92
    E_CALL_FAILED, 
 
93
    E_CALL_SUCCESSFULLY_ENDED,
 
94
    E_RESET_C_COUNTERS,
 
95
    E_RESET_PD_COUNTERS,
 
96
    E_RESET_PL_COUNTERS,
 
97
    E_ADD_CALL_DURATION,
 
98
    E_ADD_RESPONSE_TIME_DURATION,
 
99
    E_FAILED_CANNOT_SEND_MSG,
 
100
    E_FAILED_MAX_UDP_RETRANS,
 
101
    E_FAILED_TCP_CONNECT,
 
102
    E_FAILED_TCP_CLOSED,
 
103
    E_FAILED_UNEXPECTED_MSG,
 
104
    E_FAILED_CALL_REJECTED,
 
105
    E_FAILED_CMD_NOT_SENT,
 
106
    E_FAILED_REGEXP_DOESNT_MATCH,
 
107
    E_FAILED_REGEXP_SHOULDNT_MATCH,
 
108
    E_FAILED_REGEXP_HDR_NOT_FOUND,
 
109
    E_FAILED_OUTBOUND_CONGESTION,
 
110
    E_FAILED_TIMEOUT_ON_RECV,
 
111
    E_FAILED_TIMEOUT_ON_SEND,
 
112
    E_OUT_OF_CALL_MSGS,
 
113
    E_WATCHDOG_MAJOR,
 
114
    E_WATCHDOG_MINOR,
 
115
    E_DEAD_CALL_MSGS,
 
116
    E_FATAL_ERRORS,
 
117
    E_WARNING,
 
118
    E_RETRANSMISSION,
 
119
    E_AUTO_ANSWERED,
 
120
    E_ADD_GENERIC_COUNTER
 
121
  };
 
122
  /**
 
123
   * Counters management
 
124
   */
 
125
  enum E_CounterName
 
126
  {
 
127
  // Per-Scenario Counters
 
128
  // Cumulative counters
 
129
  CPT_C_IncomingCallCreated,
 
130
  CPT_C_OutgoingCallCreated,
 
131
  CPT_C_SuccessfulCall,
 
132
  CPT_C_FailedCall,
 
133
  CPT_C_CurrentCall,
 
134
  CPT_C_CurrentCallPeak,
 
135
  CPT_C_CurrentCallPeakTime,
 
136
  CPT_C_NbOfCallUsedForAverageCallLength,
 
137
  CPT_C_AverageCallLength_Sum,
 
138
  CPT_C_AverageCallLength_Squares,
 
139
  CPT_C_FailedCallCannotSendMessage,
 
140
  CPT_C_FailedCallMaxUdpRetrans,
 
141
  CPT_C_FailedCallTcpConnect,
 
142
  CPT_C_FailedCallTcpClosed,
 
143
  CPT_C_FailedCallUnexpectedMessage,
 
144
  CPT_C_FailedCallCallRejected,
 
145
  CPT_C_FailedCallCmdNotSent,
 
146
  CPT_C_FailedCallRegexpDoesntMatch,
 
147
  CPT_C_FailedCallRegexpShouldntMatch,
 
148
  CPT_C_FailedCallRegexpHdrNotFound,
 
149
  CPT_C_FailedOutboundCongestion,
 
150
  CPT_C_FailedTimeoutOnRecv,
 
151
  CPT_C_FailedTimeoutOnSend,
 
152
  CPT_C_Retransmissions,
 
153
 
 
154
  // Periodic Display counter
 
155
  CPT_PD_IncomingCallCreated, // must be first (RESET_PD_COUNTER macro)
 
156
  CPT_PD_OutgoingCallCreated,
 
157
  CPT_PD_SuccessfulCall,
 
158
  CPT_PD_FailedCall,
 
159
  CPT_PD_CurrentCallPeak,
 
160
  CPT_PD_CurrentCallPeakTime,
 
161
  CPT_PD_NbOfCallUsedForAverageCallLength,
 
162
  CPT_PD_AverageCallLength_Sum,
 
163
  CPT_PD_AverageCallLength_Squares,
 
164
  CPT_PD_NbOfCallUsedForAverageResponseTime,
 
165
  CPT_PD_NbOfCallUsedForAverageResponseTime_2, // This must match or exceed MAX_RTD_INFO
 
166
  CPT_PD_NbOfCallUsedForAverageResponseTime_3, // This must match or exceed MAX_RTD_INFO
 
167
  CPT_PD_NbOfCallUsedForAverageResponseTime_4, // This must match or exceed MAX_RTD_INFO
 
168
  CPT_PD_NbOfCallUsedForAverageResponseTime_5, // This must match or exceed MAX_RTD_INFO
 
169
  CPT_PD_AverageResponseTime_Sum,
 
170
  CPT_PD_AverageResponseTime_Sum_2,
 
171
  CPT_PD_AverageResponseTime_Sum_3,
 
172
  CPT_PD_AverageResponseTime_Sum_4,
 
173
  CPT_PD_AverageResponseTime_Sum_5,
 
174
  CPT_PD_AverageResponseTime_Squares,
 
175
  CPT_PD_AverageResponseTime_Squares_2,
 
176
  CPT_PD_AverageResponseTime_Squares_3,
 
177
  CPT_PD_AverageResponseTime_Squares_4,
 
178
  CPT_PD_AverageResponseTime_Squares_5,
 
179
  CPT_PD_FailedCallCannotSendMessage,
 
180
  CPT_PD_FailedCallMaxUdpRetrans,
 
181
  CPT_PD_FailedCallTcpConnect,
 
182
  CPT_PD_FailedCallTcpClosed,
 
183
  CPT_PD_FailedCallUnexpectedMessage,
 
184
  CPT_PD_FailedCallCallRejected,
 
185
  CPT_PD_FailedCallCmdNotSent,
 
186
  CPT_PD_FailedCallRegexpDoesntMatch,
 
187
  CPT_PD_FailedCallRegexpShouldntMatch,
 
188
  CPT_PD_FailedCallRegexpHdrNotFound,
 
189
  CPT_PD_FailedOutboundCongestion,
 
190
  CPT_PD_FailedTimeoutOnRecv,
 
191
  CPT_PD_FailedTimeoutOnSend,
 
192
  CPT_PD_Retransmissions,
 
193
 
 
194
  // Periodic logging counter
 
195
  CPT_PL_IncomingCallCreated, // must be first (RESET_PL_COUNTER macro)
 
196
  CPT_PL_OutgoingCallCreated,
 
197
  CPT_PL_SuccessfulCall,
 
198
  CPT_PL_FailedCall,
 
199
  CPT_PL_CurrentCallPeak,
 
200
  CPT_PL_CurrentCallPeakTime,
 
201
  CPT_PL_NbOfCallUsedForAverageCallLength,
 
202
  CPT_PL_AverageCallLength_Sum,
 
203
  /* The squares let us compute the standard deviation. */
 
204
  CPT_PL_AverageCallLength_Squares,
 
205
  CPT_PL_NbOfCallUsedForAverageResponseTime,
 
206
  CPT_PL_NbOfCallUsedForAverageResponseTime_2,
 
207
  CPT_PL_NbOfCallUsedForAverageResponseTime_3,
 
208
  CPT_PL_NbOfCallUsedForAverageResponseTime_4,
 
209
  CPT_PL_NbOfCallUsedForAverageResponseTime_5,
 
210
  CPT_PL_AverageResponseTime_Sum,
 
211
  CPT_PL_AverageResponseTime_Sum_2,
 
212
  CPT_PL_AverageResponseTime_Sum_3,
 
213
  CPT_PL_AverageResponseTime_Sum_4,
 
214
  CPT_PL_AverageResponseTime_Sum_5,
 
215
  CPT_PL_AverageResponseTime_Squares,
 
216
  CPT_PL_AverageResponseTime_Squares_2,
 
217
  CPT_PL_AverageResponseTime_Squares_3,
 
218
  CPT_PL_AverageResponseTime_Squares_4,
 
219
  CPT_PL_AverageResponseTime_Squares_5,
 
220
  CPT_PL_FailedCallCannotSendMessage,
 
221
  CPT_PL_FailedCallMaxUdpRetrans,
 
222
  CPT_PL_FailedCallTcpConnect,
 
223
  CPT_PL_FailedCallTcpClosed,
 
224
  CPT_PL_FailedCallUnexpectedMessage,
 
225
  CPT_PL_FailedCallCallRejected,
 
226
  CPT_PL_FailedCallCmdNotSent,
 
227
  CPT_PL_FailedCallRegexpDoesntMatch,
 
228
  CPT_PL_FailedCallRegexpShouldntMatch,
 
229
  CPT_PL_FailedCallRegexpHdrNotFound,
 
230
  CPT_PL_FailedOutboundCongestion,
 
231
  CPT_PL_FailedTimeoutOnRecv,
 
232
  CPT_PL_FailedTimeoutOnSend,
 
233
  CPT_PL_Retransmissions,
 
234
 
 
235
  E_NB_COUNTER,
 
236
 
 
237
  // Global Counters
 
238
  // Cumulative counters
 
239
  CPT_G_C_OutOfCallMsgs,
 
240
  CPT_G_C_DeadCallMsgs,
 
241
  CPT_G_C_FatalErrors,
 
242
  CPT_G_C_Warnings,
 
243
  CPT_G_C_WatchdogMajor,
 
244
  CPT_G_C_WatchdogMinor,
 
245
  CPT_G_C_AutoAnswered,
 
246
  // Periodic Display counter
 
247
  CPT_G_PD_OutOfCallMsgs,
 
248
  CPT_G_PD_DeadCallMsgs,
 
249
  CPT_G_PD_FatalErrors,
 
250
  CPT_G_PD_Warnings,
 
251
  CPT_G_PD_WatchdogMajor,
 
252
  CPT_G_PD_WatchdogMinor,
 
253
  CPT_G_PD_AutoAnswered, // must be last (RESET_PD_COUNTER)
 
254
 
 
255
  // Periodic logging counter
 
256
  CPT_G_PL_OutOfCallMsgs,
 
257
  CPT_G_PL_DeadCallMsgs,
 
258
  CPT_G_PL_FatalErrors,
 
259
  CPT_G_PL_Warnings,
 
260
  CPT_G_PL_WatchdogMajor,
 
261
  CPT_G_PL_WatchdogMinor,
 
262
  CPT_G_PL_AutoAnswered, // must be last (RESET_PL_COUNTER)
 
263
 
 
264
  E_NB_G_COUNTER,
 
265
 
 
266
  };
 
267
 
 
268
  /*
 
269
  ** exported methods
 
270
  */
 
271
 
 
272
  /**
 
273
   * Constructor.
 
274
   */
 
275
  CStat ();
 
276
 
 
277
  /**
 
278
   * Destructor.
 
279
   */
 
280
  ~CStat ();
 
281
 
 
282
 
 
283
  /**
 
284
   * Delete the single instance of the class.
 
285
   *
 
286
   * Only one instance of CStat exists in the component. This
 
287
   * instance is deleted when the close method is called.
 
288
   */
 
289
  void close (); 
 
290
 
 
291
  /**
 
292
   * ComputeStat Methods are used to modify counter value
 
293
   * It's the main interface to update counter
 
294
   *
 
295
   * @return 0 if the action is known
 
296
   *        -1 else
 
297
   */
 
298
  int computeStat (E_Action P_action);
 
299
  int computeStat (E_Action P_action, unsigned long P_value);
 
300
  int computeStat (E_Action P_action, unsigned long P_value, int which);
 
301
 
 
302
  /* This works for global counters and does not require an instance. */
 
303
  static int globalStat (E_Action P_action);
 
304
 
 
305
  /**
 
306
   * ComputeRtt Methods are used to calculate the response time
 
307
   */
 
308
  void computeRtt ( unsigned long long P_start_time, unsigned long long P_stop_time, int which);
 
309
 
 
310
  /**
 
311
   * GetStat Method is used to retrieve a counter value
 
312
   *
 
313
   * @return the counter value
 
314
   **/
 
315
  unsigned long long GetStat (E_CounterName P_counter);
 
316
  
 
317
  /* Get the current start time. */
 
318
  void getStartTime(struct timeval *t);
 
319
 
 
320
  /**
 
321
   * formatTime.
 
322
   *
 
323
   * This method converts a struct timeval parameter into a printable string
 
324
   * in the format given in parameter.
 
325
   *
 
326
   * @param P_tv.
 
327
   * @return a pointer on a static string containing formated time
 
328
   */
 
329
  static char* formatTime (struct timeval* P_tv, bool microseconds = false);
 
330
 
 
331
  /**
 
332
   * setRepartitionCallLength 
 
333
   * - set the unsigned int table passed in parameter as the repartition table 
 
334
   *   for call length. This is done by calling the initRepartition methode on 
 
335
   *   the M_CallLengthRepartition variable.
 
336
   * - set the char* list of int (must be separeted with coma as the 
 
337
   *   repartition table for call length
 
338
   *   This is done by calling the createIntegerTable to transform the char* 
 
339
   *   list into unsigned int list. Then the initRepartition methode is 
 
340
   *   call with the created unsigned int list and the M_CallLengthRepartition 
 
341
   *   variable
 
342
   *
 
343
   * setRepartitionResponseTime
 
344
   *   Same than setRepartitionCallLength with the variable
 
345
   *  M_ResponseTimeRepartition variableinstead of M_CallLengthRepartition 
 
346
   *  variable
 
347
   */
 
348
  void setRepartitionCallLength   (unsigned int* repartition, int nombre);
 
349
  void setRepartitionCallLength   (char * liste);
 
350
  void setRepartitionResponseTime (unsigned int* repartition, int nombre);
 
351
  void setRepartitionResponseTime (char * liste);
 
352
 
 
353
  /* define the file name to use to dump statistic in file */
 
354
  void setFileName                (char * name);
 
355
  void setFileName                (char * name, char * extension);
 
356
  void initRtt             (char * name, char * extension, unsigned long P_value);
 
357
 
 
358
  /**
 
359
   * Display data periodically updated on screen.
 
360
   */
 
361
  void displayData (FILE *f);
 
362
  void displayStat(FILE *f);
 
363
  void displayRepartition(FILE *f);
 
364
  void displayRtdRepartition (FILE *f, int which);
 
365
 
 
366
  /**
 
367
   * Dump data periodically in the file M_FileName
 
368
   */
 
369
  void dumpData ();
 
370
 
 
371
  void dumpDataRtt ();
 
372
 
 
373
  /**
 
374
   * initialize the class variable member
 
375
   */
 
376
  int init();
 
377
 
 
378
  /**
 
379
   * computeDiffTimeInMs.
 
380
   *
 
381
   * This method calculates elaped time in ms
 
382
   *
 
383
   * @param tf = final date
 
384
   * @param ti = initial date
 
385
   *
 
386
   * @return number of ms between the 2 dates
 
387
   */
 
388
  static long computeDiffTimeInMs (struct timeval* tf, struct timeval* ti);
 
389
 
 
390
  /**
 
391
   * msToHHMMSS.
 
392
   *
 
393
   * This converts an unsigned long containing a number of ms
 
394
   * into a string expressing the same value in format HH:MM:SS.
 
395
   *
 
396
   * @param P_ms.
 
397
   *
 
398
   * @return a pointer on a static string containing formated time
 
399
   */
 
400
  static char* msToHHMMSS (unsigned long P_ms);
 
401
 
 
402
  /**
 
403
   * msToHHMMSSmm.
 
404
   *
 
405
   * This converts an unsigned long containing a number of ms
 
406
   * into a string expressing the same value in format HH:MM:SS:mmm.
 
407
   *
 
408
   * @param P_ms.
 
409
   *
 
410
   * @return a pointer on a static string containing formated time
 
411
   */
 
412
  static char* msToHHMMSSmmm (unsigned long P_ms);
 
413
 
 
414
  /* Get a counter ID by name. */
 
415
  int findCounter(const char *counter, bool alloc);
 
416
  int findRtd(const char *name, bool start);
 
417
  void validateRtds();
 
418
  int nRtds();
 
419
 
 
420
private:
 
421
  unsigned long long       M_counters[E_NB_COUNTER];
 
422
  static unsigned long long M_G_counters[E_NB_G_COUNTER - E_NB_COUNTER];
 
423
 
 
424
#define GENERIC_C 0
 
425
#define GENERIC_PD 1
 
426
#define GENERIC_PL 2
 
427
#define GENERIC_TYPES 3
 
428
  unsigned long long       *M_genericCounters;
 
429
 
 
430
  str_int_map              M_genericMap;
 
431
  int_str_map              M_revGenericMap;
 
432
  int_str_map              M_genericDisplay;
 
433
 
 
434
  str_int_map              rtd_started;
 
435
  str_int_map              rtd_stopped;
 
436
 
 
437
#define RTD_COUNT 0
 
438
#define RTD_SUM 1
 
439
#define RTD_SUMSQ 2
 
440
#define RTD_TYPES 3
 
441
  unsigned long long       *M_rtdInfo;
 
442
  str_int_map              M_rtdMap;
 
443
  int_str_map              M_revRtdMap;
 
444
 
 
445
  T_dynamicalRepartition** M_ResponseTimeRepartition;
 
446
  T_dynamicalRepartition*  M_CallLengthRepartition;
 
447
  int                      M_SizeOfResponseTimeRepartition;
 
448
  int                      M_SizeOfCallLengthRepartition;
 
449
  struct timeval           M_startTime;
 
450
  struct timeval           M_pdStartTime;
 
451
  struct timeval           M_plStartTime;
 
452
 
 
453
  bool                     M_headerAlreadyDisplayed;
 
454
  char*                    M_fileName;
 
455
  ofstream*                M_outputStream;
 
456
 
 
457
  bool                     M_headerAlreadyDisplayedRtt ;
 
458
  char*                    M_fileNameRtt               ;
 
459
  ofstream*                M_outputStreamRtt           ;
 
460
  double                   M_time_ref                  ;
 
461
 
 
462
  T_pValue_rtt             M_dumpRespTime              ;
 
463
  unsigned int             M_counterDumpRespTime       ;
 
464
  unsigned long            M_report_freq_dumpRtt       ;
 
465
 
 
466
  /**
 
467
   * initRepartition
 
468
   * This methode is used to create the repartition table with a table of 
 
469
   * unsigned int the reparition is created like following, with Vi the given 
 
470
   * value in the table
 
471
   * 0    <= x <  V1  
 
472
   * V1   <= x <  V2 
 
473
   *  ...
 
474
   * Vn-1 <= x <  Vn
 
475
   *         x >= Vn
 
476
   * So the repartition table have the size n+1 if the given table has a size 
 
477
   * of n */
 
478
  void  initRepartition(unsigned int* repartition, int nombre,
 
479
                        T_dynamicalRepartition ** tabRepartition, int* nbTab);
 
480
  
 
481
  /**
 
482
   * createIntegerTable
 
483
   * this method try to create a table of unsigned int with the list of char* 
 
484
   * passed in parameters
 
485
   * if it succed, it's return true (1)
 
486
   * else it's return false (0)
 
487
   */
 
488
  int  createIntegerTable(char * P_listeStr, 
 
489
                          unsigned int ** listeInteger, 
 
490
                          int * sizeOfList);
 
491
 
 
492
  /**
 
493
   * isWellFormed
 
494
   * this method check if the char* passed in parameter in really a list of  
 
495
   * integer separated with comma.
 
496
   * if yes, it's return true (1)
 
497
   * else, it's return false (0)
 
498
   */
 
499
  int  isWellFormed(char * P_listeStr, int * nombre);
 
500
 
 
501
  /**
 
502
   * updateRepartition
 
503
   * The method looks for the place to set the value passed in parameter
 
504
   * Once found, the associated counter is incremented
 
505
   */
 
506
  void  updateRepartition( T_dynamicalRepartition* tabRepart, 
 
507
                           int sizeOfTab, 
 
508
                           unsigned long value);
 
509
 
 
510
  /**
 
511
   * resetRepartition
 
512
   * Zeros out all repartition counters.
 
513
   */
 
514
  void  resetRepartition(T_dynamicalRepartition* P_tabReport,
 
515
                         int P_sizeOfTab);
 
516
  /**
 
517
   * displayRepartition
 
518
   * Display the repartition passed in parameter at the screen
 
519
   */
 
520
  void  displayRepartition(FILE *f,
 
521
                           T_dynamicalRepartition * tabRepartition, 
 
522
                           int sizeOfTab);
 
523
 
 
524
  /**
 
525
   * sRepartitionHeader
 
526
   * return a string with the range description of the given repartition
 
527
   */
 
528
  char* sRepartitionHeader(T_dynamicalRepartition * tabRepartition, 
 
529
                           int sizeOfTab,
 
530
                           char* P_repartitionName);
 
531
 
 
532
  /**
 
533
   * sRepartitionInfo
 
534
   * return a string with the number of value in the differente range of the 
 
535
   * given repartition
 
536
   */
 
537
  char* sRepartitionInfo(T_dynamicalRepartition * tabRepartition, 
 
538
                         int sizeOfTab);
 
539
 
 
540
  /**
 
541
   * UpdateAverageCounter
 
542
   * This methode compute the real moyenne with the passed value on the given 
 
543
   * counter
 
544
   */
 
545
  void updateAverageCounter(E_CounterName P_SumCounter,
 
546
                            E_CounterName P_NbOfCallUsed,
 
547
                            E_CounterName P_Squares,
 
548
                            unsigned long P_value);
 
549
 
 
550
  /**
 
551
   * computeStdev
 
552
   * This method computes the standard deviation using our recorded mean
 
553
   * and recorded mean square.
 
554
   */
 
555
  double computeStdev(E_CounterName P_SumCounter,
 
556
                             E_CounterName P_NbOfCallUsed,
 
557
                             E_CounterName P_Squares);
 
558
 
 
559
  /**
 
560
   * computeMean
 
561
   * This method computes the recorded sum and count.
 
562
   */
 
563
  double computeMean(E_CounterName P_SumCounter,
 
564
                             E_CounterName P_NbOfCallUsed);
 
565
 
 
566
  double computeRtdMean(int which, int type);
 
567
  double computeRtdStdev(int which, int type);
 
568
 
 
569
  /**
 
570
   * Effective C++
 
571
   *
 
572
   * To prevent public copy ctor usage: no implementation
 
573
   */
 
574
  CStat (const CStat&);
 
575
  
 
576
  /**
 
577
   * Effective C++
 
578
   *
 
579
   * To prevent public operator= usage: no implementation
 
580
   */
 
581
  CStat& operator=(const CStat&);
 
582
};
 
583
 
 
584
/**
 
585
 * This abstract class provides the ability to sample from a distribution.
 
586
 */
 
587
class CSample {
 
588
public:
 
589
        virtual double sample() = 0;
 
590
        virtual int textDescr(char *s, int len) = 0;
 
591
        virtual int timeDescr(char *s, int len) = 0;
 
592
        virtual double cdfInv(double percentile) = 0;
 
593
        virtual ~CSample();
 
594
private:
 
595
};
 
596
 
 
597
/* Always return a fixed value for the sample. */
 
598
class CFixed : public CSample {
 
599
public:
 
600
        CFixed(double value);
 
601
        double sample();
 
602
        int textDescr(char *s, int len);
 
603
        int timeDescr(char *s, int len);
 
604
        double cdfInv(double percentile);
 
605
private:
 
606
        double value;
 
607
};
 
608
 
 
609
/* Return the default scenario duration. */
 
610
class CDefaultPause : public CSample {
 
611
public:
 
612
        CDefaultPause();
 
613
        double sample();
 
614
        int textDescr(char *s, int len);
 
615
        int timeDescr(char *s, int len);
 
616
        double cdfInv(double percentile);
 
617
private:
 
618
};
 
619
 
 
620
/* Uniform distribution. */
 
621
class CUniform : public CSample {
 
622
public:
 
623
        CUniform(double min, double max);
 
624
        double sample();
 
625
        int textDescr(char *s, int len);
 
626
        int timeDescr(char *s, int len);
 
627
        double cdfInv(double percentile);
 
628
private:
 
629
        double min, max;
 
630
};
 
631
 
 
632
#ifdef HAVE_GSL
 
633
/* Normal distribution. */
 
634
class CNormal : public CSample {
 
635
public:
 
636
        CNormal(double mean, double stdev);
 
637
        double sample();
 
638
        int textDescr(char *s, int len);
 
639
        int timeDescr(char *s, int len);
 
640
        double cdfInv(double percentile);
 
641
protected:
 
642
        double mean, stdev;
 
643
        gsl_rng *rng;
 
644
};
 
645
 
 
646
/* Lognormal distribution. */
 
647
class CLogNormal : public CNormal {
 
648
public:
 
649
        CLogNormal(double mean, double stdev) : CNormal(mean, stdev) {};
 
650
        double sample();
 
651
        int textDescr(char *s, int len);
 
652
        int timeDescr(char *s, int len);
 
653
        double cdfInv(double percentile);
 
654
};
 
655
 
 
656
/* Exponential distribution. */
 
657
class CExponential : public CSample {
 
658
public:
 
659
        CExponential(double mean);
 
660
        double sample();
 
661
        int textDescr(char *s, int len);
 
662
        int timeDescr(char *s, int len);
 
663
        double cdfInv(double percentile);
 
664
private:
 
665
        double mean;
 
666
        gsl_rng *rng;
 
667
};
 
668
 
 
669
/* Weibull distribution. */
 
670
class CWeibull : public CSample {
 
671
public:
 
672
        CWeibull(double lambda, double k);
 
673
        double sample();
 
674
        int textDescr(char *s, int len);
 
675
        int timeDescr(char *s, int len);
 
676
        double cdfInv(double percentile);
 
677
private:
 
678
        double lambda, k;
 
679
        gsl_rng *rng;
 
680
};
 
681
 
 
682
/* Pareto distribution. */
 
683
class CPareto : public CSample {
 
684
public:
 
685
        CPareto(double k, double xsubm);
 
686
        double sample();
 
687
        int textDescr(char *s, int len);
 
688
        int timeDescr(char *s, int len);
 
689
        double cdfInv(double percentile);
 
690
protected:
 
691
        double k, xsubm;
 
692
        gsl_rng *rng;
 
693
};
 
694
 
 
695
/* Generalized Pareto distribution. */
 
696
class CGPareto : public CSample {
 
697
public:
 
698
        CGPareto(double shape, double scale, double location);
 
699
        double sample();
 
700
        int textDescr(char *s, int len);
 
701
        int timeDescr(char *s, int len);
 
702
        double cdfInv(double percentile);
 
703
protected:
 
704
        double shape, scale, location;
 
705
        gsl_rng *rng;
 
706
};
 
707
 
 
708
 
 
709
/* Gamma distribution. */
 
710
class CGamma : public CSample {
 
711
public:
 
712
        CGamma(double k, double theta);
 
713
        double sample();
 
714
        int textDescr(char *s, int len);
 
715
        int timeDescr(char *s, int len);
 
716
        double cdfInv(double percentile);
 
717
protected:
 
718
        double k, theta;
 
719
        gsl_rng *rng;
 
720
};
 
721
 
 
722
/* Negative Binomial distribution. */
 
723
class CNegBin : public CSample {
 
724
public:
 
725
        CNegBin(double p, double n);
 
726
        double sample();
 
727
        int textDescr(char *s, int len);
 
728
        int timeDescr(char *s, int len);
 
729
        double cdfInv(double percentile);
 
730
protected:
 
731
        double p, n;
 
732
        gsl_rng *rng;
 
733
};
 
734
#endif
 
735
 
 
736
#endif // __STAT_H__