1 //=============================================================================
3 * @file demux_stats.cpp
5 * @author Vishal Kachroo
7 //=============================================================================
10 // FUZZ: disable check_for_math_include
12 #include "ace/Get_Opt.h"
13 #include "tao/corba.h"
20 /// Calculates the average latency and Standard deviation.
21 /// Expects the input data in my_results.dat.
23 calculate_avg_latency (void);
27 Demux_Stats::parse_args (int argc_
, char * argv_
[]);
31 /// temporary results file.
38 // parse command line arguments (if any).
40 Demux_Stats::parse_args (int argc_
, char * argv_
[])
43 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("i:"));
47 while ((c
= get_opts ()) != -1)
51 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
60 Demux_Stats::calculate_avg_latency ()
64 char str1
[50], str2
[50], str3
[50];
66 double temp
, mean_poa
, mean_servant
, mean_dispatch
, mean_perfect
, mean_dynamic
, mean_binary
, mean_linear
, mean_parse
;
67 double deviation_poa
, deviation_servant
, deviation_dispatch
;
68 double std_deviation_poa
, std_deviation_servant
, std_deviation_dispatch
;
69 double sum_poa_temp
, sum_servant_temp
, sum_dispatch_temp
;
70 double time_temp
, items_temp
;
73 CORBA::ULong sum_poa
, sum_servant
, sum_dispatch
, last_poa_time
=0, last_servant_time
=0, last_dispatch_time
=0;
74 CORBA::ULong sum_linear
, sum_dynamic
, sum_binary
, sum_perfect
, sum_parse
;
75 CORBA::ULong last_dynamic_time
=0, last_linear_time
=0, last_perfect_time
=0, last_binary_time
=0, last_parse_time
= 0;
79 if ((this->result_fp_
= ACE_OS::fopen ("my_results.dat", "r")) == 0)
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 "Demux_Test_Client::print_results - "
83 "Failed to open the results file for reading\n"),
99 while (fscanf (this->result_fp_
, "%s %s %s %ld %ld", &str1
, &str2
, &str3
, &i
, &time
) != EOF
)
102 if(ACE_OS::strcmp (str1
,"POA::locate_poa_i")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
104 if (items
< 1) { items
= items
+ 1; counter
++; }
108 last_poa_time
= time
;
114 if(ACE_OS::strcmp (str1
,"POA::find_servant")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
116 if (items
< 1) { items
= items
+ 1; counter
++; }
120 last_servant_time
= time
;
126 if(ACE_OS::strcmp (str1
,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
128 if (items
< 1) { ++items
; counter
++; }
131 sum_dispatch
+= time
;
132 last_dispatch_time
= time
;
138 if(ACE_OS::strcmp (str1
,"TAO_Dynamic_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
140 if (items
< 1) { ++items
; counter
++; }
144 last_dynamic_time
= time
;
150 if(ACE_OS::strcmp (str1
,"TAO_Linear_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
152 if (items
< 1) { items
++; counter
++; }
156 last_linear_time
= time
;
162 if(ACE_OS::strcmp (str1
,"TAO_Perfect_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
164 if (items
< 1) { items
++; counter
++; }
168 last_perfect_time
= time
;
174 if(ACE_OS::strcmp (str1
,"TAO_Binary_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
176 if (items
< 1) { items
++; counter
++; }
180 last_binary_time
= time
;
186 if(ACE_OS::strcmp (str1
,"POA::parse_key")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
188 if (items
< 1) { items
++; counter
++; }
192 last_parse_time
= time
;
200 if (counter
== iterations
)
202 mean_poa
= sum_poa
/items
;
203 mean_servant
= sum_servant
/items
;
204 mean_dispatch
= sum_dispatch
/items
;
205 mean_dynamic
= sum_dynamic
/items
;
206 mean_linear
= sum_linear
/items
;
207 mean_binary
= sum_binary
/items
;
208 mean_perfect
= sum_perfect
/items
;
209 ACE_OS::printf("Average response times = POA = %lf SERVANT = %lf DISPATCH = %lf PERFECT = %lf DYNAMIC = %lf BINARY = %lf LINEAR = %lf microsec\n",
230 ACE_OS::fclose (this->result_fp_
);
234 sum_poa
-= last_poa_time
;
235 sum_servant
-= last_servant_time
;
236 sum_dispatch
-= last_dispatch_time
;
237 sum_dynamic
-= last_dynamic_time
;
238 sum_linear
-= last_linear_time
;
239 sum_perfect
-= last_perfect_time
;
240 sum_binary
-= last_binary_time
;
241 sum_parse
-= last_parse_time
;
247 mean_poa
= sum_poa
/items
;
248 mean_servant
= sum_servant
/items
;
249 mean_dispatch
= sum_dispatch
/items
;
250 mean_dynamic
= sum_dynamic
/items
;
251 mean_linear
= sum_linear
/items
;
252 mean_binary
= sum_binary
/items
;
253 mean_perfect
= sum_perfect
/items
;
254 mean_parse
= sum_parse
/items
;
257 // now compute standard deviation
260 if ((this->result_fp_
= ACE_OS::fopen ("my_results.dat", "r")) == 0)
262 ACE_ERROR_RETURN ((LM_ERROR
,
263 "Demux_Test_Client::print_results - "
264 "Failed to open the results file for reading\n"),
270 sum_servant_temp
= 0;
271 sum_dispatch_temp
= 0;
274 deviation_servant
= 0.0;
275 deviation_dispatch
= 0.0;
277 while (fscanf (this->result_fp_
, "%s %s %s %ld %ld", &str1
, &str2
, &str3
, &i
, &time
) != EOF
)
279 time_temp
= (double) time
;
281 if(ACE_OS::strcmp (str1
,"POA::locate_poa_i")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
283 deviation_poa
= time_temp
- mean_poa
;
284 sum_poa_temp
+= deviation_poa
* deviation_poa
;
287 if(ACE_OS::strcmp (str1
,"POA::find_servant")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
289 deviation_servant
= time_temp
- mean_servant
;
290 sum_servant_temp
+= deviation_servant
* deviation_servant
;
293 if(ACE_OS::strcmp (str1
,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
295 deviation_dispatch
= time_temp
- mean_dispatch
;
296 sum_dispatch_temp
+= deviation_dispatch
* deviation_dispatch
;
300 items_temp
= (double) items
;
304 std_deviation_poa
= 0;
305 std_deviation_servant
= 0;
306 std_deviation_dispatch
= 0;
310 std_deviation_poa
= sqrt (sum_poa_temp
/(items_temp
- 1));
311 std_deviation_servant
= sqrt (sum_servant_temp
/(items_temp
- 1));
312 std_deviation_dispatch
= sqrt (sum_dispatch_temp
/(items_temp
- 1));
315 // ACE_OS::unlink ("my_results.dat");
316 ACE_OS::fclose (this->result_fp_
);
321 ACE_OS::printf("Average response times = POA = %lf SERVANT = %lf DISPATCH = %lf PERFECT = %lf DYNAMIC = %lf BINARY = %lf LINEAR = %lf PARSE = %lf microsec\n", mean_poa
, mean_servant
,
334 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
336 Demux_Stats demux_stats
;
338 demux_stats
.parse_args (argc
, argv
);
339 demux_stats
.calculate_avg_latency ();