Monero
Loading...
Searching...
No Matches
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 <string>
32#include <stdio.h>
33#include <memory>
34#include "misc_log_ex.h"
35
36namespace tools
37{
38
39class PerformanceTimer;
40
42
46
48{
49public:
50 PerformanceTimer(bool paused = false);
52 void pause();
53 void resume();
54 void reset();
55 uint64_t value() const;
56 operator uint64_t() const { return value(); }
57
58protected:
60 bool started;
61 bool paused;
62};
63
65{
66public:
67 LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l = el::Level::Info);
69
70private:
71 std::string name;
72 std::string cat;
75};
76
78
79#define PERF_TIMER_NAME(name) pt_##name
80#define PERF_TIMER_UNIT(name, unit) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, tools::performance_timer_log_level)
81#define PERF_TIMER_UNIT_L(name, unit, l) tools::LoggingPerformanceTimer PERF_TIMER_NAME(name)t_##name(#name, "perf." MONERO_DEFAULT_LOG_CATEGORY, unit, l)
82#define PERF_TIMER(name) PERF_TIMER_UNIT(name, 1000000)
83#define PERF_TIMER_L(name, l) PERF_TIMER_UNIT_L(name, 1000000, l)
84#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))
85#define PERF_TIMER_START(name) PERF_TIMER_START_UNIT(name, 1000000)
86#define PERF_TIMER_STOP(name) do { PERF_TIMER_NAME(name).reset(NULL); } while(0)
87#define PERF_TIMER_PAUSE(name) PERF_TIMER_NAME(name).pause()
88#define PERF_TIMER_RESUME(name) PERF_TIMER_NAME(name).resume()
89
90}
#define s(x, c)
Definition: aesb.c:47
Definition: perf_timer.h:65
el::Level level
Definition: perf_timer.h:74
uint64_t unit
Definition: perf_timer.h:73
std::string cat
Definition: perf_timer.h:72
~LoggingPerformanceTimer()
Definition: perf_timer.cpp:146
std::string name
Definition: perf_timer.h:71
Definition: perf_timer.h:48
void resume()
Definition: perf_timer.cpp:173
~PerformanceTimer()
Definition: perf_timer.cpp:140
void reset()
Definition: perf_timer.cpp:181
bool started
Definition: perf_timer.h:60
void pause()
Definition: perf_timer.cpp:165
bool paused
Definition: perf_timer.h:61
uint64_t value() const
Definition: perf_timer.cpp:189
uint64_t ticks
Definition: perf_timer.h:59
Level
Represents enumeration for severity level used to determine level of logging.
Definition: easylogging++.h:591
@ Info
Mainly useful to represent current progress of application.
Various Tools.
Definition: apply_permutation.h:40
uint64_t ticks_to_ns(uint64_t ticks)
Definition: perf_timer.cpp:78
void set_performance_timer_log_level(el::Level level)
Definition: perf_timer.cpp:95
uint64_t get_tick_count()
Definition: perf_timer.cpp:45
el::Level performance_timer_log_level
Definition: perf_timer.cpp:91
uint64_t get_ticks_per_ns()
unsigned __int64 uint64_t
Definition: stdint.h:136