00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_ScenarioStats.hpp"
00021 #include "C_Scenario.hpp"
00022
00023 #include "GeneratorTrace.hpp"
00024 #include "GeneratorError.h"
00025
00026
00027 #define max(a,b) ((a)>(b)) ? (a) : (b)
00028
00029 #define DISPLAY_CROSS_LINE()\
00030 printf("|--------------------------+-------------------------+-------------------------|\r\n")
00031
00032 #define DISPLAY_COMMAND(T) \
00033 printf("| %-24s | |\r\n", (T))
00034
00035 #define DISPLAY_FIRST_LINE(T1,T2,T3,T4,T5) \
00036 printf("| %-24s | %-10s | %-10s | %-10s | %-10s |\r\n", (T1), (T2), (T3), (T4), (T5))
00037
00038 #define DISPLAY_COUNTERS(T,V1,V2,V3,V4) \
00039 printf("| %-24s | %10d | %10d | %10d | %10d |\r\n", (T), (V1), (V2), (V3), (V4))
00040
00041
00042 #define DISPLAY_3TXT(T1, T2, T3)\
00043 printf("| %-24s | %23s | %23s |\r\n", (T1), (T2), (T3))
00044
00045
00046
00047 C_ScenarioStats::C_ScenarioStats(C_Scenario *P_scen) {
00048
00049 int L_i ;
00050 char *L_name ;
00051
00052
00053 m_scenario = P_scen ;
00054
00055 if (m_scenario->m_sequence_max > 1) {
00056 m_nb_command = m_scenario->m_sequence_max - 1;
00057
00058
00059 ALLOC_TABLE(m_counter_cmd_table,
00060 T_pCommandStat,
00061 sizeof(T_CommandStat),
00062 m_nb_command);
00063
00064 for (L_i = 0 ; L_i < m_nb_command ; L_i++) {
00065 m_counter_cmd_table[L_i].m_name = NULL ;
00066 ALLOC_TABLE(L_name, char*, sizeof(char), 25);
00067 L_name[0] = '\0' ;
00068
00069
00070 switch (m_scenario->m_cmd_sequence[L_i].m_type) {
00071 case E_CMD_SCEN_SEND:
00072 snprintf(L_name, 25, "%20s -->",
00073 m_scenario->m_cmd_sequence[L_i].m_message->name());
00074 case E_CMD_SCEN_RECEIVE:
00075 if (L_name[0] == '\0') {
00076 snprintf(L_name, 25, "%20s <--",
00077 m_scenario->m_cmd_sequence[L_i].m_message->name());
00078 }
00079 NEW_TABLE (m_counter_cmd_table[L_i].m_counters,
00080 C_CounterData, (size_t)E_NB_ACTIONS);
00081 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE]
00082 .m_counter_value = 0;
00083 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS]
00084 .m_counter_value = 0;
00085 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT]
00086 .m_counter_value = 0;
00087 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED]
00088 .m_counter_value = 0;
00089 break ;
00090 case E_CMD_SCEN_WAIT:
00091 snprintf(L_name, 25, " [%8ld ms]",
00092 m_scenario->m_cmd_sequence[L_i].m_duration);
00093 m_counter_cmd_table[L_i].m_counters = NULL ;
00094 break ;
00095 default:
00096 break ;
00097 }
00098 m_counter_cmd_table[L_i].m_name = L_name ;
00099
00100 }
00101
00102 m_current_scen_stat_id = -1 ;
00103 m_nb_stat_scen_id = 1 ;
00104 ALLOC_TABLE(m_current_scen_stat_table,
00105 T_DisplayScenFct*,
00106 sizeof(T_DisplayScenFct), 2);
00107 m_current_scen_stat_table[0] = &C_ScenarioStats::display_stats_command ;
00108 m_current_scen_stat_display = m_current_scen_stat_table[0];
00109
00110 m_scenario -> set_stats (this);
00111 } else {
00112 GEN_ERROR(E_GEN_FATAL_ERROR,
00113 "Bad scenario definition");
00114
00115 }
00116
00117 }
00118
00119 C_ScenarioStats::~C_ScenarioStats(){
00120 int L_i ;
00121
00122 m_scenario = NULL ;
00123 for (L_i = 0 ; L_i < m_nb_command; L_i++) {
00124 FREE_TABLE(m_counter_cmd_table[L_i].m_name);
00125 DELETE_TABLE(m_counter_cmd_table[L_i].m_counters);
00126 }
00127 FREE_TABLE(m_counter_cmd_table);
00128 m_nb_command = 0 ;
00129 FREE_TABLE(m_current_scen_stat_table);
00130 }
00131
00132
00133 void C_ScenarioStats::updateStats (int P_cmd_index,
00134 T_ScenarioStatDataAction P_action,
00135 int P_sub_msg_index) {
00136
00137 switch (P_action) {
00138 case E_MESSAGE :
00139 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.P();
00140 (m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_counter_value)++ ;
00141 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.V();
00142 break ;
00143 case E_RETRANS :
00144 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.P();
00145 (m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_counter_value)++ ;
00146 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.V();
00147 break ;
00148 case E_TIMEOUT :
00149 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.P();
00150 (m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_counter_value)++ ;
00151 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.V();
00152 break ;
00153
00154 case E_UNEXPECTED :
00155 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.P();
00156 (m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_counter_value)++ ;
00157 m_counter_cmd_table[P_cmd_index].m_counters[P_action].m_sem.V();
00158 break ;
00159
00160 default:
00161 break ;
00162
00163 }
00164 }
00165
00166 void C_ScenarioStats::setCurrentScreen(bool P_first) {
00167
00168
00169 if (P_first == true) {
00170 m_current_scen_stat_id = 0 ;
00171 } else {
00172
00173 m_current_scen_stat_id ++ ;
00174 if (m_current_scen_stat_id == m_nb_stat_scen_id) {
00175 m_current_scen_stat_id = 0 ;
00176 }
00177 }
00178 m_current_scen_stat_display
00179 = m_current_scen_stat_table[m_current_scen_stat_id];
00180 }
00181
00182 void C_ScenarioStats::displayScreen() {
00183
00184 ((this)->*(m_current_scen_stat_display))();
00185
00186 }
00187
00188
00189 void C_ScenarioStats::display_stats_command() {
00190
00191 int L_i ;
00192 T_CounterType L_message, L_timeout, L_unexpected, L_retrans ;
00193
00194 DISPLAY_FIRST_LINE("","Messages","Retrans","Timeout","Unexp.");
00195
00196 for (L_i = 0 ; L_i < m_nb_command ; L_i++) {
00197
00198 if (m_counter_cmd_table[L_i].m_counters) {
00199 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_sem.P();
00200 L_message = m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_counter_value;
00201 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_sem.V();
00202
00203 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_sem.P();
00204 L_timeout = m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_counter_value;
00205 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_sem.V();
00206
00207 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_sem.P();
00208 L_unexpected = m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_counter_value;
00209 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_sem.V();
00210
00211 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_sem.P();
00212 L_retrans = m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_counter_value;
00213 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_sem.V();
00214
00215 DISPLAY_COUNTERS(m_counter_cmd_table[L_i].m_name,
00216 L_message,
00217 L_retrans,
00218 L_timeout,
00219 L_unexpected);
00220 } else {
00221 DISPLAY_COMMAND(m_counter_cmd_table[L_i].m_name);
00222 }
00223
00224 }
00225
00226 if (m_nb_command < 21) {
00227 for (L_i = m_nb_command ; L_i < 21 ; L_i ++) {
00228 DISPLAY_3TXT("","","");
00229 }
00230 }
00231
00232
00233
00234
00235 DISPLAY_CROSS_LINE ();
00236
00237 }
00238
00239
00240
00241 void C_ScenarioStats::reset_cumul_counters() {
00242 int L_i ;
00243
00244 for (L_i = 0 ; L_i < m_nb_command ; L_i++) {
00245
00246 if (m_counter_cmd_table[L_i].m_counters) {
00247 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_sem.P();
00248 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_counter_value = 0 ;
00249 m_counter_cmd_table[L_i].m_counters[(int)E_MESSAGE].m_sem.V();
00250
00251 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_sem.P();
00252 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_counter_value = 0 ;
00253 m_counter_cmd_table[L_i].m_counters[(int)E_TIMEOUT].m_sem.V();
00254
00255 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_sem.P();
00256 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_counter_value = 0 ;
00257 m_counter_cmd_table[L_i].m_counters[(int)E_UNEXPECTED].m_sem.V();
00258
00259 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_sem.P();
00260 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_counter_value = 0;
00261 m_counter_cmd_table[L_i].m_counters[(int)E_RETRANS].m_sem.V();
00262 }
00263 }
00264 }