Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / performance-tests / Synch-Benchmarks / Perf_Test / Performance_Test_Options.cpp
blob626db592f8af0731825645f78b6ecf60042a151e
1 #define ACE_BUILD_SVC_DLL
2 #include "Performance_Test_Options.h"
3 #include "ace/OS_NS_strings.h"
5 #if defined (ACE_HAS_THREADS)
6 // Manages the options.
7 Performance_Test_Options performance_test_options;
9 size_t
10 Performance_Test_Options::count ()
12 size_t total = 0;
14 if (performance_test_options.verbose ())
15 ACE_DEBUG ((LM_DEBUG, "Thread work count size = %d\n", performance_test_options.thr_wc_size));
17 for (int i = 0; i < performance_test_options.thr_wc_size; i++)
19 if (performance_test_options.thr_work_count[i] != 0)
21 // if (performance_test_options.verbose ())
22 ACE_DEBUG ((LM_DEBUG, "count[%d] = %d\n", i, performance_test_options.thr_work_count[i]));
23 total += performance_test_options.thr_work_count[i];
27 return total;
30 void
31 Performance_Test_Options::init ()
33 for (int i = 0; i < this->thr_wc_size; i++)
34 this->thr_work_count[i] = 0;
37 Performance_Test_Options::Performance_Test_Options ()
38 : thr_wc_size (10000),
39 _service_entry (0),
40 _mapped_file (0),
41 _pipe_addr (const_cast<ACE_TCHAR *> (ACE_DEFAULT_RENDEZVOUS)),
42 _sleep_time (100),
43 _n_lwps (0),
44 _thr_count (4),
45 _t_flags (0),
46 _high_water_mark (8 * 1024),
47 _low_water_mark (1024),
48 _msg_size (128),
49 _initial_queue_length (0),
50 _logical_connections (1),
51 _physical_connections (1),
52 _iterations (100000),
53 _generate (0),
54 _udp (0),
55 _debugging (0),
56 _verbosity (0),
57 _ack (1),
58 _checksum (1),
59 _xdr (1),
60 _free_memory (1),
61 _zero_copy (0),
62 _print_summary (0),
63 _consecutive_ports (1),
64 _eager_exit (0)
66 this->thr_work_count = new int[this->thr_wc_size];
67 this->init ();
70 void
71 Performance_Test_Options::parse_args (int argc, ACE_TCHAR *argv[])
73 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("a:A:bBc:C:dDe:F:g:H:i:L:l:M:m:n:Np:P:s:S:t:T:uvX:Z:"), 0);
74 int c;
76 while ((c = get_opt ()) != -1)
77 switch (c)
79 case 'a': // Not used. (do_ack ???)
80 this->_ack = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
81 break;
82 case 'A': // Not used. (set rendezvous point.)
83 this->pipe_addr (get_opt.opt_arg ());
84 break;
85 case 'B': // Create thread with THR_BOUND.
86 this->t_flags (THR_BOUND);
87 break;
88 case 'c': // Not used. (# of connections.)
90 long connections = ACE_OS::atoi (get_opt.opt_arg ());
92 if (connections < 0)
93 this->physical_connections (size_t (-connections));
94 else if (connections > 0)
95 this->logical_connections (size_t (connections));
96 else
97 ACE_DEBUG ((LM_WARNING, "warning, 0 connections!\n"));
99 break;
101 case 'C': // Not used. (Toggle calculate checksum.)
102 this->_checksum = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
103 break;
104 case 'd': // Not used. (Enable debugging.)
105 this->_debugging = 1;
106 break;
107 case 'D': // Create thread with THR_DETACHED.
108 this->t_flags (THR_DETACHED);
109 break;
110 case 'e': // Perform eager exit (without cleaning up.)
111 this->_eager_exit = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
112 break;
113 case 'F': // Not used.
114 this->_free_memory = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
115 break;
116 case 'g': // Not used. (generate data ??)
117 this->_generate = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
118 break;
119 case 'H': // Not used. (set high water mark)
120 this->high_water_mark (ACE_OS::atoi (get_opt.opt_arg ()));
121 break;
122 case 'i': // Not used. (# of iterations)
123 this->iterations (ACE_OS::atoi (get_opt.opt_arg ()));
124 break;
125 case 'L': // Not used. (set low water mark)
126 this->low_water_mark (ACE_OS::atoi (get_opt.opt_arg ()));
127 break;
128 case 'l': // Not used. (set initial queue length)
129 this->initial_queue_length (ACE_OS::atoi (get_opt.opt_arg ()));
130 break;
131 case 'M': // Set message size in pipe_[proc|thr]_test.
132 this->msg_size (ACE_OS::atoi (get_opt.opt_arg ()));
133 break;
134 case 'm': // Not used. (set mapped file name)
135 this->mapped_file (get_opt.opt_arg ());
136 break;
137 case 'N': // Create thread with flag THR_NEW_LWP.
138 this->t_flags (THR_NEW_LWP);
139 break;
140 case 'n': // Set # of lwp's
141 this->n_lwps (ACE_OS::atoi (get_opt.opt_arg ()));
142 break;
143 case 'p': // Toggle whether summary is printed.
144 this->_print_summary = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
145 break;
146 case 'P': // Not used.
147 this->consecutive_ports (ACE_OS::atoi (get_opt.opt_arg ()));
148 break;
149 case 'S': // Not used (set service_entry ???)
150 this->service_entry (get_opt.opt_arg ());
151 break;
152 case 's': // Set testing duration.
153 this->sleep_time (ACE_OS::atoi (get_opt.opt_arg ()));
154 break;
155 case 'T': // Enable/disable tracing.
156 #if defined (ACE_HAS_TRACE)
157 if (ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0)
158 ACE_Trace::start_tracing ();
159 else if (ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("OFF")) == 0)
160 ACE_Trace::stop_tracing ();
161 #endif /* ACE_HAS_TRACE */
162 break;
163 case 't': // Set # of threads contending the lock.
164 this->thr_count (ACE_OS::atoi (get_opt.opt_arg ()));
165 break;
166 case 'u': // Not used. (use udp.)
167 this->_udp = 1;
168 break;
169 case 'v': // Not used. (set display verbosely)
170 this->_verbosity = 1;
171 break;
172 case 'X': // Not used. (Use xdr conversion.)
173 this->_xdr = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
174 break;
175 case 'Z': // Not used. (Do zero copy.)
176 this->_zero_copy = ACE_OS::strcasecmp (get_opt.opt_arg (), ACE_TEXT("ON")) == 0;
177 break;
178 default:
179 ACE_DEBUG ((LM_INFO,
180 "%s\n"
181 "\t[-a] (send acknowledgement)\n"
182 "\t[-A] address of pipe [%s]\n"
183 "\t[-B] (THR_BOUND)\n"
184 "\t[-c] + number of logical connections\n"
185 "\t[-c] - number of physical connections\n"
186 "\t[-C] (enable checksumming)\n"
187 "\t[-d] (enable debugging)\n"
188 "\t[-D] (THR_DETACHED)\n"
189 "\t[-e] (eager exit)\n"
190 "\t[-F] (free memory)\n"
191 "\t[-g] (generate data)\n"
192 "\t[-H] high water mark\n"
193 "\t[-i] number of test iterations [%d]\n"
194 "\t[-L] low water mark\n"
195 "\t[-m] mapped file\n"
196 "\t[-M] message size\n"
197 "\t[-n] number of LWPs\n"
198 "\t[-N] (THR_NEW_LWP)\n"
199 "\t[-p] (print benchmark summary)\n"
200 "\t[-P] number of consecutive ports\n"
201 "\t[-s] sleep time\n"
202 "\t[-S] service entry\n"
203 "\t[-t] number of threads [%d]\n"
204 "\t[-T] (enable tracing)\n"
205 "\t[-u] (UDP)\n"
206 "\t[-v] (verbose)\n"
207 "\t[-X] (enable xdr conversion)\n"
208 "\t[-Z] (enable zero-copy driver)\n%a",
209 argv[0],
210 this->pipe_addr (),
211 this->iterations (),
212 this->thr_count (),
213 1));
214 /* NOTREACHED */
215 break;
218 if (this->do_print_summary ())
219 ACE_DEBUG ((LM_INFO,
220 "%8d = total iterations\n"
221 "%8d = logical connections\n"
222 "%8d = physical connections\n"
223 "%8d = message_size\n"
224 "%8d = calculated checksum\n"
225 "%8d = perform xdr conversion\n"
226 "%8d = number of LWPs requested\n"
227 "%8d = number of LWPs used\n",
228 this->iterations (),
229 this->logical_connections (),
230 this->physical_connections (),
231 this->msg_size (),
232 this->do_checksum () != 0,
233 this->do_xdr() != 0,
234 this->n_lwps (),
235 ACE_Thread::getconcurrency ()));
236 else if (this->verbose ())
237 ACE_DEBUG ((LM_INFO,
238 "%8d = total iterations\n"
239 "%8d = logical connections\n"
240 "%8d = physical connections\n"
241 "%8d = thread count\n"
242 "%8d = low water mark\n"
243 "%8d = high water mark\n"
244 "%8d = message_size\n"
245 "%8d = initial queue length\n"
246 "%8d = consecutive ports\n"
247 "%8d = calculated checksum\n"
248 "%8d = perform xdr conversion\n"
249 "%8d = zero-copy driver\n"
250 "%8d = free dynamic memory\n"
251 "%8d = print summary only\n"
252 "%8d = eager exit\n"
253 "%8d = UDP\n"
254 "%8d = send ack\n"
255 "%8d = THR_DETACHED\n"
256 "%8d = THR_BOUND\n"
257 "%8d = THR_NEW_LWP\n"
258 "%8d = sleep time\n",
259 this->iterations (),
260 this->logical_connections (),
261 this->physical_connections (),
262 this->thr_count (),
263 this->low_water_mark (),
264 this->high_water_mark (),
265 this->msg_size (),
266 this->initial_queue_length (),
267 this->consecutive_ports (),
268 this->do_checksum () != 0,
269 this->do_xdr() != 0,
270 this->do_zero_copy () != 0,
271 this->do_delete () != 0,
272 this->do_print_summary () != 0,
273 this->do_eager_exit () != 0,
274 this->do_udp () != 0,
275 this->do_ack () != 0,
276 (this->t_flags () & THR_DETACHED) != 0,
277 (this->t_flags () & THR_BOUND) != 0,
278 (this->t_flags () & THR_NEW_LWP) != 0,
279 this->sleep_time ()));
282 void
283 Performance_Test_Options::print_results ()
285 ACE_Profile_Timer::ACE_Elapsed_Time et;
286 this->_itimer.elapsed_time (et);
288 ACE_Profile_Timer::Rusage rusage;
289 this->_itimer.elapsed_rusage (rusage);
291 size_t total = this->count ();
292 double nbytes = total * this->msg_size ();
293 double cpu_time = et.user_time + et.system_time;
295 #if 0
296 mutex_timer.print_total ("ACE_Thread_Mutex overhead:", mutex_counter, 2);
297 condition_timer.print_total ("ACE_Condition overhead:", condition_counter, 2);
298 ACE_DEBUG ((LM_INFO,
299 "%8d (number of ACE_Thread_Mutex operations)\n"
300 "%8d (number of ACE_Condition operations)",
301 mutex_counter, condition_counter));
302 #endif /* NDEBUG */
304 if (this->do_print_summary ())
306 #if defined (ACE_HAS_PRUSAGE_T)
307 ACE_DEBUG ((LM_INFO,
308 "\n%8d PEs\n"
309 "%8.2f Mbit/sec\n"
310 "%8d (voluntary context switches)\n"
311 "%8d (involuntary context switches)\n"
312 "%8d (total context switches)\n"
313 "%8d.%d sec (wait-cpu time)\n"
314 "%8d.%d sec (user lock wait sleep time)\n"
315 "%8d.%d sec (all other sleep time)\n"
316 "%8d (major page faults)\n"
317 "%8d (minor page faults)\n"
318 "%8d (number of LWPs)\n",
319 this->thr_count (),
320 (nbytes / et.real_time) * 8.0 / 1024.0 / 1024.0,
321 rusage.pr_vctx,
322 rusage.pr_ictx,
323 rusage.pr_vctx + rusage.pr_ictx,
324 rusage.pr_wtime.tv_sec, rusage.pr_wtime.tv_nsec / 1000000,
325 rusage.pr_ltime.tv_sec, rusage.pr_ltime.tv_nsec / 1000000,
326 rusage.pr_slptime.tv_sec, rusage.pr_slptime.tv_nsec / 1000000,
327 rusage.pr_majf,
328 rusage.pr_minf,
329 ACE_Thread::getconcurrency ()));
330 #elif defined (ACE_HAS_GETRUSAGE) && !defined (ACE_WIN32)
331 ACE_DEBUG ((LM_INFO,
332 "\n%8d PEs\n"
333 "%8.2f Mbit/sec\n"
334 "%8d (voluntary context switches)\n"
335 "%8d (involuntary context switches)\n"
336 "%8d (total context switches)\n"
337 "%8d.%d sec (user time)\n"
338 "%8d.%d sec (system time)\n"
339 "%8d (major page faults)\n"
340 "%8d (minor page faults)\n"
341 "%8d (number of LWPs)\n",
342 this->thr_count (),
343 (nbytes / et.real_time) * 8.0 / 1024.0 / 1024.0,
344 rusage.ru_nvcsw,
345 rusage.ru_nivcsw,
346 rusage.ru_nvcsw + rusage.ru_nivcsw,
347 rusage.ru_utime.tv_sec, rusage.ru_utime.tv_usec / 1000000,
348 rusage.ru_stime.tv_sec, rusage.ru_stime.tv_usec / 1000000,
349 rusage.ru_majflt,
350 rusage.ru_minflt,
351 ACE_Thread::getconcurrency ()));
352 #elif defined (ACE_HAS_GETRUSAGE) && defined (ACE_WIN32)
353 // Need more stuff for Win32.
354 ACE_DEBUG ((LM_INFO,
355 "\n%8d PEs\n"
356 "%8.2f Mbit/sec\n"
357 "%8d (number of LWPs)\n",
358 this->thr_count (),
359 (nbytes / et.real_time) * 8.0 / 1024.0 / 1024.0,
360 ACE_Thread::getconcurrency ()));
361 #endif /* ACE_HAS_PRUSAGE_T */
363 else
365 ACE_DEBUG ((LM_INFO,
366 "\ntotal work = %d\n"
367 "(Only interpret the next two statistics for throughput tests)\n"
368 "%f bytes in %.2f real seconds = %.2f Mbit/sec\n"
369 "%f bytes in %.2f CPU seconds = %.2f Mbit/sec\n",
370 total,
371 nbytes, et.real_time, (nbytes / et.real_time) * 8.0 / 1024.0 / 1024.0,
372 nbytes, cpu_time, (nbytes / cpu_time) * 8.0 / 1024.0 / 1024.0));
374 #if defined (ACE_HAS_PRUSAGE_T)
375 ACE_DEBUG ((LM_INFO,
376 "%8d = lwpid\n"
377 "%8d = lwp count\n"
378 "%8d = minor page faults\n"
379 "%8d = major page faults\n"
380 "%8d = input blocks\n"
381 "%8d = output blocks\n"
382 "%8d = messages sent\n"
383 "%8d = messages received\n"
384 "%8d = signals received\n"
385 "%8ds, %dms = wait-cpu (latency) time\n"
386 "%8ds, %dms = user lock wait sleep time\n"
387 "%8ds, %dms = all other sleep time\n"
388 "%8d = voluntary context switches\n"
389 "%8d = involuntary context switches\n"
390 "%8d = total context switches\n"
391 "%8d = system calls\n"
392 "%8d = chars read/written\n"
393 "%8d = number of LWPs\n"
394 "---------------------\n"
395 "real time = %.3f\n"
396 "user time = %.3f\n"
397 "system time = %.3f\n"
398 "---------------------\n",
399 rusage.pr_lwpid,
400 rusage.pr_count,
401 rusage.pr_minf,
402 rusage.pr_majf,
403 rusage.pr_inblk,
404 rusage.pr_oublk,
405 rusage.pr_msnd,
406 rusage.pr_mrcv,
407 rusage.pr_sigs,
408 rusage.pr_wtime.tv_sec, rusage.pr_wtime.tv_nsec / 1000000,
409 rusage.pr_ltime.tv_sec, rusage.pr_ltime.tv_nsec / 1000000,
410 rusage.pr_slptime.tv_sec, rusage.pr_slptime.tv_nsec / 1000000,
411 rusage.pr_vctx,
412 rusage.pr_ictx,
413 rusage.pr_vctx + rusage.pr_ictx,
414 rusage.pr_sysc,
415 rusage.pr_ioch,
416 ACE_Thread::getconcurrency (),
417 et.real_time, et.user_time, et.system_time));
418 #elif defined (ACE_HAS_GETRUSAGE) && !defined (ACE_WIN32)
419 ACE_DEBUG ((LM_INFO,
420 "%8d = minor page faults\n"
421 "%8d = major page faults\n"
422 "%8d = input blocks\n"
423 "%8d = output blocks\n"
424 "%8d = messages sent\n"
425 "%8d = messages received\n"
426 "%8d = signals received\n"
427 "%8d = voluntary context switches\n"
428 "%8d = involuntary context switches\n"
429 "%8d = total context switches\n"
430 "%8d = number of LWPs\n"
431 "---------------------\n"
432 "real time = %.3f\n"
433 "user time = %.3f\n"
434 "system time = %.3f\n"
435 "---------------------\n",
436 rusage.ru_minflt,
437 rusage.ru_majflt,
438 rusage.ru_inblock,
439 rusage.ru_oublock,
440 rusage.ru_msgsnd,
441 rusage.ru_msgrcv,
442 rusage.ru_nsignals,
443 rusage.ru_nvcsw,
444 rusage.ru_nivcsw,
445 rusage.ru_nvcsw + rusage.ru_nivcsw,
446 ACE_Thread::getconcurrency (),
447 et.real_time, et.user_time, et.system_time));
448 #elif defined (ACE_HAS_GETRUSAGE) && defined (ACE_WIN32)
449 // need to write more dump ops for rusage on Win32
450 ACE_DEBUG ((LM_INFO,
451 "%8d = number of LWPs\n"
452 "---------------------\n"
453 "real time = %.3f\n"
454 "user time = %.3f\n"
455 "system time = %.3f\n"
456 "---------------------\n",
457 ACE_Thread::getconcurrency (),
458 et.real_time, et.user_time, et.system_time));
459 #endif /* ACE_HAS_PRUSAGE_T */
461 if (performance_test_options.do_eager_exit ())
462 ACE_OS::_exit (0);
464 #endif /* ACE_HAS_THREADS */