Main Page
Class Categories
Classes
Namespaces
File List
File Members
exper-sw
cosmosw
AugerSW
Offline
source
main
Utilities
Time
RealTimeStopwatch.cc
Go to the documentation of this file.
1
#include <sys/time.h>
2
#include "
RealTimeStopwatch.h
"
3
4
using namespace
utl;
5
6
7
RealTimeStopwatch::RealTimeStopwatch
(
const
bool
start) :
8
fIsStopped(!start),
9
fTimeSum(0)
10
{
11
if
(start)
12
gettimeofday(&
fStart
, 0);
13
}
14
15
16
void
17
RealTimeStopwatch::Reset
()
18
{
19
fIsStopped
=
true
;
20
fTimeSum
= 0;
21
}
22
23
24
void
25
RealTimeStopwatch::Start
()
26
{
27
if
(
fIsStopped
) {
28
gettimeofday(&
fStart
, 0);
29
fIsStopped
=
false
;
30
}
31
}
32
33
34
double
35
RealTimeStopwatch::Stop
()
36
{
37
if
(
fIsStopped
)
38
return
fTimeSum
;
39
else
{
40
struct
timeval stop;
41
gettimeofday(&stop, 0);
42
fIsStopped
=
true
;
43
return
fTimeSum
+=
44
(stop.tv_sec -
fStart
.tv_sec)*
second
+
45
(stop.tv_usec -
fStart
.tv_usec)*
microsecond
;
46
}
47
}
48
49
50
double
51
RealTimeStopwatch::GetTime
()
52
{
53
if
(
fIsStopped
)
54
return
fTimeSum
;
55
else
{
56
struct
timeval stop;
57
gettimeofday(&stop, 0);
58
return
fTimeSum
+ (stop.tv_sec -
fStart
.tv_sec)*
second
+
59
(stop.tv_usec -
fStart
.tv_usec)*
microsecond
;
60
}
61
}
62
63
64
// Configure (x)emacs for this file ...
65
// Local Variables:
66
// mode: c++
67
// End:
utl::second
constexpr double second
Definition:
AugerUnits.h:145
utl::RealTimeStopwatch::Start
void Start()
Definition:
RealTimeStopwatch.cc:25
utl::RealTimeStopwatch::fStart
struct timeval fStart
Definition:
RealTimeStopwatch.h:32
utl::RealTimeStopwatch::fTimeSum
double fTimeSum
Definition:
RealTimeStopwatch.h:33
utl::RealTimeStopwatch::GetTime
double GetTime()
Definition:
RealTimeStopwatch.cc:51
utl::RealTimeStopwatch::Reset
void Reset()
Definition:
RealTimeStopwatch.cc:17
utl::RealTimeStopwatch::RealTimeStopwatch
RealTimeStopwatch(const bool start=true)
Definition:
RealTimeStopwatch.cc:7
RealTimeStopwatch.h
utl::RealTimeStopwatch::Stop
double Stop()
returns time since last call to Start()
Definition:
RealTimeStopwatch.cc:35
utl::RealTimeStopwatch::fIsStopped
bool fIsStopped
Definition:
RealTimeStopwatch.h:31
utl::microsecond
constexpr double microsecond
Definition:
AugerUnits.h:147
, generated on Tue Sep 26 2023.