Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / POA / Demux / demux_stats.cpp
blob2cea585ce4cd7f17292fa220f3a9bc04c2ff1634
1 //=============================================================================
2 /**
3 * @file demux_stats.cpp
5 * @author Vishal Kachroo
6 */
7 //=============================================================================
10 // FUZZ: disable check_for_math_include
11 #include <math.h>
12 #include "ace/Get_Opt.h"
13 #include "tao/corba.h"
15 class Demux_Stats
18 public:
20 /// Calculates the average latency and Standard deviation.
21 /// Expects the input data in my_results.dat.
22 int
23 calculate_avg_latency (void);
25 /// parses args.
26 int
27 Demux_Stats::parse_args (int argc_, char * argv_ []);
29 private :
31 /// temporary results file.
32 FILE *result_fp_;
34 int iterations;
38 // parse command line arguments (if any).
39 int
40 Demux_Stats::parse_args (int argc_, char * argv_ [])
43 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("i:"));
44 int c;
46 iterations = 0;
47 while ((c = get_opts ()) != -1)
48 switch (c)
50 case 'i':
51 iterations = ACE_OS::atoi (get_opts.opt_arg ());
52 break;
55 return 0;
59 int
60 Demux_Stats::calculate_avg_latency ()
63 CORBA::ULong i, time;
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;
72 double items;
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;
77 int counter;
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"),
84 -1);
87 sum_poa = 0;
88 sum_servant = 0;
89 sum_dispatch = 0;
90 sum_dynamic = 0;
91 sum_linear = 0;
92 sum_perfect = 0;
93 sum_binary = 0;
94 sum_parse = 0;
96 items = 0;
97 counter = 0;
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++; }
105 else
107 sum_poa += time;
108 last_poa_time = time;
109 items = items + 1;
110 ++counter;
114 if(ACE_OS::strcmp (str1,"POA::find_servant")==0 && (ACE_OS::strcmp (str3,"end") == 0))
116 if (items < 1) { items = items + 1; counter++; }
117 else
119 sum_servant += time;
120 last_servant_time = time;
121 items = items + 1;
122 counter++;
126 if(ACE_OS::strcmp (str1,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3,"end") == 0))
128 if (items < 1) { ++items; counter++; }
129 else
131 sum_dispatch += time;
132 last_dispatch_time = time;
133 ++items;items++;
134 counter++;
138 if(ACE_OS::strcmp (str1,"TAO_Dynamic_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
140 if (items < 1) { ++items; counter++; }
141 else
143 sum_dynamic += time;
144 last_dynamic_time = time;
145 ++items;
146 counter++;
150 if(ACE_OS::strcmp (str1,"TAO_Linear_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
152 if (items < 1) { items++; counter++; }
153 else
155 sum_linear += time;
156 last_linear_time = time;
157 items++;
158 counter++;
162 if(ACE_OS::strcmp (str1,"TAO_Perfect_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
164 if (items < 1) { items++; counter++; }
165 else
167 sum_perfect += time;
168 last_perfect_time = time;
169 items++;
170 counter++;
174 if(ACE_OS::strcmp (str1,"TAO_Binary_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
176 if (items < 1) { items++; counter++; }
177 else
179 sum_binary += time;
180 last_binary_time = time;
181 items++;
182 counter++;
186 if(ACE_OS::strcmp (str1,"POA::parse_key")==0 && (ACE_OS::strcmp (str3,"end") == 0))
188 if (items < 1) { items++; counter++; }
189 else
191 sum_parse += time;
192 last_parse_time = time;
193 items++;
194 counter++;
198 if (iterations !=0 )
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",
210 mean_poa,
211 mean_servant,
212 mean_dispatch,
213 mean_perfect,
214 mean_dynamic,
215 mean_binary,
216 mean_linear);
217 sum_poa = 0;
218 sum_servant = 0;
219 sum_dispatch = 0;
220 sum_dynamic = 0;
221 sum_linear = 0;
222 sum_perfect = 0;
223 sum_binary = 0;
224 items = 0;
225 counter = 0;
230 ACE_OS::fclose (this->result_fp_);
232 if (iterations == 0)
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;
243 //items = items - 4;
245 items = items - 2;
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"),
265 -1);
269 sum_poa_temp = 0;
270 sum_servant_temp = 0;
271 sum_dispatch_temp = 0;
273 deviation_poa = 0.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;
302 if (items == 1)
304 std_deviation_poa = 0;
305 std_deviation_servant = 0;
306 std_deviation_dispatch = 0;
308 else
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_);
318 if (iterations == 0)
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,
322 mean_dispatch,
323 mean_perfect,
324 mean_dynamic,
325 mean_binary,
326 mean_linear,
327 mean_parse);
330 return 0;
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 ();