Monero
perf_timer.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2018, 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 <string>
32 #include <stdio.h>
33 #include <memory>
34 #include "misc_log_ex.h"
35 
36 #undef MONERO_DEFAULT_LOG_CATEGORY
37 #define MONERO_DEFAULT_LOG_CATEGORY "perf"
38 
39 namespace tools
40 {
41 
42 class PerformanceTimer;
43 
44 extern el::Level performance_timer_log_level;
45 
46 uint64_t get_tick_count();
47 uint64_t get_ticks_per_ns();
48 uint64_t ticks_to_ns(uint64_t ticks);
49 
51 {
52 public:
53  PerformanceTimer(bool paused = false);
55  void pause();
56  void resume();
57 
58  uint64_t value() const { return ticks; }
59 void set(uint64_t v){ticks=v;}
60 
61 protected:
62  uint64_t ticks;
63  bool started;
64  bool paused;
65 };
66 
68 {
69 public:
70  LoggingPerformanceTimer(const std::string &s, uint64_t unit, el::Level l = el::Level::Debug);
72 
73 private:
74  std::string name;
75  uint64_t unit;
76  el::Level level;
77 };
78 
79 void set_performance_timer_log_level(el::Level level);
80 
81 #define PERF_TIMER_UNIT(name, unit) tools::LoggingPerformanceTimer pt_##name(#name, unit, tools::performance_timer_log_level)
82 #define PERF_TIMER_UNIT_L(name, unit, l) tools::LoggingPerformanceTimer pt_##name(#name, unit, l)
83 #define PERF_TIMER(name) PERF_TIMER_UNIT(name, 1000)
84 #define PERF_TIMER_L(name, l) PERF_TIMER_UNIT_L(name, 1000, l)
85 #define PERF_TIMER_START_UNIT(name, unit) std::unique_ptr<tools::LoggingPerformanceTimer> pt_##name(new tools::LoggingPerformanceTimer(#name, unit, el::Level::Info))
86 #define PERF_TIMER_START(name) PERF_TIMER_START_UNIT(name, 1000)
87 #define PERF_TIMER_STOP(name) do { pt_##name.reset(NULL); } while(0)
88 #define PERF_TIMER_PAUSE(name) pt_##name->pause()
89 #define PERF_TIMER_RESUME(name) pt_##name->resume()
90 
91 }
PerformanceTimer(bool paused=false)
Definition: perf_timer.cpp:99
~LoggingPerformanceTimer()
Definition: perf_timer.cpp:133
void resume()
Definition: perf_timer.cpp:156
el::Level level
Definition: perf_timer.h:76
Definition: perf_timer.h:67
void set_performance_timer_log_level(el::Level level)
Definition: perf_timer.cpp:88
std::string name
Definition: perf_timer.h:74
void pause()
Definition: perf_timer.cpp:148
~PerformanceTimer()
Definition: perf_timer.cpp:127
Various Tools.
Definition: apply_permutation.h:39
uint64_t ticks
Definition: perf_timer.h:62
Definition: perf_timer.h:50
uint64_t ticks_to_ns(uint64_t ticks)
Definition: perf_timer.cpp:71
bool paused
Definition: perf_timer.h:64
int l
Definition: base.py:3
bool started
Definition: perf_timer.h:63
uint64_t value() const
Definition: perf_timer.h:58
el::Level performance_timer_log_level
Definition: perf_timer.cpp:84
uint64_t get_tick_count()
Definition: perf_timer.cpp:38
LoggingPerformanceTimer(const std::string &s, uint64_t unit, el::Level l=el::Level::Debug)
Definition: perf_timer.cpp:107
uint64_t unit
Definition: perf_timer.h:75
#define s(x, c)
Definition: aesb.c:46
uint64_t get_ticks_per_ns()