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.
types.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
29#include <cstdint>
30#include <functional>
31#include <set>
32#include <string>
33
34namespace tim
35{
36//
37namespace scope
38{
39struct config;
40}
41//
42namespace component
43{
44//
45struct opaque
46{
47 using init_func_t = std::function<void()>;
48 using setup_func_t = std::function<void*(void*, string_view_cref_t, scope::config)>;
49 using push_func_t = std::function<void(void*&, string_view_cref_t, scope::config)>;
50 using start_func_t = std::function<void(void*)>;
51 using stop_func_t = std::function<void(void*)>;
52 using pop_func_t = std::function<void(void*)>;
53 using get_func_t = std::function<void(void*, void*&, size_t)>;
54 using delete_func_t = std::function<void(void*)>;
55 using sample_func_t = std::function<void(void*)>;
56 using stats_func_t = std::function<void(void*, bool)>;
57
58 template <typename InitF, typename StartF, typename StopF, typename GetF,
59 typename DelF, typename SetupF, typename PushF, typename PopF,
60 typename SampleF, typename UpdateStatsF>
61 opaque(bool _valid, size_t _typeid, InitF&& _init, StartF&& _start, StopF&& _stop,
62 GetF&& _get, DelF&& _del, SetupF&& _setup, PushF&& _push, PopF&& _pop,
63 SampleF&& _sample, UpdateStatsF&& _stats);
64
65 opaque() = default;
66 ~opaque();
67 opaque(const opaque&) = default;
68 opaque(opaque&&) = default;
69 opaque& operator=(const opaque&) = default;
70 opaque& operator=(opaque&&) = default;
71
72 operator bool() const { return m_valid; }
73
74 void init() const;
77 void sample() const;
78 void start() const;
79 void stop() const;
80 void pop() const;
81 void cleanup();
82 void get(void*& ptr, size_t _hash) const;
83 void update_statistics(bool) const;
84 void set_copy(bool val);
85
86 bool m_valid = false;
87 bool m_copy = false;
88 size_t m_typeid = 0;
89 void* m_data = nullptr;
92 return nullptr;
93 };
95 start_func_t m_start = [](void*) {};
96 stop_func_t m_stop = [](void*) {};
97 pop_func_t m_pop = [](void*) {};
98 get_func_t m_get = [](void*, void*&, size_t) {};
99 delete_func_t m_del = [](void*) {};
100 sample_func_t m_sample = [](void*) {};
101 stats_func_t m_update_stats = [](void*, bool) {};
102};
103//
104template <typename Toolset>
105opaque
107//
108template <typename Toolset>
109opaque
111//
112template <typename Toolset, typename Arg, typename... Args>
113opaque
114get_opaque(Arg&& arg, Args&&... args);
115//
116template <typename Toolset>
117std::set<size_t>
119//
120namespace factory
121{
122//
123template <typename Toolset, typename Arg, typename... Args>
124opaque
125get_opaque(Arg&& arg, Args&&... args);
126//
127template <typename Toolset>
128opaque
129get_opaque();
130//
131template <typename Toolset>
132opaque
134//
135template <typename Toolset>
136std::set<size_t>
138//
139} // namespace factory
140} // namespace component
141} // namespace tim
Toolset
Definition: types.hpp:40
opaque get_opaque(Arg &&arg, Args &&... args)
Definition: definition.hpp:327
std::set< size_t > get_typeids()
Definition: definition.hpp:361
opaque get_opaque()
std::set< size_t > get_typeids()
Definition: kokkosp.cpp:39
char const std::string & _prefix
Definition: config.cpp:55
const std::string & string_view_cref_t
Definition: language.hpp:103
std::function< void(void *, void *&, size_t)> get_func_t
Definition: types.hpp:53
init_func_t m_init
Definition: types.hpp:90
void get(void *&ptr, size_t _hash) const
delete_func_t m_del
Definition: types.hpp:99
stats_func_t m_update_stats
Definition: types.hpp:101
std::function< void(void *)> stop_func_t
Definition: types.hpp:51
sample_func_t m_sample
Definition: types.hpp:100
stop_func_t m_stop
Definition: types.hpp:96
void update_statistics(bool) const
setup_func_t m_setup
Definition: types.hpp:91
opaque & operator=(opaque &&)=default
std::function< void(void *)> sample_func_t
Definition: types.hpp:55
opaque & operator=(const opaque &)=default
opaque(opaque &&)=default
std::function< void(void *, bool)> stats_func_t
Definition: types.hpp:56
void push(string_view_cref_t _prefix, scope::config _scope)
std::function< void *(void *, string_view_cref_t, scope::config)> setup_func_t
Definition: types.hpp:48
std::function< void(void *)> start_func_t
Definition: types.hpp:50
std::function< void()> init_func_t
Definition: types.hpp:47
push_func_t m_push
Definition: types.hpp:94
void setup(string_view_cref_t _prefix, scope::config _scope)
Definition: declaration.hpp:88
std::function< void(void *&, string_view_cref_t, scope::config)> push_func_t
Definition: types.hpp:49
get_func_t m_get
Definition: types.hpp:98
void set_copy(bool val)
std::function< void(void *)> delete_func_t
Definition: types.hpp:54
start_func_t m_start
Definition: types.hpp:95
std::function< void(void *)> pop_func_t
Definition: types.hpp:52
pop_func_t m_pop
Definition: types.hpp:97
opaque(const opaque &)=default
this data type encodes the options of storage scope. The default is hierarchical (tree) scope....
Definition: types.hpp:453