Main Page
Class Categories
Classes
Namespaces
File List
File Members
exper-sw
cosmosw
AugerSW
Offline
source
main
Utilities
Time
Stopwatch.cc
Go to the documentation of this file.
1
#include <sys/times.h>
2
#include <unistd.h>
3
#include "
Stopwatch.h
"
4
5
using namespace
utl;
6
7
8
const
long
Stopwatch::fgClockTicks
= sysconf(_SC_CLK_TCK);
9
10
11
Stopwatch::Stopwatch
() :
12
fIsStopped(false),
13
fUserTimeSum(0),
14
fSystemTimeSum(0)
15
{
16
times(&
fStart
);
17
}
18
19
20
void
21
Stopwatch::Reset
()
22
{
23
fIsStopped
=
true
;
24
fUserTimeSum
=
fSystemTimeSum
= 0;
25
}
26
27
28
void
29
Stopwatch::Start
()
30
{
31
if
(
fIsStopped
) {
32
times(&
fStart
);
33
fIsStopped
=
false
;
34
}
35
}
36
37
38
void
39
Stopwatch::Stop
()
40
{
41
if
(!
fIsStopped
) {
42
struct
tms stop;
43
times(&stop);
44
fUserTimeSum
+= stop.tms_utime -
fStart
.tms_utime;
45
fSystemTimeSum
+= stop.tms_stime -
fStart
.tms_stime;
46
fIsStopped
=
true
;
47
}
48
}
49
50
51
double
52
Stopwatch::GetCPUTime
(
const
CPUTime
kind)
53
{
54
if
(
fIsStopped
)
55
switch
(kind) {
56
case
eTotal
:
57
return
double(
fUserTimeSum
+
fSystemTimeSum
)/
fgClockTicks
*
second
;
58
case
eUser
:
59
return
double(
fUserTimeSum
)/
fgClockTicks
*
second
;
60
case
eSystem
:
61
return
double(
fSystemTimeSum
)/
fgClockTicks
*
second
;
62
}
63
else
{
64
struct
tms stop;
65
times(&stop);
66
switch
(kind) {
67
case
eTotal
:
68
return
double(
fUserTimeSum
+
fSystemTimeSum
+
69
stop.tms_utime -
fStart
.tms_utime +
70
stop.tms_stime -
fStart
.tms_stime)/
fgClockTicks
*
second
;
71
case
eUser
:
72
return
double(
fUserTimeSum
+
73
stop.tms_utime -
fStart
.tms_utime)/
fgClockTicks
*
second
;
74
case
eSystem
:
75
return
double(
fSystemTimeSum
+
76
stop.tms_stime -
fStart
.tms_stime)/
fgClockTicks
*
second
;
77
}
78
}
79
80
return
0;
81
}
82
83
84
// Configure (x)emacs for this file ...
85
// Local Variables:
86
// mode: c++
87
// End:
utl::second
constexpr double second
Definition:
AugerUnits.h:145
utl::Stopwatch::eSystem
Definition:
Stopwatch.h:22
utl::Stopwatch::Stopwatch
Stopwatch()
Definition:
Stopwatch.cc:11
utl::Stopwatch::fStart
struct tms fStart
Definition:
Stopwatch.h:35
utl::Stopwatch::Stop
void Stop()
Definition:
Stopwatch.cc:39
utl::Stopwatch::eUser
Definition:
Stopwatch.h:21
utl::Stopwatch::fUserTimeSum
clock_t fUserTimeSum
Definition:
Stopwatch.h:36
utl::Stopwatch::Reset
void Reset()
Definition:
Stopwatch.cc:21
utl::Stopwatch::Start
void Start()
Definition:
Stopwatch.cc:29
utl::Stopwatch::fSystemTimeSum
clock_t fSystemTimeSum
Definition:
Stopwatch.h:37
utl::Stopwatch::fIsStopped
bool fIsStopped
Definition:
Stopwatch.h:34
Stopwatch.h
utl::Stopwatch::CPUTime
CPUTime
Definition:
Stopwatch.h:19
utl::Stopwatch::fgClockTicks
static const long fgClockTicks
Definition:
Stopwatch.h:33
utl::Stopwatch::GetCPUTime
double GetCPUTime(const CPUTime kind=eTotal)
Definition:
Stopwatch.cc:52
utl::Stopwatch::eTotal
Definition:
Stopwatch.h:20
, generated on Tue Sep 26 2023.