00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef STXXL_IOSTATS_HEADER
00015 #define STXXL_IOSTATS_HEADER
00016
00017 #include <iostream>
00018
00019 #include <stxxl/bits/namespace.h>
00020 #include <stxxl/bits/common/mutex.h>
00021 #include <stxxl/bits/common/types.h>
00022 #include <stxxl/bits/common/utils.h>
00023 #include <stxxl/bits/noncopyable.h>
00024
00025
00026 __STXXL_BEGIN_NAMESPACE
00027
00031
00032 #ifdef COUNT_WAIT_TIME
00033 extern double wait_time_counter;
00034 #endif
00035
00038 class stats : private noncopyable
00039 {
00040 unsigned reads, writes;
00041 int64 volume_read, volume_written;
00042 double t_reads, t_writes;
00043 double p_reads, p_writes;
00044 double p_begin_read, p_begin_write;
00045 double p_ios;
00046 double p_begin_io;
00047 int acc_ios;
00048 int acc_reads, acc_writes;
00049 double last_reset;
00050 #ifdef STXXL_BOOST_THREADS
00051 boost::mutex read_mutex, write_mutex, io_mutex;
00052 #else
00053 mutex read_mutex, write_mutex, io_mutex;
00054 #endif
00055
00056 static stats * instance;
00057
00058 stats();
00059
00060 public:
00063 static stats * get_instance()
00064 {
00065 if (!instance)
00066 instance = new stats();
00067
00068 return instance;
00069 }
00070
00073 unsigned get_reads() const
00074 {
00075 return reads;
00076 }
00077
00080 unsigned get_writes() const
00081 {
00082 return writes;
00083 }
00084
00087 int64 get_read_volume() const
00088 {
00089 return volume_read;
00090 }
00091
00094 int64 get_written_volume() const
00095 {
00096 return volume_written;
00097 }
00098
00101 double get_read_time() const
00102 {
00103 return t_reads;
00104 }
00105
00108 double get_write_time() const
00109 {
00110 return t_writes;
00111 }
00112
00115 double get_pread_time() const
00116 {
00117 return p_reads;
00118 }
00119
00122 double get_pwrite_time() const
00123 {
00124 return p_writes;
00125 }
00126
00129 double get_pio_time() const
00130 {
00131 return p_ios;
00132 }
00133
00136 double get_last_reset_time() const
00137 {
00138 return last_reset;
00139 }
00140
00142 void reset();
00143
00145 void _reset_io_wait_time();
00152 double get_io_wait_time() const;
00156 double increment_io_wait_time(double val);
00157
00158
00159 void write_started(unsigned size_);
00160 void write_finished();
00161 void read_started(unsigned size_);
00162 void read_finished();
00163 };
00164
00165
00166 class stats_data
00167 {
00168 unsigned reads, writes;
00169 int64 volume_read, volume_written;
00170 double t_reads, t_writes;
00171 double p_reads, p_writes;
00172 double p_ios;
00173 double t_wait;
00174 double elapsed;
00175
00176 public:
00177 stats_data() :
00178 reads(0),
00179 writes(0),
00180 volume_read(0),
00181 volume_written(0),
00182 t_reads(0.0),
00183 t_writes(0.0),
00184 p_reads(0.0),
00185 p_writes(0.0),
00186 p_ios(0.0),
00187 t_wait(0.0),
00188 elapsed(0.0)
00189 { }
00190
00191 stats_data(const stats & s) :
00192 reads(s.get_reads()),
00193 writes(s.get_writes()),
00194 volume_read(s.get_read_volume()),
00195 volume_written(s.get_written_volume()),
00196 t_reads(s.get_read_time()),
00197 t_writes(s.get_write_time()),
00198 p_reads(s.get_pread_time()),
00199 p_writes(s.get_pwrite_time()),
00200 p_ios(s.get_pio_time()),
00201 t_wait(s.get_io_wait_time()),
00202 elapsed(stxxl_timestamp() - s.get_last_reset_time())
00203 { }
00204
00205 stats_data operator + (const stats_data & a) const
00206 {
00207 stats_data s;
00208 s.reads = reads + a.reads;
00209 s.writes = writes + a.writes;
00210 s.volume_read = volume_read + a.volume_read;
00211 s.volume_written = volume_written + a.volume_written;
00212 s.t_reads = t_reads + a.t_reads;
00213 s.t_writes = t_writes + a.t_writes;
00214 s.p_reads = p_reads + a.p_reads;
00215 s.p_writes = p_writes + a.p_writes;
00216 s.p_ios = p_ios + a.p_ios;
00217 s.t_wait = t_wait + a.t_wait;
00218 s.elapsed = elapsed + a.elapsed;
00219 return s;
00220 }
00221
00222 stats_data operator - (const stats_data & a) const
00223 {
00224 stats_data s;
00225 s.reads = reads - a.reads;
00226 s.writes = writes - a.writes;
00227 s.volume_read = volume_read - a.volume_read;
00228 s.volume_written = volume_written - a.volume_written;
00229 s.t_reads = t_reads - a.t_reads;
00230 s.t_writes = t_writes - a.t_writes;
00231 s.p_reads = p_reads - a.p_reads;
00232 s.p_writes = p_writes - a.p_writes;
00233 s.p_ios = p_ios - a.p_ios;
00234 s.t_wait = t_wait - a.t_wait;
00235 s.elapsed = elapsed - a.elapsed;
00236 return s;
00237 }
00238
00239 unsigned get_reads() const
00240 {
00241 return reads;
00242 }
00243
00244 unsigned get_writes() const
00245 {
00246 return writes;
00247 }
00248
00249 int64 get_read_volume() const
00250 {
00251 return volume_read;
00252 }
00253
00254 int64 get_written_volume() const
00255 {
00256 return volume_written;
00257 }
00258
00259 double get_read_time() const
00260 {
00261 return t_reads;
00262 }
00263
00264 double get_write_time() const
00265 {
00266 return t_writes;
00267 }
00268
00269 double get_pread_time() const
00270 {
00271 return p_reads;
00272 }
00273
00274 double get_pwrite_time() const
00275 {
00276 return p_writes;
00277 }
00278
00279 double get_pio_time() const
00280 {
00281 return p_ios;
00282 }
00283
00284 double get_elapsed_time() const
00285 {
00286 return elapsed;
00287 }
00288
00289 double get_io_wait_time() const
00290 {
00291 return t_wait;
00292 }
00293 };
00294
00295 std::ostream & operator << (std::ostream & o, const stats_data & s);
00296
00297 inline std::ostream & operator << (std::ostream & o, const stats & s)
00298 {
00299 o << stxxl::stats_data(s);
00300 return o;
00301 }
00302
00304
00305 __STXXL_END_NAMESPACE
00306
00307 #endif // !STXXL_IOSTATS_HEADER
00308