Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file |
3 |
|
|
* @license BSD 3-clause |
4 |
|
|
* @copyright Copyright (c) 2020, New York University and Max Planck |
5 |
|
|
* Gesellschaft |
6 |
|
|
* |
7 |
|
|
* @brief Implementation of the CheckpointTimer class. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
template <size_t NUM_CHECKPOINTS, bool ENABLED> |
11 |
|
✗ |
CheckpointTimer<NUM_CHECKPOINTS, ENABLED>::CheckpointTimer() |
12 |
|
|
{ |
13 |
|
|
static_assert(NUM_CHECKPOINTS > 0, |
14 |
|
|
"CheckpointTimer needs at least one checkpoint"); |
15 |
|
✗ |
checkpoint_names_[0] = "Total"; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
template <size_t NUM_CHECKPOINTS, bool ENABLED> |
19 |
|
✗ |
void CheckpointTimer<NUM_CHECKPOINTS, ENABLED>::start() |
20 |
|
|
{ |
21 |
|
|
if (ENABLED) |
22 |
|
|
{ |
23 |
|
✗ |
timers_[0].tac_tic(); |
24 |
|
✗ |
current_checkpoint_ = 1; |
25 |
|
✗ |
timers_[current_checkpoint_].tic(); |
26 |
|
|
} |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
template <size_t NUM_CHECKPOINTS, bool ENABLED> |
30 |
|
✗ |
void CheckpointTimer<NUM_CHECKPOINTS, ENABLED>::checkpoint( |
31 |
|
|
const std::string &checkpoint_name) |
32 |
|
|
{ |
33 |
|
|
if (ENABLED) |
34 |
|
|
{ |
35 |
|
✗ |
timers_[current_checkpoint_].tac(); |
36 |
|
|
|
37 |
|
✗ |
if (checkpoint_names_[current_checkpoint_].empty()) |
38 |
|
|
{ |
39 |
|
✗ |
checkpoint_names_[current_checkpoint_] = checkpoint_name; |
40 |
|
|
} |
41 |
|
✗ |
else if (checkpoint_names_[current_checkpoint_] != checkpoint_name) |
42 |
|
|
{ |
43 |
|
|
throw std::runtime_error("Wrong checkpoint called (expected '" + |
44 |
|
✗ |
checkpoint_names_[current_checkpoint_] + |
45 |
|
✗ |
"' but got '" + checkpoint_name + "')."); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
✗ |
current_checkpoint_++; |
49 |
|
✗ |
if (current_checkpoint_ < timers_.size()) |
50 |
|
|
{ |
51 |
|
✗ |
timers_[current_checkpoint_].tic(); |
52 |
|
|
} |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
template <size_t NUM_CHECKPOINTS, bool ENABLED> |
57 |
|
✗ |
void CheckpointTimer<NUM_CHECKPOINTS, ENABLED>::print_statistics() const |
58 |
|
|
{ |
59 |
|
|
if (ENABLED) |
60 |
|
|
{ |
61 |
|
✗ |
std::cout << "======================================" << std::endl; |
62 |
|
✗ |
for (size_t i = 0; i < timers_.size(); i++) |
63 |
|
|
{ |
64 |
|
✗ |
std::cout << "===== " << checkpoint_names_[i] << std::endl; |
65 |
|
✗ |
timers_[i].print_statistics(); |
66 |
|
|
} |
67 |
|
|
} |
68 |
|
|
} |
69 |
|
|
|