Electroneum
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
37namespace tools
38{
39
41
43
47
49{
50public:
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
59protected:
61 bool started;
62 bool paused;
63};
64
66{
67public:
68 LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l = el::Level::Info);
70
71private:
72 std::string name;
73 std::string cat;
74 uint64_t unit;
75 el::Level level;
76};
77
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}
LoggingPerformanceTimer(const std::string &s, const std::string &cat, uint64_t unit, el::Level l=el::Level::Info)
PerformanceTimer(bool paused=false)
uint64_t value() const
Level
Represents enumeration for severity level used to determine level of logging.
@ Info
Mainly useful to represent current progress of application.
Various Tools.
Definition tools.cpp:31
uint64_t ticks_to_ns(uint64_t ticks)
void set_performance_timer_log_level(el::Level level)
uint64_t get_tick_count()
el::Level performance_timer_log_level
uint64_t get_ticks_per_ns()
unsigned __int64 uint64_t
Definition stdint.h:136