Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / performance-tests / Throughput / Receiver.cpp
blob065ca312c5883e6aa46901f4c889fadbaacccaf9
2 #include "Receiver.h"
3 #include "ace/High_Res_Timer.h"
5 Receiver::Receiver ()
6 : start_time_ (0)
7 , message_count_ (0)
8 , byte_count_ (0)
9 , last_message_time_ (0)
10 , last_message_id_ (0)
14 void
15 Receiver::receive_data (const Test::Message &the_message)
17 ACE_hrtime_t now = ACE_OS::gethrtime ();
18 if (this->message_count_ == 0)
20 this->start_time_ = now;
22 else
24 if (this->last_message_id_ > the_message.message_id)
26 ACE_ERROR ((LM_ERROR,
27 "ERROR: (%P|%t) Receiver::receive_data, "
28 "message out of sequence %d / %d\n",
29 the_message.message_id,
30 this->last_message_id_));
31 return;
33 this->last_message_id_ = the_message.message_id;
35 ++this->message_count_;
36 this->byte_count_ += the_message.the_payload.length ();
37 this->last_message_time_ = now;
40 void
41 Receiver::done ()
43 if (this->message_count_ == 0)
45 ACE_ERROR ((LM_ERROR,
46 "ERROR: (%P|%t) Receiver::done, "
47 "no messages received\n"));
49 else
51 ACE_High_Res_Timer::global_scale_factor_type gsf =
52 ACE_High_Res_Timer::global_scale_factor ();
54 ACE_hrtime_t elapsed_time =
55 this->last_message_time_ - this->start_time_;
57 // convert to microseconds
58 ACE_UINT32 usecs = ACE_UINT32(elapsed_time / gsf);
60 if (usecs != 0)
62 double bytes =
63 (1000000.0 * this->byte_count_) / usecs;
64 double kbytes = bytes / 1024;
65 double mbytes = kbytes / 1024;
66 double mbits = bytes * 8 / 1000000;
68 ACE_DEBUG ((LM_DEBUG,
69 "Receiver %f (bytes/sec), %f (Kb/sec)\n"
70 "Receiver %f (Mb/sec), %f Mbits\n",
71 bytes, kbytes,
72 mbytes, mbits));
76 try
78 PortableServer::POA_var poa = this->_default_POA ();
79 PortableServer::ObjectId_var oid =
80 poa->servant_to_id (this);
81 poa->deactivate_object (oid.in ());
83 catch (const CORBA::Exception&){}