cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
TimeKeeper.h
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2020-2024 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef CepGen_Utils_TimeKeeper_h
20#define CepGen_Utils_TimeKeeper_h
21
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26#include "CepGen/Utils/Timer.h"
27
28#define CG_CONCAT(a, b) a##b
29#define CG_TICKER_NAME(a, b) CG_CONCAT(a, b)
30#define CG_TICKER(tmr) utils::TimeKeeper::Ticker CG_TICKER_NAME(ticker, __COUNTER__)(tmr, __PRETTY_FUNCTION__)
31
32namespace cepgen {
33 namespace utils {
35 class TimeKeeper {
36 public:
37 explicit TimeKeeper() = default;
38
39 void clear();
40 bool empty() const { return monitors_.empty(); }
41 std::string summary() const;
42
46 TimeKeeper& tick(const std::string& func, double time = -1.);
47
48 const Timer& timer() const;
49
51 class Ticker {
52 public:
53 explicit Ticker(TimeKeeper*, const std::string&);
54 ~Ticker();
55
56 private:
57 TimeKeeper* tk_{nullptr};
58 std::string name_;
59 Timer tmr_;
60 };
61
62 private:
63 std::unordered_map<std::string, std::vector<float> > monitors_;
64 Timer tmr_;
65 };
66 } // namespace utils
67} // namespace cepgen
68
69#endif
Scoped timekeeping utility.
Definition TimeKeeper.h:51
~Ticker()
Ticker destructor to store the timing information to the parent timekeeper.
Collection of clocks to benchmark execution blocks.
Definition TimeKeeper.h:35
bool empty() const
Check if at least one monitor recorded something.
Definition TimeKeeper.h:40
TimeKeeper & tick(const std::string &func, double time=-1.)
Count the time for one monitor.
const Timer & timer() const
Local timer object.
std::string summary() const
Write a summary of all monitors.
void clear()
Reset all counters and the timer.
A generic timer to extract the processing time between two steps in this software's flow.
Definition Timer.h:30
Common namespace for this Monte Carlo generator.