2 #include "Latency_Query_Client.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
6 #include "ace/Throughput_Stats.h"
7 #include "ace/Sample_History.h"
9 const CORBA::ULong DEFAULT_NUMCALLS
= 20000;
11 Latency_Query_Client::Latency_Query_Client ()
14 iterations_ (DEFAULT_NUMCALLS
)
18 Latency_Query_Client::~Latency_Query_Client ()
23 Latency_Query_Client::init (int argc
,
28 this->orb_
= CORBA::ORB_init (argc
, argv
);
30 int retval
= this->parse_args (argc
, argv
);
37 CORBA::Object_var object
=
38 this->orb_
->resolve_initial_references ("InterfaceRepository");
40 if (CORBA::is_nil (object
.in ()))
44 "Null objref from resolve_initial_references\n"
49 CORBA::Repository::_narrow (object
.in ());
51 if (CORBA::is_nil (this->repo_
.in ()))
53 ACE_ERROR_RETURN ((LM_ERROR
,
54 "CORBA::Repository::_narrow failed\n"),
58 retval
= this->populate_ifr ();
65 catch (const CORBA::Exception
& ex
)
67 ex
._tao_print_exception ("Latency_Query_Client::init:");
75 Latency_Query_Client::run ()
77 // CORBA::DefinitionKind dk;
78 CORBA::AttributeMode am
;
82 for (int j
= 0; j
< 100; ++j
)
84 am
= this->attr_
->mode ();
86 if (am
!= CORBA::ATTR_NORMAL
)
92 ACE_Sample_History
history (this->iterations_
);
93 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
95 for (CORBA::ULong i
= 0; i
< this->iterations_
; ++i
)
97 ACE_hrtime_t start
= ACE_OS::gethrtime ();
99 am
= this->attr_
->mode ();
101 ACE_hrtime_t now
= ACE_OS::gethrtime ();
102 history
.sample (now
- start
);
105 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
109 ACE_DEBUG ((LM_DEBUG
,
111 ACE_DEBUG ((LM_DEBUG
,
112 "High resolution timer calibration...."));
113 ACE_High_Res_Timer::global_scale_factor_type gsf
=
114 ACE_High_Res_Timer::global_scale_factor ();
115 ACE_DEBUG ((LM_DEBUG
,
118 if (this->do_dump_history_
)
120 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
123 ACE_Basic_Stats stats
;
124 history
.collect_basic_stats (stats
);
125 stats
.dump_results (ACE_TEXT("Total"), gsf
);
127 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
129 test_end
- test_start
,
130 stats
.samples_count ());
133 catch (const CORBA::Exception
& ex
)
135 ex
._tao_print_exception ("Latency_Query_Client::run:");
143 Latency_Query_Client::parse_args (int argc
,
146 ACE_Get_Opt
opts (argc
, argv
, ACE_TEXT("dhi:"));
150 while ((c
= opts ()) != -1)
158 this->do_dump_history_
= true;
161 result
= ACE_OS::atoi (opts
.opt_arg ());
165 this->iterations_
= result
;
171 ACE_ERROR_RETURN ((LM_ERROR
,
185 Latency_Query_Client::populate_ifr ()
187 CORBA::Contained_var irobj
= this->repo_
->lookup_id ("IDL:dummy/attr:1.0");
189 if (! CORBA::is_nil (irobj
.in ()))
191 this->attr_
= CORBA::AttributeDef::_narrow (irobj
.in ());
193 if (CORBA::is_nil (this->attr_
.in ()))
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 "Latency_Query_Client::populate_ifr - "
197 "AttributeDef::_narrow returned null\n"),
204 CORBA::InterfaceDefSeq
in_bases (0);
207 CORBA::InterfaceDef_var iface
=
208 this->repo_
->create_interface ("IDL:dummy:1.0",
213 CORBA::PrimitiveDef_var p_long
=
214 this->repo_
->get_primitive (CORBA::pk_long
);
217 iface
->create_attribute ("IDL:dummt/attr:1.0",