Update bug_report.md
[ACE_TAO.git] / ACE / performance-tests / Synch-Benchmarks / Perf_Test / Performance_Test.cpp
blobe7db4e909a275fe6820d3f9235e741041f24e299
1 #define ACE_BUILD_SVC_DLL
3 #include "Performance_Test.h"
5 # if defined (ACE_HAS_THREADS)
7 #include "Performance_Test_Options.h"
8 #include "Benchmark_Performance.h"
10 #include "ace/Service_Repository.h"
11 #include "ace/Reactor.h"
13 Performance_Test::Performance_Test ()
14 : n_lwps_ (0),
15 orig_n_lwps_ (0)
19 // Initialize and run the benchmarks tests.
21 int
22 Performance_Test::init (int argc, ACE_TCHAR **argv)
24 ACE_DEBUG ((LM_DEBUG, "Performance_Test::init\n"));
25 performance_test_options.parse_args (argc, argv);
26 return 0;
29 int
30 Performance_Test::pre_run_test (Benchmark_Base *bb)
32 this->orig_n_lwps_ = ACE_Thread::getconcurrency ();
33 this->n_lwps_ = performance_test_options.n_lwps ();
34 Benchmark_Performance *bp = (Benchmark_Performance *) bb;
36 if (this->n_lwps_ > 0)
37 ACE_Thread::setconcurrency (this->n_lwps_);
39 // We should probably use a "barrier" here rather than
40 // THR_SUSPENDED since many OS platforms lack the ability to
41 // create suspended threads...
42 if (ACE_Thread_Manager::instance ()->spawn_n
43 (performance_test_options.thr_count (), ACE_THR_FUNC (bp->svc_run),
44 (void *) bp, performance_test_options.t_flags () | THR_SUSPENDED) == -1)
45 ACE_ERROR ((LM_ERROR, "%p\n%a", "couldn't spawn threads", 1));
46 return 0;
49 int
50 Performance_Test::run_test ()
52 // Tell the threads that we are not finished.
53 Benchmark_Performance::done (0);
55 // Allow thread(s) to make progress.
56 ACE_Thread_Manager::instance ()->resume_all ();
58 ACE_Time_Value timeout (performance_test_options.sleep_time ());
60 ACE_DEBUG ((LM_DEBUG, "starting timer\n"));
61 performance_test_options.start_timer ();
63 // Use Reactor as a timer (which can be interrupted by a signal).
64 ACE_Reactor::run_event_loop (timeout);
66 performance_test_options.stop_timer ();
67 ACE_DEBUG ((LM_DEBUG, "\nstopping timer\n"));
69 return 0;
72 int
73 Performance_Test::post_run_test ()
75 // Stop thread(s) from making any further progress.
76 ACE_Thread_Manager::instance ()->suspend_all ();
78 // Tell the threads that we are finished.
79 Benchmark_Performance::done (1);
81 ACE_DEBUG ((LM_DEBUG, "------------------------------------------------------------------------\n"));
82 ACE_DEBUG ((LM_DEBUG, "targ 0x%x (%s, %s, %s)\n"
83 "n_lwps_orig = %d, n_lwps_set = %d, n_lwps_end = %d\n",
84 performance_test_options.t_flags (),
85 (performance_test_options.t_flags () & THR_DETACHED) ? "THR_DETACHED" : "Not Detached",
86 (performance_test_options.t_flags () & THR_BOUND) ? "THR_BOUND" : "Not Bound",
87 (performance_test_options.t_flags () & THR_NEW_LWP) ? "THR_NEW_LWP" : "No New_LWP",
88 this->orig_n_lwps_, this->n_lwps_, ACE_Thread::getconcurrency ()));
89 int count = performance_test_options.count ();
90 float rate = count / (float (performance_test_options.sleep_time ()));
92 ACE_DEBUG ((LM_DEBUG,
93 "to count = %d\nrate = %.3f ops/sec, per operation = %.2f usec\n",
94 count,
95 rate,
96 (1.0e6 / rate) / synch_count));
97 performance_test_options.print_results ();
98 // Allow thread(s) to finish up.
99 ACE_Thread_Manager::instance ()->resume_all ();
101 // Wait for all the threads to exit.
102 ACE_Thread_Manager::instance ()->wait ();
103 performance_test_options.init ();
105 return 0;
109 Performance_Test::valid_test_object (Benchmark_Base *bb)
111 return (bb->benchmark_type () == Benchmark_Base::PERFORMANCE);
114 ACE_SVC_FACTORY_DEFINE (Performance_Test)
116 #endif /* ACE_HAS_THREADS */