TPIE
11a2c2d
cpu_timer.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
20
#ifndef _TPIE_CPU_TIMER_H
21
#define _TPIE_CPU_TIMER_H
22
27
28
#include <tpie/tpie_export.h>
29
// Get definitions for working with Unix and Windows
30
#include <
tpie/portability.h
>
31
#include <iostream>
32
#include <time.h>
33
#include <boost/date_time.hpp>
34
#ifndef _WIN32
35
#include <sys/times.h>
36
#include <sys/resource.h>
37
#endif
38
39
namespace
tpie
{
40
47
#ifdef _WIN32
48
typedef
boost::posix_time::ptime tms;
49
#else
50
using ::tms;
51
#endif
52
class
TPIE_EXPORT
cpu_timer
{
53
54
private
:
55
long
clock_tick_;
56
57
tms last_sync_;
58
tms elapsed_;
59
60
clock_t last_sync_real_;
61
clock_t elapsed_real_;
62
63
bool
running_;
64
65
inline
void
set_clock_tick();
66
inline
void
last_sync_real_declaration();
67
68
public
:
69
cpu_timer
();
70
74
void
start();
75
79
void
stop();
80
85
void
sync();
86
90
void
reset();
91
99
double
user_time();
100
108
double
system_time();
109
114
double
wall_time();
115
119
inline
bool
running
()
const
{
120
return
running_;
121
}
122
126
inline
long
clock_tick
()
const
{
127
return
clock_tick_;
128
}
129
133
inline
tms
last_sync
()
const
{
134
return
last_sync_;
135
}
136
140
inline
tms
elapsed
()
const
{
141
return
elapsed_;
142
}
143
147
inline
clock_t
last_sync_real
()
const
{
148
return
last_sync_real_;
149
}
150
154
inline
clock_t
elapsed_real
()
const
{
155
return
elapsed_real_;
156
}
157
158
};
159
165
TPIE_EXPORT std::ostream &operator<<(std::ostream &s, cpu_timer &ct);
166
167
}
168
169
#endif // _TPIE_CPU_TIMER_H
tpie::cpu_timer::elapsed
tms elapsed() const
Return the timestamp indicating the elapsed time. Only useful on Linux.
Definition:
cpu_timer.h:140
portability.h
tpie::cpu_timer::running
bool running() const
Tell whether the timer is currently running.
Definition:
cpu_timer.h:119
tpie::cpu_timer::last_sync
tms last_sync() const
Return the timestamp of last sync.
Definition:
cpu_timer.h:133
tpie::cpu_timer::clock_tick
long clock_tick() const
Return number of ticks per wall clock second as reported by the OS.
Definition:
cpu_timer.h:126
tpie::cpu_timer::elapsed_real
clock_t elapsed_real() const
Return the elapsed wall clock time at the last sync.
Definition:
cpu_timer.h:154
tpie::cpu_timer
Definition:
cpu_timer.h:52
tpie::cpu_timer::last_sync_real
clock_t last_sync_real() const
Return the wall clock timestamp of the last sync.
Definition:
cpu_timer.h:147
tpie
Definition:
access_type.h:26
from TPIE 11a2c2d (
browse source
). Generated on Tue Jun 8 2021 12:44:17 by
Doxygen
1.8.17