00001 #include "ace_pch.h"
00002
00003
00004 #include "ace/Basic_Stats.h"
00005 #include "ace/Log_Msg.h"
00006
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/Basic_Stats.inl"
00009 #endif
00010
00011 ACE_RCSID(ace, Basic_Stats, "$Id: Basic_Stats.cpp,v 1.1.1.1.40.1 2003/03/13 19:44:20 chad Exp $")
00012
00013 void
00014 ACE_Basic_Stats::accumulate (const ACE_Basic_Stats &rhs)
00015 {
00016 if (rhs.samples_count_ == 0)
00017 return;
00018
00019 if (this->samples_count_ == 0)
00020 {
00021 this->samples_count_ = rhs.samples_count_;
00022
00023 this->min_ = rhs.min_;
00024 this->max_ = rhs.max_;
00025 this->sum_ = rhs.sum_;
00026 this->sum2_ = rhs.sum2_;
00027
00028 return;
00029 }
00030 this->samples_count_ += rhs.samples_count_;
00031
00032 if (this->min_ > rhs.min_)
00033 this->min_ = rhs.min_;
00034 if (this->max_ < rhs.max_)
00035 this->max_ = rhs.max_;
00036
00037 this->sum_ += rhs.sum_;
00038 this->sum2_ += rhs.sum2_;
00039 }
00040
00041 void
00042 ACE_Basic_Stats::dump_results (const ACE_TCHAR *msg,
00043 ACE_UINT32 sf) const
00044 {
00045 if (this->samples_count () == 0u)
00046 {
00047 ACE_DEBUG ((LM_DEBUG,
00048 ACE_LIB_TEXT ("%s : no data collected\n"), msg));
00049 return;
00050 }
00051
00052 ACE_UINT64 avg = this->sum_ / this->samples_count_;
00053 ACE_UINT64 dev =
00054 #if defined ACE_LACKS_LONGLONG_T
00055 ACE_static_cast (ACE_U_LongLong,
00056 this->sum2_ / this->samples_count_)
00057 - avg * ACE_U64_TO_U32(avg);
00058 #else
00059 this->sum2_ / this->samples_count_ - avg * avg;
00060 #endif
00061
00062 double l_min = ACE_CU64_TO_CU32 (this->min_) / sf;
00063 double l_max = ACE_CU64_TO_CU32 (this->max_) / sf;
00064 double l_avg = ACE_CU64_TO_CU32 (avg) / sf;
00065 double l_dev = ACE_CU64_TO_CU32 (dev) / (sf * sf);
00066
00067 ACE_DEBUG ((LM_DEBUG,
00068 ACE_LIB_TEXT ("%s latency : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n"),
00069 msg,
00070 l_min, this->min_at_,
00071 l_avg,
00072 l_max, this->max_at_,
00073 l_dev));
00074 }