spla
Loading...
Searching...
No Matches
time_profiler.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_TIME_PROFILER_HPP
29#define SPLA_TIME_PROFILER_HPP
30
31#include <atomic>
32#include <chrono>
33#include <map>
34#include <ostream>
35#include <string>
36
37namespace spla {
38
45 TimeProfilerLabel(TimeProfilerLabel* in_parent, const char* in_name, const char* in_file, const char* in_function);
46
47 std::string name;
48 const char* file;
49 const char* function;
50 int child_count = 0;
51 std::atomic_uint64_t nano;
52 std::uint64_t queued_nano = 0;
53 std::uint64_t executed_nano = 0;
55 };
56
58 explicit TimeProfilerScope(TimeProfilerLabel* in_label);
60
62 std::chrono::steady_clock::time_point start;
63 std::chrono::steady_clock::time_point end;
64 };
65
70 class TimeProfiler final {
71 public:
72 void add_label(TimeProfilerLabel* label);
73 void dump(std::ostream& where);
74 void reset();
75
76 private:
77 std::map<std::string, TimeProfilerLabel*> m_labels;
78 };
79
84#ifndef SPLA_RELEASE
85 #define TIME_PROFILE_LABEL __auto_profile_label
86 #define TIME_PROFILE_SUBLABEL __auto_profile_sublabel
87
88 #define TIME_PROFILE_SUBSCOPE(name) \
89 static TimeProfilerLabel TIME_PROFILE_SUBLABEL(&__auto_profile_label, name, __FILE__, __FUNCTION__); \
90 TimeProfilerScope __auto_profile_subscope(&TIME_PROFILE_SUBLABEL);
91
92 #define TIME_PROFILE_SCOPE(name) \
93 static TimeProfilerLabel TIME_PROFILE_LABEL(nullptr, name, __FILE__, __FUNCTION__); \
94 TimeProfilerScope __auto_profile_scope(&TIME_PROFILE_LABEL);
95#else
96 #define TIME_PROFILE_LABEL
97 #define TIME_PROFILE_SUBLABEL
98 #define TIME_PROFILE_SCOPE(name)
99 #define TIME_PROFILE_SUBSCOPE(name)
100#endif
101
102}// namespace spla
103
104#endif//SPLA_TIME_PROFILER_HPP
Scope-based time profiler to measure perf of schedule tasks execution.
Definition time_profiler.hpp:70
void reset()
Definition time_profiler.cpp:79
void add_label(TimeProfilerLabel *label)
Definition time_profiler.cpp:59
void dump(std::ostream &where)
Definition time_profiler.cpp:63
Definition algorithm.hpp:37
Definition time_profiler.hpp:44
TimeProfilerLabel * parent
Definition time_profiler.hpp:54
int child_count
Definition time_profiler.hpp:50
std::uint64_t executed_nano
Definition time_profiler.hpp:53
std::atomic_uint64_t nano
Definition time_profiler.hpp:51
std::string name
Definition time_profiler.hpp:47
TimeProfilerLabel(TimeProfilerLabel *in_parent, const char *in_name, const char *in_file, const char *in_function)
Definition time_profiler.cpp:34
std::uint64_t queued_nano
Definition time_profiler.hpp:52
const char * function
Definition time_profiler.hpp:49
const char * file
Definition time_profiler.hpp:48
Definition time_profiler.hpp:57
std::chrono::steady_clock::time_point start
Definition time_profiler.hpp:62
TimeProfilerScope(TimeProfilerLabel *in_label)
Definition time_profiler.cpp:48
std::chrono::steady_clock::time_point end
Definition time_profiler.hpp:63
TimeProfilerLabel * label
Definition time_profiler.hpp:61
~TimeProfilerScope()
Definition time_profiler.cpp:53