TPIE

11a2c2d
stats.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008, 2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
23 
24 #ifndef _TPIE_STATS_H
25 #define _TPIE_STATS_H
26 
27 #include <tpie/tpie_export.h>
28 #include <tpie/types.h>
29 #include <chrono>
30 
31 namespace tpie {
32 
36  TPIE_EXPORT stream_size_type get_temp_file_usage();
37 
42  TPIE_EXPORT void increment_temp_file_usage(stream_offset_type delta);
43 
47  TPIE_EXPORT stream_size_type get_bytes_read();
48 
52  TPIE_EXPORT stream_size_type get_bytes_written();
53 
58  TPIE_EXPORT void increment_bytes_read(stream_size_type delta);
59 
64  TPIE_EXPORT void increment_bytes_written(stream_size_type delta);
65 
66  TPIE_EXPORT stream_size_type get_user(size_t i);
67  TPIE_EXPORT void increment_user(size_t i, stream_size_type delta);
68 
69 class ptime {
70 private:
71  typedef std::chrono::steady_clock clock;
72  typedef std::chrono::time_point<clock> time_point;
73 public:
74  ptime() {}
75 
76  static ptime now() {return clock::now();}
77 
78  static double seconds(const ptime & t1, const ptime & t2) {
79  return std::chrono::duration_cast<std::chrono::duration<double>>(
80  t2.m_ptime - t1.m_ptime).count();
81  }
82 
83 private:
84  time_point m_ptime;
85 
86  ptime(time_point ptime): m_ptime(ptime) {}
87 };
88 
89 class stat_timer {
90 public:
91  stat_timer(size_t i)
92  : i(i)
93  , t1(ptime::now())
94  {
95  }
96 
97  ~stat_timer() {
98  ptime t2 = ptime::now();
99  increment_user(i, (stream_size_type)(ptime::seconds(t1, t2)*1000000));
100  }
101 
102 private:
103  size_t i;
104  ptime t1;
105 };
106 
107 } // tpie namespace
108 #endif //_TPIE_STATS_H
tpie::ptime
Definition: stats.h:69
types.h
tpie::get_bytes_read
TPIE_EXPORT stream_size_type get_bytes_read()
Return the number of bytes read from disk since program start.
tpie::get_bytes_written
TPIE_EXPORT stream_size_type get_bytes_written()
Return the number of bytes written to disk since program start.
tpie::increment_temp_file_usage
TPIE_EXPORT void increment_temp_file_usage(stream_offset_type delta)
Increment (possibly by a negative amount) the number of bytes being used by temporary files.
tpie::stat_timer
Definition: stats.h:89
tpie::get_temp_file_usage
TPIE_EXPORT stream_size_type get_temp_file_usage()
Return the number of bytes currently being used by temporary files.
tpie::increment_bytes_written
TPIE_EXPORT void increment_bytes_written(stream_size_type delta)
Inform the stats module that an additional delta bytes have been written to disk.
tpie::increment_bytes_read
TPIE_EXPORT void increment_bytes_read(stream_size_type delta)
Inform that stats module that an additional delta bytes have been read from disk.
tpie
Definition: access_type.h:26