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"
18 /// Calculates the average latency and Standard deviation.
19 /// Expects the input data in my_results.dat.
21 calculate_avg_latency ();
25 Demux_Stats::parse_args (int argc_
, char * argv_
[]);
29 /// temporary results file.
36 // parse command line arguments (if any).
38 Demux_Stats::parse_args (int argc_
, char * argv_
[])
40 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("i:"));
44 while ((c
= get_opts ()) != -1)
48 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
57 Demux_Stats::calculate_avg_latency ()
60 char str1
[50], str2
[50], str3
[50];
62 double temp
, mean_poa
, mean_servant
, mean_dispatch
, mean_perfect
, mean_dynamic
, mean_binary
, mean_linear
, mean_parse
;
63 double deviation_poa
, deviation_servant
, deviation_dispatch
;
64 double std_deviation_poa
, std_deviation_servant
, std_deviation_dispatch
;
65 double sum_poa_temp
, sum_servant_temp
, sum_dispatch_temp
;
66 double time_temp
, items_temp
;
69 CORBA::ULong sum_poa
, sum_servant
, sum_dispatch
, last_poa_time
=0, last_servant_time
=0, last_dispatch_time
=0;
70 CORBA::ULong sum_linear
, sum_dynamic
, sum_binary
, sum_perfect
, sum_parse
;
71 CORBA::ULong last_dynamic_time
=0, last_linear_time
=0, last_perfect_time
=0, last_binary_time
=0, last_parse_time
= 0;
75 if ((this->result_fp_
= ACE_OS::fopen ("my_results.dat", "r")) == 0)
77 ACE_ERROR_RETURN ((LM_ERROR
,
78 "Demux_Test_Client::print_results - "
79 "Failed to open the results file for reading\n"),
95 while (fscanf (this->result_fp_
, "%s %s %s %ld %ld", &str1
, &str2
, &str3
, &i
, &time
) != EOF
)
97 if(ACE_OS::strcmp (str1
,"POA::locate_poa_i")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
99 if (items
< 1) { items
= items
+ 1; counter
++; }
103 last_poa_time
= time
;
109 if(ACE_OS::strcmp (str1
,"POA::find_servant")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
111 if (items
< 1) { items
= items
+ 1; counter
++; }
115 last_servant_time
= time
;
121 if(ACE_OS::strcmp (str1
,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
123 if (items
< 1) { ++items
; counter
++; }
126 sum_dispatch
+= time
;
127 last_dispatch_time
= time
;
133 if(ACE_OS::strcmp (str1
,"TAO_Dynamic_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
135 if (items
< 1) { ++items
; counter
++; }
139 last_dynamic_time
= time
;
145 if(ACE_OS::strcmp (str1
,"TAO_Linear_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
147 if (items
< 1) { items
++; counter
++; }
151 last_linear_time
= time
;
157 if(ACE_OS::strcmp (str1
,"TAO_Perfect_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
159 if (items
< 1) { items
++; counter
++; }
163 last_perfect_time
= time
;
169 if(ACE_OS::strcmp (str1
,"TAO_Binary_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
171 if (items
< 1) { items
++; counter
++; }
175 last_binary_time
= time
;
181 if(ACE_OS::strcmp (str1
,"POA::parse_key")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
183 if (items
< 1) { items
++; counter
++; }
187 last_parse_time
= time
;
195 if (counter
== iterations
)
197 mean_poa
= sum_poa
/items
;
198 mean_servant
= sum_servant
/items
;
199 mean_dispatch
= sum_dispatch
/items
;
200 mean_dynamic
= sum_dynamic
/items
;
201 mean_linear
= sum_linear
/items
;
202 mean_binary
= sum_binary
/items
;
203 mean_perfect
= sum_perfect
/items
;
204 ACE_OS::printf("Average response times = POA = %lf SERVANT = %lf DISPATCH = %lf PERFECT = %lf DYNAMIC = %lf BINARY = %lf LINEAR = %lf microsec\n",
225 ACE_OS::fclose (this->result_fp_
);
229 sum_poa
-= last_poa_time
;
230 sum_servant
-= last_servant_time
;
231 sum_dispatch
-= last_dispatch_time
;
232 sum_dynamic
-= last_dynamic_time
;
233 sum_linear
-= last_linear_time
;
234 sum_perfect
-= last_perfect_time
;
235 sum_binary
-= last_binary_time
;
236 sum_parse
-= last_parse_time
;
242 mean_poa
= sum_poa
/items
;
243 mean_servant
= sum_servant
/items
;
244 mean_dispatch
= sum_dispatch
/items
;
245 mean_dynamic
= sum_dynamic
/items
;
246 mean_linear
= sum_linear
/items
;
247 mean_binary
= sum_binary
/items
;
248 mean_perfect
= sum_perfect
/items
;
249 mean_parse
= sum_parse
/items
;
252 // now compute standard deviation
255 if ((this->result_fp_
= ACE_OS::fopen ("my_results.dat", "r")) == 0)
257 ACE_ERROR_RETURN ((LM_ERROR
,
258 "Demux_Test_Client::print_results - "
259 "Failed to open the results file for reading\n"),
265 sum_servant_temp
= 0;
266 sum_dispatch_temp
= 0;
269 deviation_servant
= 0.0;
270 deviation_dispatch
= 0.0;
272 while (fscanf (this->result_fp_
, "%s %s %s %ld %ld", &str1
, &str2
, &str3
, &i
, &time
) != EOF
)
274 time_temp
= (double) time
;
276 if(ACE_OS::strcmp (str1
,"POA::locate_poa_i")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
278 deviation_poa
= time_temp
- mean_poa
;
279 sum_poa_temp
+= deviation_poa
* deviation_poa
;
282 if(ACE_OS::strcmp (str1
,"POA::find_servant")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
284 deviation_servant
= time_temp
- mean_servant
;
285 sum_servant_temp
+= deviation_servant
* deviation_servant
;
288 if(ACE_OS::strcmp (str1
,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3
,"end") == 0))
290 deviation_dispatch
= time_temp
- mean_dispatch
;
291 sum_dispatch_temp
+= deviation_dispatch
* deviation_dispatch
;
295 items_temp
= (double) items
;
299 std_deviation_poa
= 0;
300 std_deviation_servant
= 0;
301 std_deviation_dispatch
= 0;
305 std_deviation_poa
= sqrt (sum_poa_temp
/(items_temp
- 1));
306 std_deviation_servant
= sqrt (sum_servant_temp
/(items_temp
- 1));
307 std_deviation_dispatch
= sqrt (sum_dispatch_temp
/(items_temp
- 1));
310 // ACE_OS::unlink ("my_results.dat");
311 ACE_OS::fclose (this->result_fp_
);
315 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
,
328 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
330 Demux_Stats demux_stats
;
332 demux_stats
.parse_args (argc
, argv
);
333 demux_stats
.calculate_avg_latency ();