00001
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 79636 2007-09-13 15:18:33Z sowayaa $")
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
00019
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
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
00041
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
00050 }
00051 else
00052 {
00053 this->throughput_last_ = throughput;
00054
00055 #if 0
00056
00057
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
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
00082
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
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
00099
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
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
00127
00128 double t_sum_x =
00129 ACE_CU64_TO_CU32 (this->throughput_sum_x_);
00130
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_);
00135
00136
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_);
00141
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
00163
00164
00165
00166
00167
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
00185 static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / sf));
00186 # endif
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
00200 }
00201
00202 ACE_END_VERSIONED_NAMESPACE_DECL