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.
audit.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/**
26 * \file timemory/operations/types/audit.hpp
27 * \brief Definition for various functions for audit in operations
28 */
29
30#pragma once
31
32#include "timemory/components/gotcha/backends.hpp"
36
37namespace tim
38{
39namespace operation
40{
41//
42//--------------------------------------------------------------------------------------//
43//
44///
45/// \struct tim::operation::audit
46///
47/// \brief The purpose of this operation class is for a component to provide some extra
48/// customization within a GOTCHA function. It allows a GOTCHA component to inspect
49/// the arguments and the return type of a wrapped function. To add support to a
50/// component, define `void audit(std::string, context, <Args...>)`. The first argument is
51/// the function name (possibly mangled), the second is either type \ref
52/// tim::audit::incoming or \ref tim::audit::outgoing, and the remaining arguments are the
53/// corresponding types
54///
55/// One such purpose may be to create a custom component that intercepts a malloc and
56/// uses the arguments to get the exact allocation size.
57///
58template <typename Tp>
59struct audit
60{
61 using type = Tp;
62 using gotcha_data_t = component::gotcha_data;
63
65
66 template <typename... Args>
67 audit(type& obj, Args&&... args)
68 {
69 (*this)(obj, std::forward<Args>(args)...);
70 }
71
72 auto operator()(type& obj) const
73 {
74 bool _called = false;
75 sfinae(obj, _called, 0, 0, 0);
76 }
77
78 template <typename Up, typename... Args,
80 auto operator()(type& obj, const gotcha_data_t& _data, Up&& _phase,
81 Args&&... args) const
82 {
83 bool _called = false;
84 sfinae(obj, _called, 0, 0, 0, _data, std::forward<Up>(_phase),
85 std::forward<Args>(args)...);
86 if(!_called)
87 {
88 sfinae(obj, _called, 0, 0, 0, _data, std::forward<Args>(args)...);
89 if(!_called)
90 {
91 sfinae(obj, _called, 0, 0, 0, std::forward<Up>(_phase),
92 std::forward<Args>(args)...);
93 if(!_called)
94 sfinae(obj, _called, 0, 0, 0, std::forward<Args>(args)...);
95 }
96 }
97 }
98
99 template <typename Arg, typename... Args,
101 auto operator()(type& obj, Arg&& arg, Args&&... args) const
102 {
103 bool _called = false;
104 sfinae(obj, _called, 0, 0, 0, std::forward<Arg>(arg),
105 std::forward<Args>(args)...);
106 }
107
108private:
109 //----------------------------------------------------------------------------------//
110 // resolution #1 (best)
111 // operation is supported with given arguments
112 //
113 template <typename Up, typename... Args>
114 auto sfinae(Up& obj, bool& _called, int, int, int, const gotcha_data_t& _data,
115 Args&&... args) const
116 -> decltype(obj.audit(_data, std::forward<Args>(args)...))
117 {
118 _called = true;
119 return obj.audit(_data, std::forward<Args>(args)...);
120 }
121
122 template <typename Up, typename... Args>
123 auto sfinae(Up& obj, bool& _called, int, int, int, Args&&... args) const
124 -> decltype(obj.audit(std::forward<Args>(args)...))
125 {
126 _called = true;
127 return obj.audit(std::forward<Args>(args)...);
128 }
129
130 //----------------------------------------------------------------------------------//
131 // resolution #2
132 // converts gotcha_data to string
133 //
134 template <typename Up, typename... Args>
135 auto sfinae(Up& obj, bool& _called, int, int, long, const gotcha_data_t& _data,
136 Args&&... args) const
137 -> decltype(obj.audit(_data.tool_id, std::forward<Args>(args)...))
138 {
139 _called = true;
140 return obj.audit(_data.tool_id, std::forward<Args>(args)...);
141 }
142
143 //----------------------------------------------------------------------------------//
144 // resolution #3
145 // operation is supported with first argument only
146 //
147 template <typename Up, typename Arg, typename... Args>
148 auto sfinae(Up& obj, bool& _called, int, long, long, Arg&& arg, Args&&...) const
149 -> decltype(obj.audit(std::forward<Arg>(arg)))
150 {
151 _called = true;
152 return obj.audit(std::forward<Arg>(arg));
153 }
154
155 //----------------------------------------------------------------------------------//
156 // resolution #4
157 // operation is not supported
158 //
159 template <typename Up, typename... Args>
160 void sfinae(Up&, bool&, long, long, long, Args&&...) const
161 {}
162 //
163 //----------------------------------------------------------------------------------//
164};
165//
166//--------------------------------------------------------------------------------------//
167//
168} // namespace operation
169} // namespace tim
STL namespace.
void audit(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:939
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
The purpose of this operation class is for a component to provide some extra customization within a G...
Definition: audit.hpp:60
auto operator()(type &obj) const
Definition: audit.hpp:72
TIMEMORY_DELETED_OBJECT(audit) template< typename... Args > audit(type &obj
component::gotcha_data gotcha_data_t
Definition: audit.hpp:62
auto operator()(type &obj, const gotcha_data_t &_data, Up &&_phase, Args &&... args) const
Definition: audit.hpp:80
auto operator()(type &obj, Arg &&arg, Args &&... args) const
Definition: audit.hpp:101