Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_GeneratorStats.hpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #ifndef _C_GENERATOR_STATS_H
00021 #define _C_GENERATOR_STATS_H
00022 
00023 #define TIME_LENGTH 32
00024 #define DEFAULT_FILE_NAME (char*)"dumpFile"
00025 #define DEFAULT_EXTENSION (char*)".csv"
00026 
00027 #define MAX_REPARTITION_HEADER_LENGTH 1024
00028 #define MAX_REPARTITION_INFO_LENGTH   1024
00029 #define MAX_CHAR_BUFFER_SIZE          256
00030 
00031 #include "TimeUtils.hpp"
00032 #include "C_Mutex.hpp"
00033 
00034 // C++ standard include
00035 #include "fstream_t.hpp"
00036 
00037 
00038 /*
00039 __________________________________________________________________________
00040 
00041               C L A S S    C S t a t 
00042 __________________________________________________________________________
00043 */
00044 
00050 class C_GeneratorStats {
00051 public:
00052 
00053   /* 
00054    * This struct is used for repartition table
00055    * border max is the max value allow for this range
00056    * nbInThisBorder is the counter of value in this range
00057    */
00058   typedef struct _T_dynamicalRepartition
00059   {
00060     unsigned int  borderMax;
00061     unsigned long nbInThisBorder; 
00062   } T_dynamicalRepartition; 
00063 
00067   enum E_Action
00068   {
00069     E_CREATE_INCOMING_CALL,
00070     E_CALL_FAILED, 
00071     E_CALL_REFUSED,
00072     //    E_CALL_SUCCESSFULLY_ENDED,
00073 
00074 
00075     E_CALL_INIT_SUCCESSFULLY_ENDED,
00076     E_CALL_TRAFFIC_SUCCESSFULLY_ENDED,
00077     E_CALL_DEFAULT_SUCCESSFULLY_ENDED,
00078     E_CALL_ABORT_SUCCESSFULLY_ENDED,
00079 
00080     E_SEND_MSG,    
00081     E_RECV_MSG,
00082 
00083     E_RESET_PD_COUNTERS,
00084     E_RESET_PL_COUNTERS,
00085 
00086     E_FAILED_UNEXPECTED_MSG,
00087     E_FAILED_CANNOT_SEND_MSG,
00088     E_FAILED_ABORTED,
00089 
00090     E_FAILED_TIMEOUT,
00091 
00092     E_CREATE_OUTGOING_CALL,
00093    
00094 
00095     // Not used 
00096     E_ADD_CALL_DURATION,
00097     E_ADD_RESPONSE_TIME_DURATION,
00098     E_FAILED_CALL_REJECTED,
00099     E_FAILED_MAX_UDP_RETRANS,
00100     E_FAILED_CMD_NOT_SENT,
00101     E_FAILED_REGEXP_DOESNT_MATCH,
00102     E_FAILED_REGEXP_HDR_NOT_FOUND
00103   };
00107   enum E_CounterName
00108   {
00109          // Cumulative counter
00110          CPT_C_IncomingCallCreated,
00111          CPT_C_MsgSend,    
00112          CPT_C_MsgRecv,
00113          CPT_C_CurrentCall,
00114 
00115 
00116          CPT_C_InitSuccessfulCall,
00117          CPT_C_TrafficSuccessfulCall,
00118          CPT_C_DefaultSuccessfulCall,
00119          CPT_C_AbortSuccessfulCall,
00120          CPT_C_FailedCall,
00121          CPT_C_RefusedCall,
00122          CPT_C_FailedCallAborted,
00123          CPT_C_FailedCallTimeout,
00124 
00125          CPT_C_FailedCallCannotSendMessage,
00126          CPT_C_FailedCallUnexpectedMessage,
00127          CPT_C_OutgoingCallCreated,
00128          CPT_C_NbOfCallUsedForAverageResponseTime,
00129          CPT_C_AverageResponseTime,
00130 
00131          // not used
00132          CPT_C_NbOfCallUsedForAverageCallLength,
00133          CPT_C_AverageCallLength,
00134          CPT_C_FailedCallMaxUdpRetrans,
00135          CPT_C_FailedCallCallRejected,
00136          CPT_C_FailedCallCmdNotSent,
00137          CPT_C_FailedCallRegexpDoesntMatch,
00138          CPT_C_FailedCallRegexpHdrNotFound,
00139 
00140          // Periodic Display counter
00141          CPT_PD_IncomingCallCreated, // must be the first PD counter (RESET_PD_COUNTER macro)
00142          CPT_PD_MsgSend,    
00143          CPT_PD_MsgRecv,
00144 
00145 
00146          CPT_PD_InitSuccessfulCall,
00147          CPT_PD_TrafficSuccessfulCall,
00148          CPT_PD_DefaultSuccessfulCall,
00149          CPT_PD_AbortSuccessfulCall,
00150          CPT_PD_FailedCall,
00151          CPT_PD_RefusedCall,
00152          CPT_PD_FailedCallAborted,
00153          CPT_PD_FailedCallTimeout,
00154 
00155          CPT_PD_FailedCallCannotSendMessage,
00156          CPT_PD_FailedCallUnexpectedMessage,
00157          CPT_PD_OutgoingCallCreated,
00158          CPT_PD_NbOfCallUsedForAverageResponseTime,
00159          CPT_PD_AverageResponseTime,
00160 
00161 
00162          // not used
00163          CPT_PD_NbOfCallUsedForAverageCallLength,
00164          CPT_PD_AverageCallLength,
00165          CPT_PD_FailedCallMaxUdpRetrans,
00166          CPT_PD_FailedCallCallRejected,
00167          CPT_PD_FailedCallCmdNotSent,
00168          CPT_PD_FailedCallRegexpDoesntMatch,
00169          CPT_PD_FailedCallRegexpHdrNotFound, // must be the last PD counter (RESET_PD_COUNTER macro)
00170 
00171          // Periodic logging counter
00172          CPT_PL_IncomingCallCreated, // must be the first PL counter (RESET_PL_COUNTER macro)
00173          CPT_PL_MsgSend,    
00174          CPT_PL_MsgRecv,
00175 
00176 
00177          CPT_PL_InitSuccessfulCall,
00178          CPT_PL_TrafficSuccessfulCall,
00179          CPT_PL_DefaultSuccessfulCall,
00180          CPT_PL_AbortSuccessfulCall,
00181          CPT_PL_FailedCall,
00182          CPT_PL_RefusedCall,
00183          CPT_PL_FailedCallAborted,
00184          CPT_PL_FailedCallTimeout,
00185 
00186 
00187          CPT_PL_FailedCallCannotSendMessage,
00188          CPT_PL_FailedCallUnexpectedMessage,
00189          CPT_PL_OutgoingCallCreated,
00190          CPT_PL_NbOfCallUsedForAverageResponseTime,
00191          CPT_PL_AverageResponseTime,
00192 
00193 
00194          // not used
00195          CPT_PL_NbOfCallUsedForAverageCallLength,
00196          CPT_PL_AverageCallLength,
00197          CPT_PL_FailedCallMaxUdpRetrans,
00198          CPT_PL_FailedCallCallRejected,
00199          CPT_PL_FailedCallCmdNotSent,
00200          CPT_PL_FailedCallRegexpDoesntMatch,
00201          CPT_PL_FailedCallRegexpHdrNotFound, // must be the last PL counter (RESET_PL_COUNTER macro)
00202 
00203          E_NB_COUNTER
00204   };
00205 
00206 
00207 
00208   /*
00209   ** exported methods
00210   */
00220   static C_GeneratorStats* instance (); 
00221 
00228   void close (); 
00229 
00237   int computeStat (E_Action P_action);
00238   int computeStat (E_Action P_action, unsigned long P_value);
00239 
00240   int executeStatAction (E_Action P_action);
00241   int executeStatAction (E_Action P_action, unsigned long P_value);
00242 
00243   void displayScreen (int P_id, int P_sub_screen);
00244 
00245   void makeFirstLog ();
00246   void makeLog() ;
00247 
00248   void info_msg (char *P_msg) ;
00249   void err_msg (char *P_msg) ;
00250   
00251   void reset_cumul_counters () ;
00252 
00253 
00254   void activate_percent_traffic () ;
00255 
00270   void setRepartitionCallLength   (unsigned int* repartition, int nombre);
00271   void setRepartitionCallLength   (char * liste);
00272   void setRepartitionResponseTime (unsigned int* repartition, int nombre);
00273   void setRepartitionResponseTime (char * liste);
00274 
00275   /* define the file name to use to dump statistic in file */
00276   void setFileName                (char * name);
00277   void setFileName                (char * name, char * extension);
00278 
00282   void displayData ();
00283   void displayStat();
00284 
00285   void displayRepartition();
00286 
00287 
00288 
00292   void dumpData ();
00293   
00294 
00298   int init();
00299 
00300   void displayScreen() ;
00301   // void setCurrentScreen() ;
00302   void makeDisplay1 (bool P_display) ;
00303   void makeDisplay2 () ;
00304 
00305   char *dumpCounters();
00306 
00307 private:
00308 
00309   bool m_initDone ;
00310    
00316   C_GeneratorStats ();
00317 
00323   ~C_GeneratorStats ();
00324 
00325   static C_GeneratorStats*            m_instance;
00326 
00327   unsigned long            m_counters        [E_NB_COUNTER];
00328   unsigned long            m_displayCounters [E_NB_COUNTER];
00329   unsigned long            m_loggingCounters [E_NB_COUNTER];
00330   unsigned long            m_remoteCounters  [E_NB_COUNTER];
00331 
00332   T_dynamicalRepartition*  m_ResponseTimeRepartition;
00333   T_dynamicalRepartition*  m_CallLengthRepartition;
00334   int                      m_SizeOfResponseTimeRepartition;
00335   int                      m_SizeOfCallLengthRepartition;
00336 
00337   struct timeval           m_startTime;
00338   struct timeval           m_pdStartTime;
00339   struct timeval           m_plStartTime;
00340 
00341   bool                     m_headerAlreadyDisplayed;
00342   char                    *m_fileName;
00343   fstream_output          *m_outputStream;
00344 
00345   unsigned long long       m_C_sumCallLength;
00346   unsigned long long       m_C_sumResponseTime;
00347   unsigned long long       m_PD_sumCallLength;
00348   unsigned long long       m_PD_sumResponseTime;
00349   unsigned long long       m_PL_sumCallLength;
00350   unsigned long long       m_PL_sumResponseTime;
00351 
00352   C_Mutex                  m_mutexTable[E_NB_COUNTER];
00353 
00354   void makeDisplay3 (int P_sub_screen) ;
00355 
00356   char  *m_info_msg ;
00357   char  *m_err_msg ;
00358   size_t m_max_msg_size ;
00359 
00371   void  initRepartition(unsigned int* repartition, int nombre,
00372                        T_dynamicalRepartition ** tabRepartition, int* nbTab);
00373 
00381   int  createIntegerTable(char * P_listeStr, unsigned int ** listeInteger, int * sizeOfList);
00382 
00390   int  isWellFormed(char * P_listeStr, int * nombre);
00391 
00397   void  updateRepartition( T_dynamicalRepartition* tabRepart, int sizeOfTab, unsigned long value);
00398 
00403   void  displayRepartition(T_dynamicalRepartition * tabRepartition, int sizeOfTab);
00404 
00405   void displayRepartition_with_percent(T_dynamicalRepartition * tabRepartition, int sizeOfTab);
00406   void displayRepartition_without_percent(T_dynamicalRepartition * tabRepartition, int sizeOfTab);
00407 
00408 
00413   char* sRepartitionHeader(T_dynamicalRepartition * tabRepartition, int sizeOfTab,
00414                            char* P_repartitionName);
00415 
00420   char* sRepartitionInfo(T_dynamicalRepartition * tabRepartition, int sizeOfTab);
00421 
00426   void updateAverageCounter(E_CounterName P_AvarageCounter, E_CounterName P_NbOfCallUsed,
00427                             unsigned long long* P_sum, unsigned long P_value);
00428 
00439   char* msToHHMMSS (unsigned long P_ms);
00440 
00441   char* msToHHMMSSmmm (unsigned long P_ms);
00463   char* formatTime (struct timeval* P_tv);
00464   void  formatTime (char *P_time, struct timeval* P_tv);
00465 
00466   // typedef void (C_GeneratorStats::* T_DisplayFct) () ;
00467 
00468   // int           m_current_stat_id      ;
00469   // int           m_nb_stat_id           ;
00470   // T_DisplayFct *m_current_stat_table   ;
00471   // T_DisplayFct  m_current_stat_display ;
00472 
00473 
00474   typedef void (C_GeneratorStats::* T_DisplayRepFct)(T_dynamicalRepartition * tabRepartition, 
00475                                                      int sizeOfTab) ;
00476 
00477   int                   m_current_display_rep_id      ;
00478   int                   m_nb_display_rep_id           ;
00479   T_DisplayRepFct      *m_current_repartition_table   ;
00480   T_DisplayRepFct       m_current_repartition_display ;
00481 
00482 
00483 
00484 
00485 
00491   C_GeneratorStats (const C_GeneratorStats&);
00492 
00498   C_GeneratorStats& operator=(const C_GeneratorStats&);
00499 
00500 };
00501 
00502 #endif // _C_GENERATOR_STATS_H

Generated on Wed Mar 7 14:44:50 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002