2 Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 * @brief Some timing classes for debugging and profiling.
25 #ifndef DCPOMATIC_TIMER_H
26 #define DCPOMATIC_TIMER_H
29 #include <boost/optional.hpp>
33 /** @class PeriodTimer
34 * @brief A class to allow timing of a period within the caller.
36 * On destruction, it will output the time since its construction.
41 explicit PeriodTimer (std::string n);
46 /** name to use when giving output */
48 /** time that this class was constructed */
49 struct timeval _start;
53 * @brief A class to allow measurement of the amount of time a program
54 * spends in one of a set of states.
56 * Once constructed, the caller can call set_state() whenever
57 * its state changes. When StateTimer is destroyed, it will
58 * output (to cout) a summary of the time spent in each state.
63 explicit StateTimer (std::string n);
64 StateTimer (std::string n, std::string s);
67 void set (std::string s);
70 std::string name () const {
86 std::map<std::string, Counts> counts () const {
91 void set_internal (boost::optional<std::string> s);
93 /** name to add to the output */
96 boost::optional<std::string> _state;
97 /** time that _state was entered */
99 /** total time and number of entries for each state */
100 std::map<std::string, Counts> _counts;