Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
perf_timer.h
Go to the documentation of this file.
1
// Copyright (c) 2017-Present, Electroneum
2
// Copyright (c) 2016-2019, The Monero Project
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without modification, are
7
// permitted provided that the following conditions are met:
8
//
9
// 1. Redistributions of source code must retain the above copyright notice, this list of
10
// conditions and the following disclaimer.
11
//
12
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13
// of conditions and the following disclaimer in the documentation and/or other
14
// materials provided with the distribution.
15
//
16
// 3. Neither the name of the copyright holder nor the names of its contributors may be
17
// used to endorse or promote products derived from this software without specific
18
// prior written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
#pragma once
31
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
42
extern
el::Level
performance_timer_log_level
;
43
44
uint64_t
get_tick_count
();
45
uint64_t
get_ticks_per_ns
();
46
uint64_t
ticks_to_ns
(
uint64_t
ticks);
47
48
class
PerformanceTimer
49
{
50
public
:
51
PerformanceTimer
(
bool
paused
=
false
);
52
~PerformanceTimer
();
53
void
pause
();
54
void
resume
();
55
void
reset
();
56
uint64_t
value
()
const
;
57
operator
uint64_t
()
const
{
return
value
(); }
58
59
protected
:
60
uint64_t
ticks
;
61
bool
started
;
62
bool
paused
;
63
};
64
65
class
LoggingPerformanceTimer
:
public
PerformanceTimer
66
{
67
public
:
68
LoggingPerformanceTimer
(
const
std::string &s,
const
std::string &cat,
uint64_t
unit,
el::Level
l =
el::Level::Info
);
69
~LoggingPerformanceTimer
();
70
71
private
:
72
std::string name;
73
std::string cat;
74
uint64_t
unit;
75
el::Level
level;
76
};
77
78
void
set_performance_timer_log_level
(
el::Level
level);
79
80
#define PERF_TIMER_UNIT(name, unit) tools::LoggingPerformanceTimer pt_##name(#name, "perf." ELECTRONEUM_DEFAULT_LOG_CATEGORY, unit, tools::performance_timer_log_level)
81
#define PERF_TIMER_UNIT_L(name, unit, l) tools::LoggingPerformanceTimer pt_##name(#name, "perf." ELECTRONEUM_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> pt_##name(new tools::LoggingPerformanceTimer(#name, "perf." ELECTRONEUM_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 { pt_##name.reset(NULL); } while(0)
87
#define PERF_TIMER_PAUSE(name) pt_##name->pause()
88
#define PERF_TIMER_RESUME(name) pt_##name->resume()
89
90
}
tools::LoggingPerformanceTimer::LoggingPerformanceTimer
LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l=el::Level::Info)
Definition
perf_timer.cpp:115
tools::LoggingPerformanceTimer::~LoggingPerformanceTimer
~LoggingPerformanceTimer()
Definition
perf_timer.cpp:147
tools::PerformanceTimer
Definition
perf_timer.h:49
tools::PerformanceTimer::resume
void resume()
Definition
perf_timer.cpp:174
tools::PerformanceTimer::PerformanceTimer
PerformanceTimer(bool paused=false)
Definition
perf_timer.cpp:107
tools::PerformanceTimer::~PerformanceTimer
~PerformanceTimer()
Definition
perf_timer.cpp:141
tools::PerformanceTimer::reset
void reset()
Definition
perf_timer.cpp:182
tools::PerformanceTimer::started
bool started
Definition
perf_timer.h:61
tools::PerformanceTimer::pause
void pause()
Definition
perf_timer.cpp:166
tools::PerformanceTimer::paused
bool paused
Definition
perf_timer.h:62
tools::PerformanceTimer::value
uint64_t value() const
Definition
perf_timer.cpp:190
tools::PerformanceTimer::ticks
uint64_t ticks
Definition
perf_timer.h:60
misc_log_ex.h
el::Level
Level
Represents enumeration for severity level used to determine level of logging.
Definition
easylogging++.h:585
el::Level::Info
@ Info
Mainly useful to represent current progress of application.
Definition
easylogging++.h:601
tools
Various Tools.
Definition
tools.cpp:31
tools::ticks_to_ns
uint64_t ticks_to_ns(uint64_t ticks)
Definition
perf_timer.cpp:79
tools::set_performance_timer_log_level
void set_performance_timer_log_level(el::Level level)
Definition
perf_timer.cpp:96
tools::get_tick_count
uint64_t get_tick_count()
Definition
perf_timer.cpp:46
tools::performance_timer_log_level
el::Level performance_timer_log_level
Definition
perf_timer.cpp:92
tools::get_ticks_per_ns
uint64_t get_ticks_per_ns()
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
src
common
perf_timer.h
Generated on
for Electroneum by
1.17.0