=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / performance-tests / POA / Demux / demux_stats.cpp
blob9df67df49384a84b4090ec71901b85cdc51840ad
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
17 public:
18 /// Calculates the average latency and Standard deviation.
19 /// Expects the input data in my_results.dat.
20 int
21 calculate_avg_latency ();
23 /// parses args.
24 int
25 Demux_Stats::parse_args (int argc_, char * argv_ []);
27 private :
29 /// temporary results file.
30 FILE *result_fp_;
32 int iterations;
36 // parse command line arguments (if any).
37 int
38 Demux_Stats::parse_args (int argc_, char * argv_ [])
40 ACE_Get_Opt get_opts (argc_, argv_, ACE_TEXT("i:"));
41 int c;
43 iterations = 0;
44 while ((c = get_opts ()) != -1)
45 switch (c)
47 case 'i':
48 iterations = ACE_OS::atoi (get_opts.opt_arg ());
49 break;
52 return 0;
56 int
57 Demux_Stats::calculate_avg_latency ()
59 CORBA::ULong i, time;
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;
68 double items;
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;
73 int counter;
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"),
80 -1);
83 sum_poa = 0;
84 sum_servant = 0;
85 sum_dispatch = 0;
86 sum_dynamic = 0;
87 sum_linear = 0;
88 sum_perfect = 0;
89 sum_binary = 0;
90 sum_parse = 0;
92 items = 0;
93 counter = 0;
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++; }
100 else
102 sum_poa += time;
103 last_poa_time = time;
104 items = items + 1;
105 ++counter;
109 if(ACE_OS::strcmp (str1,"POA::find_servant")==0 && (ACE_OS::strcmp (str3,"end") == 0))
111 if (items < 1) { items = items + 1; counter++; }
112 else
114 sum_servant += time;
115 last_servant_time = time;
116 items = items + 1;
117 counter++;
121 if(ACE_OS::strcmp (str1,"Servant::_dispatch")==0 && (ACE_OS::strcmp (str3,"end") == 0))
123 if (items < 1) { ++items; counter++; }
124 else
126 sum_dispatch += time;
127 last_dispatch_time = time;
128 ++items;items++;
129 counter++;
133 if(ACE_OS::strcmp (str1,"TAO_Dynamic_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
135 if (items < 1) { ++items; counter++; }
136 else
138 sum_dynamic += time;
139 last_dynamic_time = time;
140 ++items;
141 counter++;
145 if(ACE_OS::strcmp (str1,"TAO_Linear_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
147 if (items < 1) { items++; counter++; }
148 else
150 sum_linear += time;
151 last_linear_time = time;
152 items++;
153 counter++;
157 if(ACE_OS::strcmp (str1,"TAO_Perfect_Hash_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
159 if (items < 1) { items++; counter++; }
160 else
162 sum_perfect += time;
163 last_perfect_time = time;
164 items++;
165 counter++;
169 if(ACE_OS::strcmp (str1,"TAO_Binary_Search_OpTable::find")==0 && (ACE_OS::strcmp (str3,"end") == 0))
171 if (items < 1) { items++; counter++; }
172 else
174 sum_binary += time;
175 last_binary_time = time;
176 items++;
177 counter++;
181 if(ACE_OS::strcmp (str1,"POA::parse_key")==0 && (ACE_OS::strcmp (str3,"end") == 0))
183 if (items < 1) { items++; counter++; }
184 else
186 sum_parse += time;
187 last_parse_time = time;
188 items++;
189 counter++;
193 if (iterations !=0 )
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",
205 mean_poa,
206 mean_servant,
207 mean_dispatch,
208 mean_perfect,
209 mean_dynamic,
210 mean_binary,
211 mean_linear);
212 sum_poa = 0;
213 sum_servant = 0;
214 sum_dispatch = 0;
215 sum_dynamic = 0;
216 sum_linear = 0;
217 sum_perfect = 0;
218 sum_binary = 0;
219 items = 0;
220 counter = 0;
225 ACE_OS::fclose (this->result_fp_);
227 if (iterations == 0)
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;
238 //items = items - 4;
240 items = items - 2;
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"),
260 -1);
264 sum_poa_temp = 0;
265 sum_servant_temp = 0;
266 sum_dispatch_temp = 0;
268 deviation_poa = 0.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;
297 if (items == 1)
299 std_deviation_poa = 0;
300 std_deviation_servant = 0;
301 std_deviation_dispatch = 0;
303 else
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_);
313 if (iterations == 0)
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,
316 mean_dispatch,
317 mean_perfect,
318 mean_dynamic,
319 mean_binary,
320 mean_linear,
321 mean_parse);
324 return 0;
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 ();