Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / performance-tests / Latency / Thread_Per_Connection / client.cpp
blobb377c69f6dd153f605b4b77baac1593d5cfa2880
1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/Stats.h"
6 #include "ace/Throughput_Stats.h"
7 #include "ace/OS_NS_errno.h"
9 #include "tao/Strategies/advanced_resource.h"
11 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
12 int niterations = 1000;
13 int do_shutdown = 1;
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:i:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'x':
25 do_shutdown = 0;
26 break;
28 case 'k':
29 ior = get_opts.opt_arg ();
30 break;
32 case 'i':
33 niterations = ACE_OS::atoi (get_opts.opt_arg ());
34 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "usage: %s "
40 "-k <ior> "
41 "-i <niterations> "
42 "-x (disable shutdown) "
43 "\n",
44 argv [0]),
45 -1);
47 // Indicates successful parsing of the command line
48 return 0;
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 int priority =
55 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
56 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
57 // Enable FIFO scheduling
59 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
60 priority,
61 ACE_SCOPE_PROCESS)) != 0)
63 if (ACE_OS::last_error () == EPERM)
65 ACE_DEBUG ((LM_DEBUG,
66 "client (%P|%t): user is not superuser, "
67 "test runs in time-shared class\n"));
69 else
70 ACE_ERROR ((LM_ERROR,
71 "client (%P|%t): sched_params failed\n"));
74 try
76 CORBA::ORB_var orb =
77 CORBA::ORB_init (argc, argv);
79 if (parse_args (argc, argv) != 0)
80 return 1;
82 CORBA::Object_var object =
83 orb->string_to_object (ior);
85 Test::Roundtrip_var roundtrip =
86 Test::Roundtrip::_narrow (object.in ());
88 if (CORBA::is_nil (roundtrip.in ()))
90 ACE_ERROR_RETURN ((LM_ERROR,
91 "Nil Test::Roundtrip reference <%s>\n",
92 ior),
93 1);
96 ACE_DEBUG ((LM_DEBUG, "Starting threads\n"));
98 Client_Task task0(roundtrip.in (), niterations);
99 Client_Task task1(roundtrip.in (), niterations);
100 Client_Task task2(roundtrip.in (), niterations);
101 Client_Task task3(roundtrip.in (), niterations);
103 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
104 task0.activate(THR_NEW_LWP | THR_JOINABLE);
105 task1.activate(THR_NEW_LWP | THR_JOINABLE);
106 task2.activate(THR_NEW_LWP | THR_JOINABLE);
107 task3.activate(THR_NEW_LWP | THR_JOINABLE);
109 task0.thr_mgr()->wait ();
110 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
112 ACE_DEBUG ((LM_DEBUG, "Threads finished\n"));
114 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
115 ACE_High_Res_Timer::global_scale_factor_type gsf =
116 ACE_High_Res_Timer::global_scale_factor ();
117 ACE_DEBUG ((LM_DEBUG, "done\n"));
119 ACE_Basic_Stats totals;
120 task0.accumulate_and_dump (totals, ACE_TEXT("Task[0]"), gsf);
121 task1.accumulate_and_dump (totals, ACE_TEXT("Task[1]"), gsf);
122 task2.accumulate_and_dump (totals, ACE_TEXT("Task[2]"), gsf);
123 task3.accumulate_and_dump (totals, ACE_TEXT("Task[3]"), gsf);
125 totals.dump_results (ACE_TEXT("Total"), gsf);
127 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
128 test_end - test_start,
129 totals.samples_count ());
131 if (do_shutdown)
133 roundtrip->shutdown ();
136 catch (const CORBA::Exception& ex)
138 ex._tao_print_exception ("Exception caught:");
139 return 1;
142 return 0;