⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stat.cpp

📁 学习sip协议的好工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  globalElapsedTime   = computeDiffTimeInMs (&currentTime, &M_startTime);  localElapsedTime    = computeDiffTimeInMs (&currentTime, &M_pdStartTime);  // the call rate is for all the call : incoming and outgoing  numberOfCall        = M_counters[CPT_C_IncomingCallCreated] +     M_counters[CPT_C_OutgoingCallCreated];  averageCallRate     = (globalElapsedTime > 0 ?                          1000*(float)numberOfCall/(float)globalElapsedTime                          : 0.0);  numberOfCall        = (M_counters[CPT_PD_IncomingCallCreated] +                          M_counters[CPT_PD_OutgoingCallCreated]);  realInstantCallRate = (localElapsedTime  > 0 ?                          1000*(float)numberOfCall / (float)localElapsedTime :                         0.0);  // display info  DISPLAY_DLINE ();  // build and display header info  DISPLAY_TXT ("Start Time  ", formatTime(&M_startTime));  DISPLAY_TXT ("Last Reset Time", formatTime(&M_pdStartTime));  DISPLAY_TXT ("Current Time", formatTime(&currentTime));  // printing the header in the middle  DISPLAY_CROSS_LINE();  DISPLAY_HEADER();  DISPLAY_CROSS_LINE();  DISPLAY_TXT_COL ("Elapsed Time",                    msToHHMMSSmmm(localElapsedTime),                      msToHHMMSSmmm(globalElapsedTime));  DISPLAY_VAL_RATEF_COL ("Call Rate",                           realInstantCallRate,                          averageCallRate);  DISPLAY_CROSS_LINE ();  DISPLAY_2VAL  ("Incoming call created",                  M_counters[CPT_PD_IncomingCallCreated],                 M_counters[CPT_C_IncomingCallCreated]);  DISPLAY_2VAL  ("OutGoing call created",                  M_counters[CPT_PD_OutgoingCallCreated],                 M_counters[CPT_C_OutgoingCallCreated]);  DISPLAY_CUMUL ("Total Call created", M_counters[CPT_C_IncomingCallCreated] +                 M_counters[CPT_C_OutgoingCallCreated]);  DISPLAY_PERIO ("Current Call",       M_counters[CPT_C_CurrentCall]);  DISPLAY_CROSS_LINE ();  DISPLAY_2VAL  ("Successful call",                  M_counters[CPT_PD_SuccessfulCall],                  M_counters[CPT_C_SuccessfulCall]);  DISPLAY_2VAL  ("Failed call",                       M_counters[CPT_PD_FailedCall],                  M_counters[CPT_C_FailedCall]);  // DISPLAY_2VAL  ("Unexpected msg",     //                 M_counters[CPT_PD_UnexpectedMessage],   //                 M_counters[CPT_C_UnexpectedMessage]);  DISPLAY_CROSS_LINE ();  DISPLAY_TXT_COL ("Response Time",                    msToHHMMSSmmm( M_counters [CPT_PD_AverageResponseTime] ),                    msToHHMMSSmmm( M_counters [CPT_C_AverageResponseTime] ));  DISPLAY_TXT_COL ("Call Length",                    msToHHMMSSmmm( M_counters [CPT_PD_AverageCallLength] ),                    msToHHMMSSmmm( M_counters [CPT_C_AverageCallLength] ));  DISPLAY_CROSS_LINE ();  DISPLAY_INFO("Average Response Time Repartition");  displayRepartition(f, M_ResponseTimeRepartition, M_SizeOfResponseTimeRepartition);  DISPLAY_INFO("Average Call Length Repartition");  displayRepartition(f, M_CallLengthRepartition, M_SizeOfCallLengthRepartition);  //  DISPLAY_VAL ("NbCall Average RT(P)",  //                 M_counters[CPT_PD_NbOfCallUsedForAverageResponseTime]);  //  DISPLAY_VAL ("NbCall Average RT",  //                 M_counters[CPT_C_NbOfCallUsedForAverageResponseTime]);  //  DISPLAY_VAL ("NbCall Average CL",  //                 M_counters[CPT_C_NbOfCallUsedForAverageCallLength]);  //  DISPLAY_VAL ("NbCall Average CL(P)",  //                 M_counters[CPT_PD_NbOfCallUsedForAverageCallLength]);  DISPLAY_DLINE ();} /* end of displayData () */void CStat::displayStat (FILE *f){  char   buf1 [64], buf2 [64], buf3 [64];  long   localElapsedTime, globalElapsedTime ;  struct timeval currentTime;  float  averageCallRate;  float  realInstantCallRate;  unsigned long numberOfCall;  GET_TIME (&currentTime);  // computing the real call rate  globalElapsedTime   = computeDiffTimeInMs (&currentTime, &M_startTime);  localElapsedTime    = computeDiffTimeInMs (&currentTime, &M_pdStartTime);  // the call rate is for all the call : incoming and outgoing  numberOfCall        = (M_counters[CPT_C_IncomingCallCreated] +                          M_counters[CPT_C_OutgoingCallCreated]);  averageCallRate     = (globalElapsedTime > 0 ?                          1000*(float)numberOfCall/(float)globalElapsedTime :                         0.0);  numberOfCall        = (M_counters[CPT_PD_IncomingCallCreated] +                          M_counters[CPT_PD_OutgoingCallCreated]);  realInstantCallRate = (localElapsedTime  > 0 ?                          1000*(float)numberOfCall / (float)localElapsedTime :                         0.0);  // build and display header info  DISPLAY_TXT ("Start Time  ", formatTime(&M_startTime));  DISPLAY_TXT ("Last Reset Time", formatTime(&M_pdStartTime));  DISPLAY_TXT ("Current Time", formatTime(&currentTime));  // printing the header in the middle  DISPLAY_CROSS_LINE();  DISPLAY_HEADER();  DISPLAY_CROSS_LINE();  DISPLAY_TXT_COL ("Elapsed Time",                    msToHHMMSSmmm(localElapsedTime),                      msToHHMMSSmmm(globalElapsedTime));  DISPLAY_VAL_RATEF_COL ("Call Rate",  realInstantCallRate, averageCallRate);  DISPLAY_CROSS_LINE ();  DISPLAY_2VAL  ("Incoming call created",                  M_counters[CPT_PD_IncomingCallCreated],                 M_counters[CPT_C_IncomingCallCreated]);  DISPLAY_2VAL  ("OutGoing call created",                  M_counters[CPT_PD_OutgoingCallCreated],                 M_counters[CPT_C_OutgoingCallCreated]);  DISPLAY_CUMUL ("Total Call created", M_counters[CPT_C_IncomingCallCreated] +                 M_counters[CPT_C_OutgoingCallCreated]);  DISPLAY_PERIO ("Current Call",                 M_counters[CPT_C_CurrentCall]);  DISPLAY_CROSS_LINE ();  DISPLAY_2VAL  ("Successful call",                 M_counters[CPT_PD_SuccessfulCall],                  M_counters[CPT_C_SuccessfulCall]);  DISPLAY_2VAL  ("Failed call",                 M_counters[CPT_PD_FailedCall],                 M_counters[CPT_C_FailedCall]);  //DISPLAY_2VAL  ("Unexpected msg",     //               M_counters[CPT_PD_UnexpectedMessage],   //               M_counters[CPT_C_UnexpectedMessage]);  DISPLAY_CROSS_LINE ();  DISPLAY_TXT_COL ("Response Time",                    msToHHMMSSmmm( M_counters [CPT_PD_AverageResponseTime] ),                    msToHHMMSSmmm( M_counters [CPT_C_AverageResponseTime] ));  DISPLAY_TXT_COL ("Call Length",                    msToHHMMSSmmm( M_counters [CPT_PD_AverageCallLength] ),                    msToHHMMSSmmm( M_counters [CPT_C_AverageCallLength] ));}void CStat::displayRepartition (FILE *f){  DISPLAY_INFO("Average Response Time Repartition");  displayRepartition(f,                     M_ResponseTimeRepartition,                      M_SizeOfResponseTimeRepartition);  DISPLAY_INFO("Average Call Length Repartition");  displayRepartition(f,                     M_CallLengthRepartition,                      M_SizeOfCallLengthRepartition);}void CStat::dumpData (){  long   localElapsedTime, globalElapsedTime ;  struct timeval currentTime;  float  averageCallRate;  float  realInstantCallRate;  unsigned long numberOfCall;  // computing the real call rate  GET_TIME (&currentTime);  globalElapsedTime   = computeDiffTimeInMs (&currentTime, &M_startTime);  localElapsedTime    = computeDiffTimeInMs (&currentTime, &M_plStartTime);  // the call rate is for all the call : incoming and outgoing  numberOfCall        = (M_counters[CPT_C_IncomingCallCreated] +                          M_counters[CPT_C_OutgoingCallCreated]);  averageCallRate     = (globalElapsedTime > 0 ?                          1000*(float)numberOfCall/(float)globalElapsedTime :                          0.0);  numberOfCall        = (M_counters[CPT_PL_IncomingCallCreated] +                          M_counters[CPT_PL_OutgoingCallCreated]);  realInstantCallRate = (localElapsedTime  > 0 ?                         1000*(float)numberOfCall / (float)localElapsedTime :                         0.0);  if(M_outputStream == NULL) {    // if the file is still not opened, we opened it now    M_outputStream = new ofstream(M_fileName);    M_headerAlreadyDisplayed = false;        if(M_outputStream == NULL) {      cerr << "Unable to open log file !" << endl;      exit(EXIT_FATAL_ERROR);    }#ifndef __osf__    if(!M_outputStream->is_open())      {        cerr << "Unable to open log file !" << endl;        exit(EXIT_FATAL_ERROR);      }#endif  }  if(M_headerAlreadyDisplayed == false) {    // header - it's dump in file only one time at the beginning of the file    (*M_outputStream) << "StartTime;"                      << "LastResetTime;"                      << "CurrentTime;"                       << "ElapsedTime(P);"                      << "ElapsedTime(C);"                      << "CallRate(P);"                      << "CallRate(C);"                      << "IncomingCall(P);"                      << "IncomingCall(C);"                      << "OutgoingCall(P);"                      << "OutgoingCall(C);"                      << "TotalCallCreated;"                      << "CurrentCall;"                      << "SuccessfulCall(P);"                      << "SuccessfulCall(C);"                      << "FailedCall(P);"                      << "FailedCall(C);"                      << "FailedCannotSendMessage(P);"                      << "FailedCannotSendMessage(C);"                      << "FailedMaxUDPRetrans(P);"                      << "FailedMaxUDPRetrans(C);"                      << "FailedUnexpectedMessage(P);"                      << "FailedUnexpectedMessage(C);"                      << "FailedCallRejected(P);"                      << "FailedCallRejected(C);"                      << "FailedCmdNotSent(P);"                      << "FailedCmdNotSent(C);"                      << "FailedRegexpDoesntMatch(P);"                      << "FailedRegexpDoesntMatch(C);"                      << "FailedRegexpHdrNotFound(P);"                      << "FailedRegexpHdrNotFound(C);"                      << "OutOfCallMsgs(P);"                      << "OutOfCallMsgs(C);"                      << "AutoAnswered(P);"                      << "AutoAnswered(C);"                      << "ResponseTime(P);"                      << "ResponseTime(C);"                      << "CallLength(P);"                      << "CallLength(C);";    (*M_outputStream) << sRepartitionHeader(M_ResponseTimeRepartition,                                             M_SizeOfResponseTimeRepartition,                                            (char*) "ResponseTimeRepartition");    (*M_outputStream) << sRepartitionHeader(M_CallLengthRepartition,                                             M_SizeOfCallLengthRepartition,                                            (char*) "CallLengthRepartition");    (*M_outputStream) << endl;    M_headerAlreadyDisplayed = true;  }    // content  (*M_outputStream) << formatTime(&M_startTime)               << ";";  (*M_outputStream) << formatTime(&M_plStartTime)             << ";";  (*M_outputStream) << formatTime(&currentTime)               << ";"                    << msToHHMMSS(localElapsedTime)           << ";";  (*M_outputStream) << msToHHMMSS(globalElapsedTime)          << ";"                    << realInstantCallRate                    << ";"                    << averageCallRate                        << ";"                    << M_counters[CPT_PL_IncomingCallCreated] << ";"                    << M_counters[CPT_C_IncomingCallCreated]  << ";"                    << M_counters[CPT_PL_OutgoingCallCreated] << ";"                    << M_counters[CPT_C_OutgoingCallCreated]  << ";"                    << (M_counters[CPT_C_IncomingCallCreated]+                         M_counters[CPT_C_OutgoingCallCreated])<< ";"                    << M_counters[CPT_C_CurrentCall]          << ";"                    << M_counters[CPT_PL_SuccessfulCall]      << ";"                    << M_counters[CPT_C_SuccessfulCall]       << ";"                    << M_counters[CPT_PL_FailedCall]          << ";"                    << M_counters[CPT_C_FailedCall]           << ";"                    << M_counters[CPT_PL_FailedCallCannotSendMessage]   << ";"                    << M_counters[CPT_C_FailedCallCannotSendMessage]    << ";"                    << M_counters[CPT_PL_FailedCallMaxUdpRetrans]       << ";"                    << M_counters[CPT_C_FailedCallMaxUdpRetrans     ]   << ";"                    << M_counters[CPT_PL_FailedCallUnexpectedMessage]   << ";"                    << M_counters[CPT_C_FailedCallUnexpectedMessage]    << ";"                    << M_counters[CPT_PL_FailedCallCallRejected]        << ";"                    << M_counters[CPT_C_FailedCallCallRejected]         << ";"                    << M_counters[CPT_PL_FailedCallCmdNotSent]          << ";"                    << M_counters[CPT_C_FailedCallCmdNotSent]           << ";"                    << M_counters[CPT_PL_FailedCallRegexpDoesntMatch]   << ";"                    << M_counters[CPT_C_FailedCallRegexpDoesntMatch]    << ";"                    << M_counters[CPT_PL_FailedCallRegexpHdrNotFound]   << ";"                    << M_counters[CPT_C_FailedCallRegexpHdrNotFound]    << ";"                    << M_counters[CPT_PL_OutOfCallMsgs]                 << ";"                    << M_counters[CPT_C_OutOfCallMsgs]                  << ";"                    << M_counters[CPT_PL_AutoAnswered]                  << ";"                    << M_counters[CPT_C_AutoAnswered]                   << ";";  // SF917289 << M_counters[CPT_C_UnexpectedMessage]    << ";";  (*M_outputStream)     << msToHHMMSSmmm( M_counters [CPT_PL_AverageResponseTime] ) << ";";  (*M_outputStream)     << msToHHMMSSmmm( M_counters [CPT_C_AverageResponseTime ] ) << ";";  (*M_outputStream)     << msToHHMMSSmmm( M_counters [CPT_PL_AverageCallLength  ] ) << ";";  (*M_outputStream)     << msToHHMMSSmmm( M_counters [CPT_C_AverageCallLength   ] ) << ";";  (*M_outputStream)     << sRepartitionInfo(M_ResponseTimeRepartition,                         M_SizeOfResponseTimeRepartition);  (*M_outputStream)     << sRepartitionInfo(M_CallLengthRepartition,                         M_SizeOfCallLengthRepartition);  (*M_outputStream) << endl;  // flushing the output file to let the tail -f working !  (*M_outputStream).flush();  } /* end of logData () *//* Time Gestion */char* CStat::msToHHMMSS (unsigned long P_ms){  static char L_time [TIME_LENGTH];  unsigned long hh, mm, ss;          P_ms = P_ms / 1000;  hh = P_ms / 3600;  mm = (P_ms - hh * 3600) / 60;  ss = P_ms - (hh * 3600) - (mm * 60);  sprintf (L_time, "%2.2d:%2.2d:%2.2d", hh, mm, ss);  return (L_time);} /* end of msToHHMMSS */char* CStat::msToHHMMSSmmm (unsigned long P_ms){  static char L_time [TIME_LENGTH];  unsigned long sec, hh, mm, ss, mmm;  sec  = P_ms / 1000;  hh   = sec / 3600;  mm   = (sec - hh * 3600) / 60;  ss   = sec - (hh * 3600) - (mm * 60);  mmm  = P_ms - (hh * 3600000) - (mm * 60000) - (ss*1000);  sprintf (L_time, "%2.2d:%2.2d:%2.2d:%3.3d", hh, mm, ss, mmm);  return (L_time);} /* end of msToHHMMSS */char* CStat::formatTime (struct timeval* P_tv){  static char L_time [TIME_LENGTH];  struct tm * L_currentDate;  // Get the current date and time  L_currentDate = localtime ((const time_t *)&P_tv->tv_sec);  // Format the time  if (L_currentDate == NULL)    {      memset (L_time, 0, TIME_LENGTH);    }   else    {      // SF917230 sprintf(L_time, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d:%3.3d",       sprintf(L_time, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",               L_currentDate->tm_year + 1900,              L_currentDate->tm_mon + 1,              L_currentDate->tm_mday,              L_currentDate->tm_hour,              L_currentDate->tm_min,              L_currentDate->tm_sec);      // SF917230 (int) (P_tv->tv_usec)/1000);    }  return (L_time);} /* end of formatTime */long CStat::computeDiffTimeInMs (struct timeval* tf, struct timeval* ti){  long v1, v2;  v1 = tf->tv_sec - ti->tv_sec;  v2 = tf->tv_usec - ti->tv_usec;  if (v2 < 0) v2 += 1000000, v1--;  return (v1*1000 + v2/1000);}CStat* CStat::M_instance = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -