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
;
10 Performance_Test_Options::count ()
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
];
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),
41 _pipe_addr (const_cast<ACE_TCHAR
*> (ACE_DEFAULT_RENDEZVOUS
)),
46 _high_water_mark (8 * 1024),
47 _low_water_mark (1024),
49 _initial_queue_length (0),
50 _logical_connections (1),
51 _physical_connections (1),
63 _consecutive_ports (1),
66 this->thr_work_count
= new int[this->thr_wc_size
];
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);
76 while ((c
= get_opt ()) != -1)
79 case 'a': // Not used. (do_ack ???)
80 this->_ack
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
82 case 'A': // Not used. (set rendezvous point.)
83 this->pipe_addr (get_opt
.opt_arg ());
85 case 'B': // Create thread with THR_BOUND.
86 this->t_flags (THR_BOUND
);
88 case 'c': // Not used. (# of connections.)
90 long connections
= ACE_OS::atoi (get_opt
.opt_arg ());
93 this->physical_connections (size_t (-connections
));
94 else if (connections
> 0)
95 this->logical_connections (size_t (connections
));
97 ACE_DEBUG ((LM_WARNING
, "warning, 0 connections!\n"));
101 case 'C': // Not used. (Toggle calculate checksum.)
102 this->_checksum
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
104 case 'd': // Not used. (Enable debugging.)
105 this->_debugging
= 1;
107 case 'D': // Create thread with THR_DETACHED.
108 this->t_flags (THR_DETACHED
);
110 case 'e': // Perform eager exit (without cleaning up.)
111 this->_eager_exit
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
113 case 'F': // Not used.
114 this->_free_memory
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
116 case 'g': // Not used. (generate data ??)
117 this->_generate
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
119 case 'H': // Not used. (set high water mark)
120 this->high_water_mark (ACE_OS::atoi (get_opt
.opt_arg ()));
122 case 'i': // Not used. (# of iterations)
123 this->iterations (ACE_OS::atoi (get_opt
.opt_arg ()));
125 case 'L': // Not used. (set low water mark)
126 this->low_water_mark (ACE_OS::atoi (get_opt
.opt_arg ()));
128 case 'l': // Not used. (set initial queue length)
129 this->initial_queue_length (ACE_OS::atoi (get_opt
.opt_arg ()));
131 case 'M': // Set message size in pipe_[proc|thr]_test.
132 this->msg_size (ACE_OS::atoi (get_opt
.opt_arg ()));
134 case 'm': // Not used. (set mapped file name)
135 this->mapped_file (get_opt
.opt_arg ());
137 case 'N': // Create thread with flag THR_NEW_LWP.
138 this->t_flags (THR_NEW_LWP
);
140 case 'n': // Set # of lwp's
141 this->n_lwps (ACE_OS::atoi (get_opt
.opt_arg ()));
143 case 'p': // Toggle whether summary is printed.
144 this->_print_summary
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
146 case 'P': // Not used.
147 this->consecutive_ports (ACE_OS::atoi (get_opt
.opt_arg ()));
149 case 'S': // Not used (set service_entry ???)
150 this->service_entry (get_opt
.opt_arg ());
152 case 's': // Set testing duration.
153 this->sleep_time (ACE_OS::atoi (get_opt
.opt_arg ()));
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 */
163 case 't': // Set # of threads contending the lock.
164 this->thr_count (ACE_OS::atoi (get_opt
.opt_arg ()));
166 case 'u': // Not used. (use udp.)
169 case 'v': // Not used. (set display verbosely)
170 this->_verbosity
= 1;
172 case 'X': // Not used. (Use xdr conversion.)
173 this->_xdr
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
175 case 'Z': // Not used. (Do zero copy.)
176 this->_zero_copy
= ACE_OS::strcasecmp (get_opt
.opt_arg (), ACE_TEXT("ON")) == 0;
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"
207 "\t[-X] (enable xdr conversion)\n"
208 "\t[-Z] (enable zero-copy driver)\n%a",
218 if (this->do_print_summary ())
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",
229 this->logical_connections (),
230 this->physical_connections (),
232 this->do_checksum () != 0,
235 ACE_Thread::getconcurrency ()));
236 else if (this->verbose ())
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"
255 "%8d = THR_DETACHED\n"
257 "%8d = THR_NEW_LWP\n"
258 "%8d = sleep time\n",
260 this->logical_connections (),
261 this->physical_connections (),
263 this->low_water_mark (),
264 this->high_water_mark (),
266 this->initial_queue_length (),
267 this->consecutive_ports (),
268 this->do_checksum () != 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 ()));
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
;
296 mutex_timer
.print_total ("ACE_Thread_Mutex overhead:", mutex_counter
, 2);
297 condition_timer
.print_total ("ACE_Condition overhead:", condition_counter
, 2);
299 "%8d (number of ACE_Thread_Mutex operations)\n"
300 "%8d (number of ACE_Condition operations)",
301 mutex_counter
, condition_counter
));
304 if (this->do_print_summary ())
306 #if defined (ACE_HAS_PRUSAGE_T)
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",
320 (nbytes
/ et
.real_time
) * 8.0 / 1024.0 / 1024.0,
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,
329 ACE_Thread::getconcurrency ()));
330 #elif defined (ACE_HAS_GETRUSAGE) && !defined (ACE_WIN32)
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",
343 (nbytes
/ et
.real_time
) * 8.0 / 1024.0 / 1024.0,
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,
351 ACE_Thread::getconcurrency ()));
352 #elif defined (ACE_HAS_GETRUSAGE) && defined (ACE_WIN32)
353 // Need more stuff for Win32.
357 "%8d (number of LWPs)\n",
359 (nbytes
/ et
.real_time
) * 8.0 / 1024.0 / 1024.0,
360 ACE_Thread::getconcurrency ()));
361 #endif /* ACE_HAS_PRUSAGE_T */
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",
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)
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"
397 "system time = %.3f\n"
398 "---------------------\n",
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,
413 rusage
.pr_vctx
+ rusage
.pr_ictx
,
416 ACE_Thread::getconcurrency (),
417 et
.real_time
, et
.user_time
, et
.system_time
));
418 #elif defined (ACE_HAS_GETRUSAGE) && !defined (ACE_WIN32)
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"
434 "system time = %.3f\n"
435 "---------------------\n",
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
451 "%8d = number of LWPs\n"
452 "---------------------\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 ())
464 #endif /* ACE_HAS_THREADS */