Monero
perf_timer.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include <cstdint>
32 #include <string>
33 #include <stdio.h>
34 #include <memory>
35 #include "misc_log_ex.h"
36 
37 namespace tools
38 {
39 
40 class PerformanceTimer;
41 
43 
47 
49 {
50 public:
51  PerformanceTimer(bool paused = false);
53  void pause();
54  void resume();
55  void reset();
56  uint64_t value() const;
57  operator uint64_t() const { return value(); }
58 
59 protected:
61  bool started;
62  bool paused;
63 };
64 
66 {
67 public:
70 
71 private:
76 };
77 
79 
80 #define PERF_TIMER_NAME(name) pt_##name
81 #define PERF_TIMER_UNIT(name, unit) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, tools::performance_timer_log_level)
82 #define PERF_TIMER_UNIT_L(name, unit, l) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)t_##name(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, l)
83 #define PERF_TIMER(name) PERF_TIMER_UNIT(name, 1000000)
84 #define PERF_TIMER_L(name, l) PERF_TIMER_UNIT_L(name, 1000000, l)
85 #define PERF_TIMER_START_UNIT(name, unit) std::unique_ptr<tools::LoggingPerformanceTimer> PERF_TIMER_NAME(name)(new tools::LoggingPerformanceTimer(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, el::Level::Info))
86 #define PERF_TIMER_START(name) PERF_TIMER_START_UNIT(name, 1000000)
87 #define PERF_TIMER_STOP(name) do { PERF_TIMER_NAME(name).reset(NULL); } while(0)
88 #define PERF_TIMER_PAUSE(name) PERF_TIMER_NAME(name).pause()
89 #define PERF_TIMER_RESUME(name) PERF_TIMER_NAME(name).resume()
90 
91 }
PerformanceTimer(bool paused=false)
Definition: perf_timer.cpp:106
~LoggingPerformanceTimer()
Definition: perf_timer.cpp:146
void resume()
Definition: perf_timer.cpp:173
el::Level level
Definition: perf_timer.h:75
Definition: perf_timer.h:65
::std::string string
Definition: gtest-port.h:1097
l
Definition: base.py:3
const char * s
Definition: minissdp.c:596
void set_performance_timer_log_level(el::Level level)
Definition: perf_timer.cpp:95
Level
Represents enumeration for severity level used to determine level of logging.
Definition: easylogging++.h:591
std::string name
Definition: perf_timer.h:72
void pause()
Definition: perf_timer.cpp:165
~PerformanceTimer()
Definition: perf_timer.cpp:140
LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l=el::Level::Info)
Definition: perf_timer.cpp:114
Various Tools.
Definition: apply_permutation.h:39
uint64_t ticks
Definition: perf_timer.h:60
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: perf_timer.h:48
uint64_t ticks_to_ns(uint64_t ticks)
Definition: perf_timer.cpp:78
bool paused
Definition: perf_timer.h:62
std::string cat
Definition: perf_timer.h:73
Mainly useful to represent current progress of application.
bool started
Definition: perf_timer.h:61
uint64_t value() const
Definition: perf_timer.cpp:189
el::Level performance_timer_log_level
Definition: perf_timer.cpp:91
uint64_t get_tick_count()
Definition: perf_timer.cpp:45
void reset()
Definition: perf_timer.cpp:181
uint64_t unit
Definition: perf_timer.h:74
uint64_t get_ticks_per_ns()