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

📄 stat.cpp

📁 学习sip协议的好工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  initRepartition(repartition,                   nombre,                   &M_ResponseTimeRepartition,                   &M_SizeOfResponseTimeRepartition);}void CStat::initRepartition(unsigned int* repartition,                             int nombre,                             T_dynamicalRepartition ** tabRepartition,                             int* tabNb){  bool sortDone;  int i;  unsigned int swap;  if((nombre <= 0) || (repartition == NULL) )    {      (*tabNb)          = 0;      (*tabRepartition) = NULL;      return;    }  (*tabNb)          = nombre + 1;  (*tabRepartition) = new T_dynamicalRepartition[(*tabNb)];   // copying the repartition table in the local table   for(i=0; i<nombre; i++)    {       (*tabRepartition)[i].borderMax      = repartition[i];      (*tabRepartition)[i].nbInThisBorder = 0;    }     // sorting the repartition table  sortDone = false;  while(!sortDone)    {       sortDone = true;      for(i=0; i<(nombre-1); i++)        {           if((*tabRepartition)[i].borderMax > (*tabRepartition)[i+1].borderMax)            {                // swapping this two value and setting sortDone to false              swap = (*tabRepartition)[i].borderMax;              (*tabRepartition)[i].borderMax =                 (*tabRepartition)[i+1].borderMax;              (*tabRepartition)[i+1].borderMax = swap;              sortDone = false;            }         }     }  // setting the range for max <= value < infinity  (*tabRepartition)[nombre].borderMax =    (*tabRepartition)[nombre-1].borderMax;  (*tabRepartition)[nombre].nbInThisBorder = 0;}int CStat::computeStat (E_Action P_action){  switch (P_action)    {    case E_CREATE_OUTGOING_CALL :      M_counters [CPT_C_OutgoingCallCreated]++;      M_counters [CPT_PD_OutgoingCallCreated]++;      M_counters [CPT_PL_OutgoingCallCreated]++;      M_counters [CPT_C_CurrentCall]++;      break;    case E_CREATE_INCOMING_CALL :      M_counters [CPT_C_IncomingCallCreated]++;      M_counters [CPT_PD_IncomingCallCreated]++;      M_counters [CPT_PL_IncomingCallCreated]++;      M_counters [CPT_C_CurrentCall]++;      break;    case E_CALL_FAILED :      M_counters [CPT_C_FailedCall]++;      M_counters [CPT_PD_FailedCall]++;      M_counters [CPT_PL_FailedCall]++;      M_counters [CPT_C_CurrentCall]--;      break;    case E_CALL_SUCCESSFULLY_ENDED :      M_counters [CPT_C_SuccessfulCall]++;      M_counters [CPT_PD_SuccessfulCall]++;      M_counters [CPT_PL_SuccessfulCall]++;      M_counters [CPT_C_CurrentCall]--;      break;    case E_FAILED_CANNOT_SEND_MSG :      M_counters [CPT_C_FailedCallCannotSendMessage]++;      M_counters [CPT_PD_FailedCallCannotSendMessage]++;      M_counters [CPT_PL_FailedCallCannotSendMessage]++;      break;    case E_FAILED_MAX_UDP_RETRANS :      M_counters [CPT_C_FailedCallMaxUdpRetrans]++;      M_counters [CPT_PD_FailedCallMaxUdpRetrans]++;      M_counters [CPT_PL_FailedCallMaxUdpRetrans]++;      break;    case E_FAILED_UNEXPECTED_MSG :      M_counters [CPT_C_FailedCallUnexpectedMessage]++;      M_counters [CPT_PD_FailedCallUnexpectedMessage]++;      M_counters [CPT_PL_FailedCallUnexpectedMessage]++;      break;    case E_FAILED_CALL_REJECTED :      M_counters [CPT_C_FailedCallCallRejected]++;      M_counters [CPT_PD_FailedCallCallRejected]++;      M_counters [CPT_PL_FailedCallCallRejected]++;      break;    case E_FAILED_CMD_NOT_SENT :      M_counters [CPT_C_FailedCallCmdNotSent]++;      M_counters [CPT_PD_FailedCallCmdNotSent]++;      M_counters [CPT_PL_FailedCallCmdNotSent]++;      break;    case E_FAILED_REGEXP_DOESNT_MATCH :      M_counters [CPT_C_FailedCallRegexpDoesntMatch]++;      M_counters [CPT_PD_FailedCallRegexpDoesntMatch]++;      M_counters [CPT_PL_FailedCallRegexpDoesntMatch]++;      break;    case E_FAILED_REGEXP_HDR_NOT_FOUND :      M_counters [CPT_C_FailedCallRegexpHdrNotFound]++;      M_counters [CPT_PD_FailedCallRegexpHdrNotFound]++;      M_counters [CPT_PL_FailedCallRegexpHdrNotFound]++;      break;    case E_OUT_OF_CALL_MSGS :      M_counters [CPT_C_OutOfCallMsgs]++;      M_counters [CPT_PD_OutOfCallMsgs]++;      M_counters [CPT_PL_OutOfCallMsgs]++;      break;    case E_AUTO_ANSWERED :      // We just realized that the call we created must be       // answered automatically and not counted in normal incomming calls.       M_counters [CPT_C_IncomingCallCreated]--;      M_counters [CPT_PD_IncomingCallCreated]--;      M_counters [CPT_PL_IncomingCallCreated]--;      M_counters [CPT_C_CurrentCall]--;      // Let's count the automatic answered calls      M_counters [CPT_C_AutoAnswered]++;      M_counters [CPT_PD_AutoAnswered]++;      M_counters [CPT_PL_AutoAnswered]++;      break;    case E_RESET_PD_COUNTERS :      //DEBUG (C_Debug::E_LEVEL_4, "ENTER CASE", "%s",       //       "CStat::computeStat : RESET_PD_COUNTERS");      RESET_PD_COUNTERS (M_counters);      GET_TIME (&M_pdStartTime);      break;    case E_RESET_PL_COUNTERS :      //DEBUG (C_Debug::E_LEVEL_4, "ENTER CASE", "%s",       //       "C_Stat::computeStat : RESET_PL_COUNTERS");      RESET_PL_COUNTERS (M_counters);      GET_TIME (&M_plStartTime);      break;         default :      ERROR_P1("CStat::ComputeStat() - Unrecognized Action %d\n", P_action);      return (-1);    } /* end switch */  return (0);}unsigned long CStat::GetStat (E_CounterName P_counter){  return M_counters [P_counter];}void CStat::updateAverageCounter(E_CounterName P_AverageCounter,                                  E_CounterName P_NbOfCallUsed,                                 unsigned long long* P_sum,                                  unsigned long P_value){  if (M_counters [P_NbOfCallUsed] <= 0)    {      M_counters [P_NbOfCallUsed] ++;      M_counters [P_AverageCounter] = P_value;      (*P_sum) = P_value;    }  else    {      (*P_sum) = P_value + (*P_sum);      M_counters [P_AverageCounter] = (*P_sum) /        (M_counters [P_NbOfCallUsed] + 1);          M_counters [P_NbOfCallUsed] ++;    }}int CStat::computeStat (E_Action P_action,                         unsigned long P_value){  switch (P_action)    {    case E_ADD_CALL_DURATION :      // Updating Cumulative Counter      updateAverageCounter(CPT_C_AverageCallLength,                            CPT_C_NbOfCallUsedForAverageCallLength,                           &M_C_sumCallLength, P_value);       updateRepartition(M_CallLengthRepartition,                         M_SizeOfCallLengthRepartition, P_value);      // Updating Periodical Diplayed counter      updateAverageCounter(CPT_PD_AverageCallLength,                            CPT_PD_NbOfCallUsedForAverageCallLength,                           &M_PD_sumCallLength, P_value);       // Updating Periodical Logging counter      updateAverageCounter(CPT_PL_AverageCallLength,                            CPT_PL_NbOfCallUsedForAverageCallLength,                           &M_PL_sumCallLength, P_value);       break;    case E_ADD_RESPONSE_TIME_DURATION :      // Updating Cumulative Counter      updateAverageCounter(CPT_C_AverageResponseTime,                            CPT_C_NbOfCallUsedForAverageResponseTime,                           &M_C_sumResponseTime, P_value);       updateRepartition(M_ResponseTimeRepartition,                         M_SizeOfResponseTimeRepartition, P_value);      // Updating Periodical Diplayed counter      updateAverageCounter(CPT_PD_AverageResponseTime,                            CPT_PD_NbOfCallUsedForAverageResponseTime,                           &M_PD_sumResponseTime, P_value);       // Updating Periodical Logging counter      updateAverageCounter(CPT_PL_AverageResponseTime,                            CPT_PL_NbOfCallUsedForAverageResponseTime,                           &M_PL_sumResponseTime, P_value);       break;    default :      ERROR_P1("CStat::ComputeStat() - Unrecognized Action %d\n", P_action);      return (-1);    } /* end switch */  return (0);}void CStat::updateRepartition(T_dynamicalRepartition* P_tabReport,                               int P_sizeOfTab,                               unsigned long P_value){  bool found;  int i;  if(P_tabReport != NULL)    {      i = P_sizeOfTab-2;      found = false;      while((found == false) && (i>=1))        {          if( (P_value < P_tabReport[i].borderMax) &&              (P_tabReport[i-1].borderMax <= P_value) )            {              found = true;              P_tabReport[i].nbInThisBorder ++;            }          i--;        }          if(!found)        {          if(P_value < P_tabReport[0].borderMax)            {              P_tabReport[0].nbInThisBorder ++;            }          else if(P_value >= P_tabReport[P_sizeOfTab-1].borderMax)            {              P_tabReport[P_sizeOfTab-1].nbInThisBorder ++;            }          else            {              // ERROR !!!!              printf("\n ERROR - Unable to sort this Value in "                     "the repartition table! %d \n", P_value);            }        }    }}CStat::CStat (){  size_t L_size = 0;  L_size += strlen(DEFAULT_FILE_NAME) ;  L_size += strlen(DEFAULT_EXTENSION) ;  L_size += 1 ;  M_fileName = new char[L_size];  strcpy(M_fileName, DEFAULT_FILE_NAME);  strcat(M_fileName, DEFAULT_EXTENSION);  M_ResponseTimeRepartition = NULL;  M_CallLengthRepartition   = NULL;  M_SizeOfResponseTimeRepartition = 0;  M_SizeOfCallLengthRepartition   = 0;  init();}CStat::~CStat (){}char* CStat::sRepartitionHeader(T_dynamicalRepartition * tabRepartition,                                 int sizeOfTab,                                 char * P_repartitionName){  static char  repartitionHeader[MAX_REPARTITION_HEADER_LENGTH];  char buffer[MAX_CHAR_BUFFER_SIZE];  if(tabRepartition != NULL)    {      sprintf(repartitionHeader, "%s;", P_repartitionName);      for(int i=0; i<(sizeOfTab-1); i++)        {             sprintf(buffer, "<%d;", tabRepartition[i].borderMax);          strcat(repartitionHeader, buffer);        }      sprintf(buffer, ">=%d;", tabRepartition[sizeOfTab-1].borderMax);      strcat(repartitionHeader, buffer);    }  else    {      sprintf(repartitionHeader, "");    }  return(repartitionHeader);}char* CStat::sRepartitionInfo(T_dynamicalRepartition * tabRepartition,                               int sizeOfTab){  static char repartitionInfo[MAX_REPARTITION_INFO_LENGTH];  char buffer[MAX_CHAR_BUFFER_SIZE];  if(tabRepartition != NULL)    {      // if a repartition is present, this field match the repartition name      sprintf(repartitionInfo, ";");      for(int i=0; i<(sizeOfTab-1); i++)        {             sprintf(buffer, "%d;", tabRepartition[i].nbInThisBorder);          strcat(repartitionInfo, buffer);        }      sprintf(buffer, "%d;", tabRepartition[sizeOfTab-1].nbInThisBorder);      strcat(repartitionInfo, buffer);    }  else    {      sprintf(repartitionInfo, "");    }  return(repartitionInfo);}void CStat::displayRepartition(FILE *f,                               T_dynamicalRepartition * tabRepartition,                                int sizeOfTab){  if(tabRepartition != NULL) {    for(int i=0; i<(sizeOfTab-1); i++) {         if(i==0) {        DISPLAY_REPART(0, tabRepartition[i].borderMax,                         tabRepartition[i].nbInThisBorder);      } else {        DISPLAY_REPART(tabRepartition[i-1].borderMax,                        tabRepartition[i].borderMax,                        tabRepartition[i].nbInThisBorder);      }    }    DISPLAY_LAST_REPART (tabRepartition[sizeOfTab-1].borderMax,                          tabRepartition[sizeOfTab-1].nbInThisBorder);  } else {    DISPLAY_INFO ("  <No repartion defined>");  }}void CStat::displayData (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

⌨️ 快捷键说明

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