Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
Clock.cpp
Go to the documentation of this file.
1
static
const
char
rcsid
[] =
"$Id$"
;
2
3
/*
4
* See the COPYING file for the terms of usage and distribution.
5
*/
6
7
#include <cstdlib>
8
#include <sys/time.h>
// for struct timeval
9
#ifdef __osf__
10
# include <machine/builtins.h>
// for __RPCC()
11
#elif __linux__ && __i386__
12
# define rdtscl(low) \
13
__asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
14
#endif
15
#include <iostream>
16
17
#include "
Clock.hh
"
18
19
namespace
20
{
21
const
usec_t
UsecPerSec =
INT64_CONSTANT
(1000000);
22
}
23
24
bool
Clock::UsingCPU
= std::getenv(
"CLOCK_USE_CPU"
) ?
true
:
false
;
25
26
// -----------------------------------------------------------------------------
27
usec_t
Clock::time
(
void
)
28
{
29
if
(
UsingCPU
) {
30
static
bool
warn =
true
;
31
32
if
(warn) {
33
std::cout <<
"Using CPU clock."
<< std::endl;
34
warn =
false
;
35
}
36
37
#ifdef __osf__
38
return
(
usec_t
) __RPCC();
39
#elif __linux__ && __i386__
40
{
41
unsigned
long
tsc;
42
43
rdtscl(tsc);
44
return
(
usec_t
) tsc;
45
}
46
#else
47
{
48
std::cerr <<
"CPU clock not implemented for this architecture"
<< std::endl;
49
UsingCPU
=
false
;
50
return
Clock::time
();
51
}
52
#endif
53
}
else
{
54
struct
timeval tv;
55
56
gettimeofday(&tv, NULL);
57
return
(
usec_t
) (tv.tv_sec * UsecPerSec + tv.tv_usec);
58
}
59
}
60
61
// -----------------------------------------------------------------------------
62
Clock::Clock
(
void
)
63
:
_start
(0),
64
_elapsed
(0),
65
_active
(false)
66
{
67
start
();
68
}
69
70
// -----------------------------------------------------------------------------
71
Clock::~Clock
(
void
)
72
{
73
;
74
}
75
76
// -----------------------------------------------------------------------------
77
usec_t
Clock::elapsed
(
void
)
const
78
{
79
if
(!
active
())
80
return
_elapsed
;
81
82
return
time
() -
_start
;
83
}
84
85
86
// -----------------------------------------------------------------------------
87
usec_t
Clock::start
(
void
)
88
{
89
_active
=
true
;
90
91
return
_start
=
time
();
92
}
93
94
// -----------------------------------------------------------------------------
95
usec_t
Clock::stop
(
void
)
96
{
97
_elapsed
=
elapsed
();
98
_active
=
false
;
99
100
return
_elapsed
;
101
}
102
Clock::Clock
Clock(void)
Definition:
Clock.cpp:62
Clock::~Clock
~Clock(void)
Definition:
Clock.cpp:71
INT64_CONSTANT
#define INT64_CONSTANT(val)
Definition:
Clock.hh:18
usec_t
int64_t usec_t
Definition:
Clock.hh:17
Clock::stop
usec_t stop(void)
Definition:
Clock.cpp:95
Clock::_start
usec_t _start
Definition:
Clock.hh:37
rcsid
static const char rcsid[]
Definition:
Clock.cpp:1
Clock::time
static usec_t time(void)
Definition:
Clock.cpp:27
Clock.hh
Clock::_elapsed
usec_t _elapsed
Definition:
Clock.hh:38
Clock::_active
bool _active
Definition:
Clock.hh:39
Clock::start
usec_t start(void)
Definition:
Clock.cpp:87
Clock::elapsed
usec_t elapsed(void) const
Definition:
Clock.cpp:77
Clock::UsingCPU
static bool UsingCPU
Definition:
Clock.hh:24
Clock::active
bool active(void) const
Definition:
Clock.hh:30
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00