Throughput_Stats.cpp

Go to the documentation of this file.
00001 // $Id: Throughput_Stats.cpp 80826 2008-03-04 14:51:23Z wotte $
00002 
00003 #include "ace/Throughput_Stats.h"
00004 
00005 #include "ace/OS_NS_stdio.h"
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/High_Res_Timer.h"
00008 #include "ace/Log_Msg.h"
00009 
00010 ACE_RCSID(ace, Throughput_Stats, "$Id: Throughput_Stats.cpp 80826 2008-03-04 14:51:23Z wotte $")
00011 
00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00013 
00014 ACE_Throughput_Stats::ACE_Throughput_Stats (void)
00015   : ACE_Basic_Stats ()
00016   , throughput_last_ (0)
00017 #if 0
00018   // @@TODO: This is what I really wanted to compute, but it just
00019   // does not work.
00020   , throughput_sum_x_ (0)
00021   , throughput_sum_x2_ (0)
00022   , throughput_sum_y_ (0)
00023   , throughput_sum_y2_ (0)
00024   , throughput_sum_xy_ (0)
00025 #endif /* 0 */
00026 {
00027 }
00028 
00029 void
00030 ACE_Throughput_Stats::sample (ACE_UINT64 throughput,
00031                               ACE_UINT64 latency)
00032 {
00033   this->ACE_Basic_Stats::sample (latency);
00034 
00035   if (this->samples_count () == 1u)
00036     {
00037 
00038       this->throughput_last_   = throughput;
00039 #if 0
00040       // @@TODO: This is what I really wanted to compute, but it just
00041       // does not work.
00042       this->throughput_sum_y_  = this->samples_count_;
00043       this->throughput_sum_y2_ = this->samples_count_ * this->samples_count_;
00044       this->throughput_sum_x_  = throughput;
00045       this->throughput_sum_x2_ = throughput * throughput;
00046       this->throughput_sum_xy_ = throughput * this->samples_count_;
00047 
00048       ACE_OS::printf ("%f %qu\n", throughput / 400000000.0, this->samples_count_);
00049 #endif /* 0 */
00050     }
00051   else
00052     {
00053       this->throughput_last_ = throughput;
00054 
00055 #if 0
00056       // @@TODO: This is what I really wanted to compute, but it just
00057       // does not work.
00058       this->throughput_sum_y_  += this->samples_count_;
00059       this->throughput_sum_y2_ += this->samples_count_ * this->samples_count_;
00060       this->throughput_sum_x_  += throughput;
00061       this->throughput_sum_x2_ += throughput * throughput;
00062       this->throughput_sum_xy_ += throughput * this->samples_count_;
00063 
00064       ACE_OS::printf ("%f %qu\n", throughput / 400000000.0, this->samples_count_);
00065 #endif /* 0 */
00066     }
00067 }
00068 
00069 void
00070 ACE_Throughput_Stats::accumulate (const ACE_Throughput_Stats &rhs)
00071 {
00072   if (rhs.samples_count () == 0u)
00073     return;
00074 
00075   this->ACE_Basic_Stats::accumulate (rhs);
00076 
00077   if (this->samples_count () == 0u)
00078     {
00079       this->throughput_last_   = rhs.throughput_last_;
00080 #if 0
00081       // @@TODO: This is what I really wanted to compute, but it just
00082       // does not work.
00083       this->throughput_sum_x_  = rhs.throughput_sum_x_;
00084       this->throughput_sum_x2_ = rhs.throughput_sum_x2_;
00085       this->throughput_sum_y_  = rhs.throughput_sum_y_;
00086       this->throughput_sum_y2_ = rhs.throughput_sum_y2_;
00087       this->throughput_sum_xy_ = rhs.throughput_sum_xy_;
00088 #endif /* 0 */
00089 
00090       return;
00091     }
00092 
00093 
00094   if (this->throughput_last_ < rhs.throughput_last_)
00095     this->throughput_last_ = rhs.throughput_last_;
00096 
00097 #if 0
00098   // @@TODO: This is what I really wanted to compute, but it just
00099   // does not work.
00100   this->throughput_sum_x_  += rhs.throughput_sum_x_;
00101   this->throughput_sum_x2_ += rhs.throughput_sum_x2_;
00102   this->throughput_sum_y_  += rhs.throughput_sum_y_;
00103   this->throughput_sum_y2_ += rhs.throughput_sum_y2_;
00104   this->throughput_sum_xy_ += rhs.throughput_sum_xy_;
00105 #endif /* 0 */
00106 }
00107 
00108 void
00109 ACE_Throughput_Stats::dump_results (const ACE_TCHAR* msg,
00110                                     ACE_UINT32 sf)
00111 {
00112   if (this->samples_count () == 0u)
00113     {
00114       ACE_DEBUG ((LM_DEBUG,
00115                   ACE_TEXT ("%s : no data collected\n"), msg));
00116       return;
00117     }
00118 
00119   this->ACE_Basic_Stats::dump_results (msg, sf);
00120 
00121   ACE_Throughput_Stats::dump_throughput (msg, sf,
00122                                          this->throughput_last_,
00123                                          this->samples_count ());
00124 
00125 #if 0
00126   // @@TODO: This is what I really wanted to generate, but it just
00127   // doesn't work.
00128   double t_sum_x =
00129     ACE_CU64_TO_CU32 (this->throughput_sum_x_);// / sf);
00130   //t_sum_x /= 1000000.0;
00131   double t_sum_y =
00132     ACE_CU64_TO_CU32 (this->throughput_sum_y_);
00133   double t_sum_x2 =
00134     ACE_CU64_TO_CU32 (this->throughput_sum_x2_);// / (sf*sf));
00135   //t_sum_x2 /= 1000000.0;
00136   //t_sum_x2 /= 1000000.0;
00137   double t_sum_y2 =
00138     ACE_CU64_TO_CU32 (this->throughput_sum_y2_);
00139   double t_sum_xy =
00140     ACE_CU64_TO_CU32 (this->throughput_sum_xy_);// / sf);
00141   //t_sum_xy /= 1000000.0;
00142   double t_avgx = t_sum_x / this->samples_count ();
00143   double t_avgy = t_sum_y / this->samples_count ();
00144 
00145   double t_a =
00146     (this->samples_count () * t_sum_xy - t_sum_x * t_sum_y)
00147     / (this->samples_count () * t_sum_x2 - t_sum_x * t_sum_x);
00148   double t_b = (t_avgy - t_a * t_avgx);
00149 
00150   t_a *= 1000000.0;
00151 
00152   double d_r =
00153     (t_sum_xy - t_avgx * t_sum_y - t_avgy * t_sum_x
00154      + this->samples_count () * t_avgx * t_avgy);
00155   double n_r =
00156     (t_sum_x2
00157      - this->samples_count () * t_avgx * t_avgx)
00158     * (t_sum_y2
00159        - this->samples_count () * t_avgy * t_avgy);
00160   double t_r = d_r * d_r / n_r;
00161 
00162   //  ACE_DEBUG ((LM_DEBUG,
00163   //              "%s throughput: %.2f/%.2f/%.2f/%.6f/%.2f (avg/a/b/r/elapsed)\n",
00164   //              msg, t_avg, t_a, t_b, t_r, seconds));
00165   //  ACE_DEBUG ((LM_DEBUG,
00166   //              "%s        data: %.2f/%.2f/%.2f/%.6f/%.2f (x/x2/y/y2/xy)\n",
00167   //              msg, t_sum_x, t_sum_x2, t_sum_y, t_sum_y2, t_sum_xy));
00168 #endif
00169 }
00170 
00171 void
00172 ACE_Throughput_Stats::dump_throughput (const ACE_TCHAR *msg,
00173                                        ACE_UINT32 sf,
00174                                        ACE_UINT64 elapsed_time,
00175                                        ACE_UINT32 samples_count)
00176 {
00177 #ifndef ACE_NLOGGING
00178   double seconds =
00179 # if defined ACE_LACKS_LONGLONG_T
00180     elapsed_time / sf;
00181 #elif  defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00182     static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (
00183                            ACE_U_LongLong(elapsed_time / sf)));
00184 # else  /* ! ACE_LACKS_LONGLONG_T */
00185     static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / sf));
00186 # endif /* ! ACE_LACKS_LONGLONG_T */
00187   seconds /= ACE_HR_SCALE_CONVERSION;
00188 
00189   const double t_avg = samples_count / seconds;
00190 
00191   ACE_DEBUG ((LM_DEBUG,
00192               ACE_TEXT ("%s throughput: %.2f (events/second)\n"),
00193               msg, t_avg));
00194 #else
00195   ACE_UNUSED_ARG (msg);
00196   ACE_UNUSED_ARG (sf);
00197   ACE_UNUSED_ARG (elapsed_time);
00198   ACE_UNUSED_ARG (samples_count);
00199 #endif /* ACE_NLOGGING */
00200 }
00201 
00202 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:43 2010 for ACE by  doxygen 1.4.7