📄 stat.cpp
字号:
// 4 for '_rtt' and 6 for pid sizeOf += 10 ; sizeOfExtension = strlen(P_extension); if(M_fileNameRtt != NULL) delete [] M_fileNameRtt; sizeOf += sizeOfExtension; M_fileNameRtt = new char[sizeOf+1]; sprintf (M_fileNameRtt, "%s_%d_rtt%s", P_name, getpid(),P_extension); } else { cerr << "new file name length is null - " << "keeping the default filename : " << DEFAULT_FILE_NAME << endl; } } else { cerr << "new file name is NULL ! - keeping the default filename : " << DEFAULT_FILE_NAME << endl; } // calculate M_time_ref M_time_ref = (double)M_startTime.tv_sec*1000.0 + (double)M_startTime.tv_usec/1000.0 ; // initiate the table dump response time M_report_freq_dumpRtt = P_report_freq_dumpRtt ; M_dumpRespTime = new T_value_rtt [P_report_freq_dumpRtt] ; if ( M_dumpRespTime == NULL ) { cerr << "Memory allocation failure" << endl; exit(EXIT_FATAL_ERROR); } for (L_i = 0 ; L_i < P_report_freq_dumpRtt; L_i ++) { M_dumpRespTime[L_i].date = 0.0; M_dumpRespTime[L_i].rtt = 0.0; }}void CStat::setRepartitionCallLength(char * P_listeStr){ unsigned int * listeInteger; int sizeOfListe; if(createIntegerTable(P_listeStr, &listeInteger, &sizeOfListe) == 1) { initRepartition(listeInteger, sizeOfListe, &M_CallLengthRepartition, &M_SizeOfCallLengthRepartition); } else { M_CallLengthRepartition = NULL; M_SizeOfCallLengthRepartition = 0; } delete [] listeInteger; listeInteger = NULL;}void CStat::setRepartitionResponseTime (char * P_listeStr){ unsigned int * listeInteger; int sizeOfListe; int i; for (i = 0; i < MAX_RTD_INFO_LENGTH; i++) { if(createIntegerTable(P_listeStr, &listeInteger, &sizeOfListe) == 1) { initRepartition(listeInteger, sizeOfListe, &M_ResponseTimeRepartition[i], &M_SizeOfResponseTimeRepartition); } else { M_CallLengthRepartition = NULL; M_SizeOfCallLengthRepartition = 0; } } delete [] listeInteger; listeInteger = NULL;}void CStat::setRepartitionCallLength(unsigned int* repartition, int nombre){ initRepartition(repartition, nombre, &M_CallLengthRepartition, &M_SizeOfCallLengthRepartition);} void CStat::setRepartitionResponseTime(unsigned int* repartition, int nombre){ for (int i = 0; i < MAX_RTD_INFO_LENGTH; i++) { initRepartition(repartition, nombre, &M_ResponseTimeRepartition[i], &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_FAILED_OUTBOUND_CONGESTION : M_counters [CPT_C_FailedOutboundCongestion]++; M_counters [CPT_PD_FailedOutboundCongestion]++; M_counters [CPT_PL_FailedOutboundCongestion]++; break; case E_FAILED_TIMEOUT_ON_RECV : M_counters [CPT_C_FailedTimeoutOnRecv]++; M_counters [CPT_PD_FailedTimeoutOnRecv]++; M_counters [CPT_PL_FailedTimeoutOnRecv]++; 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_RETRANSMISSION : M_counters [CPT_C_Retransmissions]++; M_counters [CPT_PD_Retransmissions]++; M_counters [CPT_PL_Retransmissions]++; break; case E_AUTO_ANSWERED : // 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);}int CStat::computeRtt (unsigned long P_start_time, double P_stop_time) { M_dumpRespTime[M_counterDumpRespTime].date = (P_stop_time - M_time_ref) ; M_dumpRespTime[M_counterDumpRespTime].rtt = ( P_stop_time - (P_start_time + M_time_ref)); M_counterDumpRespTime++ ; if (M_counterDumpRespTime > (M_report_freq_dumpRtt - 1)) { dumpDataRtt () ; } return (0);}int CStat::get_current_counter_call (){ return (M_counters[CPT_C_CurrentCall]);}unsigned long CStat::GetStat (E_CounterName P_counter){ return M_counters [P_counter];}/* Use the short form standard deviation formula given our average square and * the average. */unsigned long CStat::computeStdev(E_CounterName P_AverageCounter, E_CounterName P_NbOfCallUsed, E_CounterName P_Squares) { return (unsigned long)sqrt((double)(M_counters[P_Squares] - (M_counters[P_AverageCounter] * M_counters[P_AverageCounter])));}void CStat::updateAverageCounter(E_CounterName P_AverageCounter, E_CounterName P_NbOfCallUsed, E_CounterName P_Squares, unsigned long long* P_sum, unsigned long long* P_sq, unsigned long P_value){ if (M_counters [P_NbOfCallUsed] <= 0) { M_counters [P_NbOfCallUsed] ++; *(P_sum) = M_counters [P_AverageCounter] = P_value; *(P_sq) = M_counters [P_Squares] = (P_value * P_value); } else { (*P_sum) = P_value + (*P_sum); (*P_sq) = (P_value * P_value) + (*P_sq); M_counters [P_AverageCounter] = (*P_sum) / (M_counters [P_NbOfCallUsed] + 1); M_counters [P_Squares] = (*P_sq) / (M_counters [P_NbOfCallUsed] + 1); M_counters [P_NbOfCallUsed] ++; }}int CStat::computeStat (E_Action P_action, unsigned long P_value) { return computeStat(P_action, P_value, 0);}int CStat::computeStat (E_Action P_action, unsigned long P_value, int which){ switch (P_action) { case E_ADD_CALL_DURATION : // Updating Cumulative Counter updateAverageCounter(CPT_C_AverageCallLength, CPT_C_NbOfCallUsedForAverageCallLength, CPT_C_AverageCallLength_Squares, &M_C_sumCallLength, &M_C_sumCallLength_Square, P_value); updateRepartition(M_CallLengthRepartition, M_SizeOfCallLengthRepartition, P_value); // Updating Periodical Diplayed counter updateAverageCounter(CPT_PD_AverageCallLength, CPT_PD_NbOfCallUsedForAverageCallLength, CPT_PD_AverageCallLength_Squares, &M_PD_sumCallLength, &M_PD_sumCallLength_Square, P_value); // Updating Periodical Logging counter updateAverageCounter(CPT_PL_AverageCallLength, CPT_PL_NbOfCallUsedForAverageCallLength, CPT_PL_AverageCallLength_Squares, &M_PL_sumCallLength, &M_PL_sumCallLength_Square, P_value); break; case E_ADD_GENERIC_COUNTER : M_counters [CPT_C_Generic + which] += P_value; M_counters [CPT_PD_Generic + which] += P_value; M_counters [CPT_PL_Generic + which] += P_value; break; case E_ADD_RESPONSE_TIME_DURATION : // Updating Cumulative Counter updateAverageCounter((E_CounterName)(CPT_C_AverageResponseTime + which), (E_CounterName)(CPT_C_NbOfCallUsedForAverageResponseTime + which), (E_CounterName)(CPT_C_AverageResponseTime_Squares + which), &M_C_sumResponseTime[which], &M_C_sumResponseTime_Square[which], P_value); updateRepartition(M_ResponseTimeRepartition[which], M_SizeOfResponseTimeRepartition, P_value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -