timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
components.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25#pragma once
26
28#include "timemory/components/vtune/backends.hpp"
30#include "timemory/units.hpp"
31
32namespace tim
33{
34namespace component
35{
36//
37/// \struct tim::component::vtune_event
38/// \brief Implements `__itt_event`
39///
40struct vtune_event : public base<vtune_event, void>
41{
42 using value_type = void;
45
46 static std::string label() { return "vtune_event"; }
48 {
49 return "Creates events for Intel profiler running on the application";
50 }
51 static value_type record() {}
52
53 static void global_init() { ittnotify::pause(); }
54 static void global_finalize() { ittnotify::pause(); }
55
56 void start()
57 {
58 get_index()++;
59
60 if(m_index == 0)
61 ittnotify::resume();
62 if(!m_created)
63 {
64 m_event = ittnotify::create_event(m_prefix);
65 m_created = true;
66 }
67 ittnotify::start_event(m_event);
68 }
69
70 void stop()
71 {
72 auto _index = --get_index();
73 ittnotify::end_event(m_event);
74 if(_index == 0)
75 ittnotify::pause();
76 }
77
79
80protected:
81 bool m_created = false;
83 int64_t m_index = -1;
84 ittnotify::event_t m_event;
85
86private:
87 static std::atomic<int64_t>& get_index()
88 {
89 static std::atomic<int64_t> _instance(0);
90 return _instance;
91 }
92};
93//
94//--------------------------------------------------------------------------------------//
95//
96/// \struct tim::component::vtune_frame
97/// \brief Implements `__itt_domain`
98///
99struct vtune_frame : public base<vtune_frame, void>
100{
101 using value_type = void;
104
105 static std::string label() { return "vtune_frame"; }
107 {
108 return "Creates frames for Intel profiler running on the application";
109 }
110 static value_type record() {}
111
112 static void global_init() { ittnotify::pause(); }
113 static void global_finalize() { ittnotify::pause(); }
114
115 void start()
116 {
117 get_index()++;
118
119 if(m_index == 0)
120 ittnotify::resume();
121 if(m_domain == nullptr)
122 m_domain = ittnotify::create_domain(m_prefix);
123 ittnotify::start_frame(m_domain);
124 }
125
126 void stop()
127 {
128 auto _index = --get_index();
129 if(m_domain)
130 ittnotify::end_frame(m_domain);
131 if(_index == 0)
132 ittnotify::pause();
133 }
134
136
137protected:
139 int64_t m_index = -1;
140 ittnotify::domain_t* m_domain = nullptr;
141
142private:
143 static std::atomic<int64_t>& get_index()
144 {
145 static std::atomic<int64_t> _instance(0);
146 return _instance;
147 }
148};
149//
150//--------------------------------------------------------------------------------------//
151//
152/// \struct tim::component::vtune_profiler
153/// \brief Implements `__itt_pause()` and `__itt_resume()` to control where the vtune
154/// profiler is active
155///
157: public base<vtune_profiler, void>
158, private policy::instance_tracker<vtune_profiler, false>
159{
160 using value_type = void;
164
165 static std::string label() { return "vtune_profiler"; }
167 {
168 return "Control switch for Intel profiler running on the application";
169 }
170 static value_type record() {}
171
172 static void global_init() { ittnotify::pause(); }
173 static void global_finalize() { ittnotify::pause(); }
174
175 using tracker_type::m_tot;
176
177 void start()
178 {
180
181 if(m_tot == 0)
182 ittnotify::resume();
183 }
184
185 void stop()
186 {
188
189 if(m_tot == 0)
190 ittnotify::pause();
191 }
192};
193//
194} // namespace component
195} // namespace tim
void stop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:386
void start(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:316
Inherit from this policy to add reference counting support. Useful if you want to turn a global setti...
Definition: types.hpp:406
Definition: kokkosp.cpp:39
char const std::string & _prefix
Definition: config.cpp:55
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
Implements __itt_event
Definition: components.hpp:41
static std::string description()
Definition: components.hpp:47
ittnotify::event_t m_event
Definition: components.hpp:84
static std::string label()
Definition: components.hpp:46
static value_type record()
Definition: components.hpp:51
void set_prefix(const std::string &_prefix)
Definition: components.hpp:78
static void global_finalize()
Definition: components.hpp:54
Implements __itt_domain
Definition: components.hpp:100
static value_type record()
Definition: components.hpp:110
ittnotify::domain_t * m_domain
Definition: components.hpp:140
void set_prefix(const std::string &_prefix)
Definition: components.hpp:135
static std::string label()
Definition: components.hpp:105
static std::string description()
Definition: components.hpp:106
Implements __itt_pause() and __itt_resume() to control where the vtune profiler is active.
Definition: components.hpp:159
static value_type record()
Definition: components.hpp:170
static std::string description()
Definition: components.hpp:166
static std::string label()
Definition: components.hpp:165