[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Throughput_Stats.cpp
blob6e667299729866512618ae4b9652a419bc3633bd
1 // $Id: Throughput_Stats.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/Throughput_Stats.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/High_Res_Timer.h"
8 #include "ace/Log_Msg.h"
10 ACE_RCSID(ace, Throughput_Stats, "$Id: Throughput_Stats.cpp 80826 2008-03-04 14:51:23Z wotte $")
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_Throughput_Stats::ACE_Throughput_Stats (void)
15 : ACE_Basic_Stats ()
16 , throughput_last_ (0)
17 #if 0
18 // @@TODO: This is what I really wanted to compute, but it just
19 // does not work.
20 , throughput_sum_x_ (0)
21 , throughput_sum_x2_ (0)
22 , throughput_sum_y_ (0)
23 , throughput_sum_y2_ (0)
24 , throughput_sum_xy_ (0)
25 #endif /* 0 */
29 void
30 ACE_Throughput_Stats::sample (ACE_UINT64 throughput,
31 ACE_UINT64 latency)
33 this->ACE_Basic_Stats::sample (latency);
35 if (this->samples_count () == 1u)
38 this->throughput_last_ = throughput;
39 #if 0
40 // @@TODO: This is what I really wanted to compute, but it just
41 // does not work.
42 this->throughput_sum_y_ = this->samples_count_;
43 this->throughput_sum_y2_ = this->samples_count_ * this->samples_count_;
44 this->throughput_sum_x_ = throughput;
45 this->throughput_sum_x2_ = throughput * throughput;
46 this->throughput_sum_xy_ = throughput * this->samples_count_;
48 ACE_OS::printf ("%f %qu\n", throughput / 400000000.0, this->samples_count_);
49 #endif /* 0 */
51 else
53 this->throughput_last_ = throughput;
55 #if 0
56 // @@TODO: This is what I really wanted to compute, but it just
57 // does not work.
58 this->throughput_sum_y_ += this->samples_count_;
59 this->throughput_sum_y2_ += this->samples_count_ * this->samples_count_;
60 this->throughput_sum_x_ += throughput;
61 this->throughput_sum_x2_ += throughput * throughput;
62 this->throughput_sum_xy_ += throughput * this->samples_count_;
64 ACE_OS::printf ("%f %qu\n", throughput / 400000000.0, this->samples_count_);
65 #endif /* 0 */
69 void
70 ACE_Throughput_Stats::accumulate (const ACE_Throughput_Stats &rhs)
72 if (rhs.samples_count () == 0u)
73 return;
75 this->ACE_Basic_Stats::accumulate (rhs);
77 if (this->samples_count () == 0u)
79 this->throughput_last_ = rhs.throughput_last_;
80 #if 0
81 // @@TODO: This is what I really wanted to compute, but it just
82 // does not work.
83 this->throughput_sum_x_ = rhs.throughput_sum_x_;
84 this->throughput_sum_x2_ = rhs.throughput_sum_x2_;
85 this->throughput_sum_y_ = rhs.throughput_sum_y_;
86 this->throughput_sum_y2_ = rhs.throughput_sum_y2_;
87 this->throughput_sum_xy_ = rhs.throughput_sum_xy_;
88 #endif /* 0 */
90 return;
94 if (this->throughput_last_ < rhs.throughput_last_)
95 this->throughput_last_ = rhs.throughput_last_;
97 #if 0
98 // @@TODO: This is what I really wanted to compute, but it just
99 // does not work.
100 this->throughput_sum_x_ += rhs.throughput_sum_x_;
101 this->throughput_sum_x2_ += rhs.throughput_sum_x2_;
102 this->throughput_sum_y_ += rhs.throughput_sum_y_;
103 this->throughput_sum_y2_ += rhs.throughput_sum_y2_;
104 this->throughput_sum_xy_ += rhs.throughput_sum_xy_;
105 #endif /* 0 */
108 void
109 ACE_Throughput_Stats::dump_results (const ACE_TCHAR* msg,
110 ACE_UINT32 sf)
112 if (this->samples_count () == 0u)
114 ACE_DEBUG ((LM_DEBUG,
115 ACE_TEXT ("%s : no data collected\n"), msg));
116 return;
119 this->ACE_Basic_Stats::dump_results (msg, sf);
121 ACE_Throughput_Stats::dump_throughput (msg, sf,
122 this->throughput_last_,
123 this->samples_count ());
125 #if 0
126 // @@TODO: This is what I really wanted to generate, but it just
127 // doesn't work.
128 double t_sum_x =
129 ACE_CU64_TO_CU32 (this->throughput_sum_x_);// / sf);
130 //t_sum_x /= 1000000.0;
131 double t_sum_y =
132 ACE_CU64_TO_CU32 (this->throughput_sum_y_);
133 double t_sum_x2 =
134 ACE_CU64_TO_CU32 (this->throughput_sum_x2_);// / (sf*sf));
135 //t_sum_x2 /= 1000000.0;
136 //t_sum_x2 /= 1000000.0;
137 double t_sum_y2 =
138 ACE_CU64_TO_CU32 (this->throughput_sum_y2_);
139 double t_sum_xy =
140 ACE_CU64_TO_CU32 (this->throughput_sum_xy_);// / sf);
141 //t_sum_xy /= 1000000.0;
142 double t_avgx = t_sum_x / this->samples_count ();
143 double t_avgy = t_sum_y / this->samples_count ();
145 double t_a =
146 (this->samples_count () * t_sum_xy - t_sum_x * t_sum_y)
147 / (this->samples_count () * t_sum_x2 - t_sum_x * t_sum_x);
148 double t_b = (t_avgy - t_a * t_avgx);
150 t_a *= 1000000.0;
152 double d_r =
153 (t_sum_xy - t_avgx * t_sum_y - t_avgy * t_sum_x
154 + this->samples_count () * t_avgx * t_avgy);
155 double n_r =
156 (t_sum_x2
157 - this->samples_count () * t_avgx * t_avgx)
158 * (t_sum_y2
159 - this->samples_count () * t_avgy * t_avgy);
160 double t_r = d_r * d_r / n_r;
162 // ACE_DEBUG ((LM_DEBUG,
163 // "%s throughput: %.2f/%.2f/%.2f/%.6f/%.2f (avg/a/b/r/elapsed)\n",
164 // msg, t_avg, t_a, t_b, t_r, seconds));
165 // ACE_DEBUG ((LM_DEBUG,
166 // "%s data: %.2f/%.2f/%.2f/%.6f/%.2f (x/x2/y/y2/xy)\n",
167 // msg, t_sum_x, t_sum_x2, t_sum_y, t_sum_y2, t_sum_xy));
168 #endif
171 void
172 ACE_Throughput_Stats::dump_throughput (const ACE_TCHAR *msg,
173 ACE_UINT32 sf,
174 ACE_UINT64 elapsed_time,
175 ACE_UINT32 samples_count)
177 #ifndef ACE_NLOGGING
178 double seconds =
179 # if defined ACE_LACKS_LONGLONG_T
180 elapsed_time / sf;
181 #elif defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
182 static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (
183 ACE_U_LongLong(elapsed_time / sf)));
184 # else /* ! ACE_LACKS_LONGLONG_T */
185 static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / sf));
186 # endif /* ! ACE_LACKS_LONGLONG_T */
187 seconds /= ACE_HR_SCALE_CONVERSION;
189 const double t_avg = samples_count / seconds;
191 ACE_DEBUG ((LM_DEBUG,
192 ACE_TEXT ("%s throughput: %.2f (events/second)\n"),
193 msg, t_avg));
194 #else
195 ACE_UNUSED_ARG (msg);
196 ACE_UNUSED_ARG (sf);
197 ACE_UNUSED_ARG (elapsed_time);
198 ACE_UNUSED_ARG (samples_count);
199 #endif /* ACE_NLOGGING */
202 ACE_END_VERSIONED_NAMESPACE_DECL