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)
16 , throughput_last_ (0)
18 // @@TODO: This is what I really wanted to compute, but it just
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)
30 ACE_Throughput_Stats::sample (ACE_UINT64 throughput
,
33 this->ACE_Basic_Stats::sample (latency
);
35 if (this->samples_count () == 1u)
38 this->throughput_last_
= throughput
;
40 // @@TODO: This is what I really wanted to compute, but it just
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_
);
53 this->throughput_last_
= throughput
;
56 // @@TODO: This is what I really wanted to compute, but it just
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_
);
70 ACE_Throughput_Stats::accumulate (const ACE_Throughput_Stats
&rhs
)
72 if (rhs
.samples_count () == 0u)
75 this->ACE_Basic_Stats::accumulate (rhs
);
77 if (this->samples_count () == 0u)
79 this->throughput_last_
= rhs
.throughput_last_
;
81 // @@TODO: This is what I really wanted to compute, but it just
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_
;
94 if (this->throughput_last_
< rhs
.throughput_last_
)
95 this->throughput_last_
= rhs
.throughput_last_
;
98 // @@TODO: This is what I really wanted to compute, but it just
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_
;
109 ACE_Throughput_Stats::dump_results (const ACE_TCHAR
* msg
,
112 if (this->samples_count () == 0u)
114 ACE_DEBUG ((LM_DEBUG
,
115 ACE_TEXT ("%s : no data collected\n"), msg
));
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 ());
126 // @@TODO: This is what I really wanted to generate, but it just
129 ACE_CU64_TO_CU32 (this->throughput_sum_x_
);// / sf);
130 //t_sum_x /= 1000000.0;
132 ACE_CU64_TO_CU32 (this->throughput_sum_y_
);
134 ACE_CU64_TO_CU32 (this->throughput_sum_x2_
);// / (sf*sf));
135 //t_sum_x2 /= 1000000.0;
136 //t_sum_x2 /= 1000000.0;
138 ACE_CU64_TO_CU32 (this->throughput_sum_y2_
);
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 ();
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
);
153 (t_sum_xy
- t_avgx
* t_sum_y
- t_avgy
* t_sum_x
154 + this->samples_count () * t_avgx
* t_avgy
);
157 - this->samples_count () * t_avgx
* t_avgx
)
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));
172 ACE_Throughput_Stats::dump_throughput (const ACE_TCHAR
*msg
,
174 ACE_UINT64 elapsed_time
,
175 ACE_UINT32 samples_count
)
179 # if defined ACE_LACKS_LONGLONG_T
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"),
195 ACE_UNUSED_ARG (msg
);
197 ACE_UNUSED_ARG (elapsed_time
);
198 ACE_UNUSED_ARG (samples_count
);
199 #endif /* ACE_NLOGGING */
202 ACE_END_VERSIONED_NAMESPACE_DECL