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.
suppression.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/or sell
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/mpl/concepts.hpp" // component::gotcha forward decl
29
30#include <type_traits>
31
32namespace tim
33{
34namespace component
35{
36//
38{
39private:
40 template <size_t Nt, typename Components, typename Differentiator>
41 friend struct gotcha;
42
43 static TIMEMORY_NOINLINE bool& get()
44 {
45 static thread_local bool _instance = false;
46 return _instance;
47 }
48
49public:
51 {
52 explicit auto_toggle(bool& _value, bool _if_equal = false);
53 auto_toggle(std::false_type);
54 auto_toggle(std::true_type);
56 auto_toggle(const auto_toggle&) = delete;
60
61 private:
62 bool& m_value;
63 bool m_if_equal;
64 bool m_did_toggle = false;
65 };
66};
67//
68inline gotcha_suppression::auto_toggle::auto_toggle(bool& _value, bool _if_equal)
69: m_value{ _value }
70, m_if_equal{ _if_equal }
71{
72 if(m_value == m_if_equal)
73 {
74 m_value = !m_value;
75 m_did_toggle = true;
76 }
77}
78//
80: auto_toggle{ get(), false }
81{}
82//
84: auto_toggle{ get(), true }
85{}
86//
88{
89 if(m_value != m_if_equal && m_did_toggle)
90 {
91 m_value = !m_value;
92 }
93}
94//
95} // namespace component
96} // namespace tim
return false
Definition: definition.hpp:326
Definition: kokkosp.cpp:39
auto get(const auto_bundle< Tag, Types... > &_obj)
auto_toggle & operator=(auto_toggle &&)=delete
auto_toggle & operator=(const auto_toggle &)=delete
auto_toggle(bool &_value, bool _if_equal=false)
Definition: suppression.hpp:68
The gotcha component rewrites the global offset table such that calling the wrapped function actually...
Definition: components.hpp:179