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 (void)
14 iterations_ (DEFAULT_NUMCALLS
)
18 Latency_Query_Client::~Latency_Query_Client (void)
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"
51 CORBA::Repository::_narrow (object
.in ());
53 if (CORBA::is_nil (this->repo_
.in ()))
55 ACE_ERROR_RETURN ((LM_ERROR
,
56 "CORBA::Repository::_narrow failed\n"),
60 retval
= this->populate_ifr ();
67 catch (const CORBA::Exception
& ex
)
69 ex
._tao_print_exception ("Latency_Query_Client::init:");
77 Latency_Query_Client::run (void)
79 // CORBA::DefinitionKind dk;
80 CORBA::AttributeMode am
;
84 for (int j
= 0; j
< 100; ++j
)
86 am
= this->attr_
->mode ();
88 if (am
!= CORBA::ATTR_NORMAL
)
94 ACE_Sample_History
history (this->iterations_
);
95 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
97 for (CORBA::ULong i
= 0; i
< this->iterations_
; ++i
)
99 ACE_hrtime_t start
= ACE_OS::gethrtime ();
101 am
= this->attr_
->mode ();
103 ACE_hrtime_t now
= ACE_OS::gethrtime ();
104 history
.sample (now
- start
);
107 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
111 ACE_DEBUG ((LM_DEBUG
,
113 ACE_DEBUG ((LM_DEBUG
,
114 "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
,
120 if (this->do_dump_history_
)
122 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
125 ACE_Basic_Stats stats
;
126 history
.collect_basic_stats (stats
);
127 stats
.dump_results (ACE_TEXT("Total"), gsf
);
129 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
131 test_end
- test_start
,
132 stats
.samples_count ());
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Latency_Query_Client::run:");
145 Latency_Query_Client::parse_args (int argc
,
148 ACE_Get_Opt
opts (argc
, argv
, ACE_TEXT("dhi:"));
152 while ((c
= opts ()) != -1)
160 this->do_dump_history_
= true;
163 result
= ACE_OS::atoi (opts
.opt_arg ());
167 this->iterations_
= result
;
173 ACE_ERROR_RETURN ((LM_ERROR
,
187 Latency_Query_Client::populate_ifr (void)
189 CORBA::Contained_var irobj
= this->repo_
->lookup_id ("IDL:dummy/attr:1.0");
191 if (! CORBA::is_nil (irobj
.in ()))
193 this->attr_
= CORBA::AttributeDef::_narrow (irobj
.in ());
195 if (CORBA::is_nil (this->attr_
.in ()))
197 ACE_ERROR_RETURN ((LM_ERROR
,
198 "Latency_Query_Client::populate_ifr - "
199 "AttributeDef::_narrow returned null\n"),
206 CORBA::InterfaceDefSeq
in_bases (0);
209 CORBA::InterfaceDef_var iface
=
210 this->repo_
->create_interface ("IDL:dummy:1.0",
215 CORBA::PrimitiveDef_var p_long
=
216 this->repo_
->get_primitive (CORBA::pk_long
);
219 iface
->create_attribute ("IDL:dummt/attr:1.0",