15 #ifndef STXXL_IOSTATS_HEADER 16 #define STXXL_IOSTATS_HEADER 18 #ifndef STXXL_IO_STATS 19 #define STXXL_IO_STATS 1 25 #include <stxxl/bits/namespace.h> 26 #include <stxxl/bits/deprecated.h> 27 #include <stxxl/bits/common/mutex.h> 28 #include <stxxl/bits/common/timer.h> 29 #include <stxxl/bits/common/types.h> 30 #include <stxxl/bits/common/utils.h> 31 #include <stxxl/bits/unused.h> 32 #include <stxxl/bits/singleton.h> 35 __STXXL_BEGIN_NAMESPACE
43 class stats :
public singleton<stats>
45 friend class singleton<stats>;
47 unsigned reads, writes;
48 int64 volume_read, volume_written;
49 unsigned c_reads, c_writes;
50 int64 c_volume_read, c_volume_written;
51 double t_reads, t_writes;
52 double p_reads, p_writes;
53 double p_begin_read, p_begin_write;
56 double t_waits, p_waits;
58 double t_wait_read, p_wait_read;
59 double p_begin_wait_read;
60 double t_wait_write, p_wait_write;
61 double p_begin_wait_write;
62 int acc_reads, acc_writes;
65 int acc_wait_read, acc_wait_write;
67 mutex read_mutex, write_mutex, io_mutex, wait_mutex;
78 class scoped_read_write_timer
80 typedef unsigned_type size_type;
88 scoped_read_write_timer(size_type size,
bool is_write =
false)
97 ~scoped_read_write_timer()
102 void start(size_type size)
108 stats::get_instance()->write_started(size);
110 stats::get_instance()->read_started(size);
122 stats::get_instance()->write_finished();
124 stats::get_instance()->read_finished();
131 class scoped_write_timer
133 typedef unsigned_type size_type;
140 scoped_write_timer(size_type size)
148 ~scoped_write_timer()
153 void start(size_type size)
158 stats::get_instance()->write_started(size);
169 stats::get_instance()->write_finished();
176 class scoped_read_timer
178 typedef unsigned_type size_type;
185 scoped_read_timer(size_type size)
198 void start(size_type size)
203 stats::get_instance()->read_started(size);
214 stats::get_instance()->read_finished();
221 class scoped_wait_timer
223 #ifndef STXXL_DO_NOT_COUNT_WAIT_TIME 225 wait_op_type wait_op;
229 scoped_wait_timer(wait_op_type wait_op,
bool measure_time =
true)
230 #ifndef STXXL_DO_NOT_COUNT_WAIT_TIME 231 : running(
false), wait_op(wait_op)
245 #ifndef STXXL_DO_NOT_COUNT_WAIT_TIME 248 stats::get_instance()->wait_started(wait_op);
255 #ifndef STXXL_DO_NOT_COUNT_WAIT_TIME 257 stats::get_instance()->wait_finished(wait_op);
290 return volume_written;
311 return c_volume_read;
318 return c_volume_written;
366 double get_wait_read_time()
const 371 double get_wait_write_time()
const 383 #ifndef STXXL_IO_STATS_RESET_FORBIDDEN 392 void write_started(unsigned_type size_,
double now = 0.0);
393 void write_canceled(unsigned_type size_);
394 void write_finished();
395 void write_cached(unsigned_type size_);
396 void read_started(unsigned_type size_,
double now = 0.0);
397 void read_canceled(unsigned_type size_);
398 void read_finished();
399 void read_cached(unsigned_type size_);
400 void wait_started(wait_op_type wait_op);
401 void wait_finished(wait_op_type wait_op);
405 inline void stats::write_started(unsigned_type size_,
double now)
410 inline void stats::write_cached(unsigned_type size_)
414 inline void stats::write_finished() { }
415 inline void stats::read_started(unsigned_type size_,
double now)
420 inline void stats::read_cached(unsigned_type size_)
424 inline void stats::read_finished() { }
426 #ifdef STXXL_DO_NOT_COUNT_WAIT_TIME 427 inline void stats::wait_started(wait_op_type) { }
428 inline void stats::wait_finished(wait_op_type) { }
434 unsigned reads, writes;
435 int64 volume_read, volume_written;
436 unsigned c_reads, c_writes;
437 int64 c_volume_read, c_volume_written;
438 double t_reads, t_writes;
439 double p_reads, p_writes;
442 double t_wait_read, t_wait_write;
466 stats_data(
const stats & s) :
481 t_wait_read(s.get_wait_read_time()),
482 t_wait_write(s.get_wait_write_time()),
486 stats_data operator + (
const stats_data & a)
const 489 s.reads = reads + a.reads;
490 s.writes = writes + a.writes;
491 s.volume_read = volume_read + a.volume_read;
492 s.volume_written = volume_written + a.volume_written;
493 s.c_reads = c_reads + a.c_reads;
494 s.c_writes = c_writes + a.c_writes;
495 s.c_volume_read = c_volume_read + a.c_volume_read;
496 s.c_volume_written = c_volume_written + a.c_volume_written;
497 s.t_reads = t_reads + a.t_reads;
498 s.t_writes = t_writes + a.t_writes;
499 s.p_reads = p_reads + a.p_reads;
500 s.p_writes = p_writes + a.p_writes;
501 s.p_ios = p_ios + a.p_ios;
502 s.t_wait = t_wait + a.t_wait;
503 s.t_wait_read = t_wait_read + a.t_wait_read;
504 s.t_wait_write = t_wait_write + a.t_wait_write;
505 s.elapsed = elapsed + a.elapsed;
509 stats_data operator - (
const stats_data & a)
const 512 s.reads = reads - a.reads;
513 s.writes = writes - a.writes;
514 s.volume_read = volume_read - a.volume_read;
515 s.volume_written = volume_written - a.volume_written;
516 s.c_reads = c_reads - a.c_reads;
517 s.c_writes = c_writes - a.c_writes;
518 s.c_volume_read = c_volume_read - a.c_volume_read;
519 s.c_volume_written = c_volume_written - a.c_volume_written;
520 s.t_reads = t_reads - a.t_reads;
521 s.t_writes = t_writes - a.t_writes;
522 s.p_reads = p_reads - a.p_reads;
523 s.p_writes = p_writes - a.p_writes;
524 s.p_ios = p_ios - a.p_ios;
525 s.t_wait = t_wait - a.t_wait;
526 s.t_wait_read = t_wait_read - a.t_wait_read;
527 s.t_wait_write = t_wait_write - a.t_wait_write;
528 s.elapsed = elapsed - a.elapsed;
549 return volume_written;
564 return c_volume_read;
569 return c_volume_written;
597 double get_elapsed_time()
const 607 double get_wait_read_time()
const 612 double get_wait_write_time()
const 618 std::ostream & operator << (std::ostream & o,
const stats_data & s);
620 inline std::ostream & operator << (std::ostream & o,
const stats & s)
622 o << stxxl::stats_data(s);
626 std::string format_with_SI_IEC_unit_multiplier(uint64 number,
const char * unit =
"",
int multiplier = 1000);
628 inline std::string add_IEC_binary_multiplier(uint64 number,
const char * unit =
"")
630 return format_with_SI_IEC_unit_multiplier(number, unit, 1024);
633 inline std::string add_SI_multiplier(uint64 number,
const char * unit =
"")
635 return format_with_SI_IEC_unit_multiplier(number, unit, 1000);
640 __STXXL_END_NAMESPACE
642 #endif // !STXXL_IOSTATS_HEADER _STXXL_DEPRECATED(void reset())
Resets I/O time counters (including I/O wait counter)
double get_pread_time() const
Period of time when at least one I/O thread was executing a read.
Definition: iostats.h:337
double get_write_time() const
Time that would be spent in write syscalls if all parallel writes were serialized.
Definition: iostats.h:330
int64 get_written_volume() const
Returns number of bytes written to the disks.
Definition: iostats.h:288
double get_last_reset_time() const
Return time of the last reset.
Definition: iostats.h:378
int64 get_read_volume() const
Returns number of bytes read from disks.
Definition: iostats.h:281
double get_read_time() const
Time that would be spent in read syscalls if all parallel reads were serialized.
Definition: iostats.h:323
double get_io_wait_time() const
I/O wait time counter.
Definition: iostats.h:361
unsigned get_writes() const
Returns total number of writes.
Definition: iostats.h:274
int64 get_cached_written_volume() const
Returns number of bytes written to the cache.
Definition: iostats.h:316
double get_pio_time() const
Period of time when at least one I/O thread was executing a read or a write.
Definition: iostats.h:351
int64 get_cached_read_volume() const
Returns number of bytes read from cache.
Definition: iostats.h:309
Collects various I/O statistics.
Definition: iostats.h:43
double get_pwrite_time() const
Period of time when at least one I/O thread was executing a write.
Definition: iostats.h:344
unsigned get_cached_reads() const
Returns total number of reads served from cache.
Definition: iostats.h:295
unsigned get_cached_writes() const
Returns total number of cached writes.
Definition: iostats.h:302
unsigned get_reads() const
Returns total number of reads.
Definition: iostats.h:267