rocprofiler-sdk/cxx/details/name_info.hpp Source File

rocprofiler-sdk/cxx/details/name_info.hpp Source File#

Rocprofiler SDK Developer API: rocprofiler-sdk/cxx/details/name_info.hpp Source File
Rocprofiler SDK Developer API 0.4.0
ROCm Profiling API and tools
name_info.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22//
23
24#pragma once
25
26#if !defined(ROCPROFILER_SDK_CXX_NAME_INFO_HPP_)
28#endif
29
32#include <rocprofiler-sdk/fwd.h>
33
34#include <string_view>
35#include <type_traits>
36#include <vector>
37
38namespace rocprofiler
39{
40namespace sdk
41{
42namespace utility
43{
44template <typename EnumT, typename ValueT>
47{
48 auto ret = item_array_t{};
49 ret.reserve(operations.size());
51 for(const auto& itr : operations)
52 ret.emplace_back(_idx++, &itr);
53 return ret;
54}
55
56template <typename EnumT, typename ValueT>
57inline void
58name_info<EnumT, ValueT>::emplace(EnumT idx, const char* name)
59{
60 impl.resize(idx + 1, value_type{});
61 impl.at(idx).value = idx;
62 impl.at(idx).name = support_type{}(name);
63}
64
65template <typename EnumT, typename ValueT>
66inline void
69 const char* name)
70{
71 impl.resize(idx + 1, value_type{});
72 impl.at(idx).operations.resize(opidx + 1, support_type::default_value());
73 impl.at(idx).operations.at(opidx) = support_type{}(name);
74}
75
76template <typename EnumT, typename ValueT>
79{
80 return impl.at(idx).name;
81}
82
83template <typename EnumT, typename ValueT>
86{
87 return impl.at(idx).operations.at(opidx);
88}
89
90template <typename EnumT, typename ValueT>
93{
94 auto ret = item_array_t{};
95 ret.reserve(impl.size());
96 for(const auto& itr : impl)
97 ret.emplace_back(&itr);
98 return ret;
99}
100} // namespace utility
101
103
104template <typename Tp>
107{
108 auto cb_name_info = callback_name_info_t<Tp>{};
109 //
110 // callback for each kind operation
111 //
112 static auto tracing_kind_operation_cb =
113 [](rocprofiler_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) {
114 auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data_v);
115
116 const char* name = nullptr;
118 kindv, operation, &name, nullptr);
119 if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
120 return 0;
121 };
122
123 //
124 // callback for each buffer kind (i.e. domain)
125 //
126 static auto tracing_kind_cb = [](rocprofiler_callback_tracing_kind_t kind, void* data) {
127 // store the buffer kind name
128 auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data);
129 const char* name = nullptr;
130 auto status = rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr);
131 if(status == success_v && name) name_info_v->emplace(kind, name);
132
133 rocprofiler_iterate_callback_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
134 return 0;
135 };
136
137 rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb, &cb_name_info);
138
139 return cb_name_info;
140}
141
142template <typename Tp>
143inline buffer_name_info_t<Tp>
145{
146 auto cb_name_info = buffer_name_info_t<Tp>{};
147 //
148 // callback for each kind operation
149 //
150 static auto tracing_kind_operation_cb =
151 [](rocprofiler_buffer_tracing_kind_t kindv, uint32_t operation, void* data_v) {
152 auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data_v);
153
154 const char* name = nullptr;
156 kindv, operation, &name, nullptr);
157 if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
158 return 0;
159 };
160
161 //
162 // callback for each buffer kind (i.e. domain)
163 //
164 static auto tracing_kind_cb = [](rocprofiler_buffer_tracing_kind_t kind, void* data) {
165 // store the buffer kind name
166 auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data);
167 const char* name = nullptr;
168 auto status = rocprofiler_query_buffer_tracing_kind_name(kind, &name, nullptr);
169 if(status == success_v && name) name_info_v->emplace(kind, name);
170
171 rocprofiler_iterate_buffer_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
172 return 0;
173 };
174
175 rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb, &cb_name_info);
176
177 return cb_name_info;
178}
179} // namespace sdk
180} // namespace rocprofiler
uint32_t rocprofiler_tracing_operation_t
Tracing Operation ID. Depending on the kind, operations can be determined. If the value is equal to z...
Definition fwd.h:448
rocprofiler_buffer_tracing_kind_t
Service Buffer Tracing Kind.
Definition fwd.h:179
rocprofiler_callback_tracing_kind_t
Service Callback Tracing Kind.
Definition fwd.h:155
@ ROCPROFILER_STATUS_SUCCESS
No error occurred.
Definition fwd.h:56
rocprofiler_status_t rocprofiler_iterate_buffer_tracing_kinds(rocprofiler_buffer_tracing_kind_cb_t callback, void *data)
Iterate over all the buffer tracing kinds and invokes the callback for each buffer tracing kind.
rocprofiler_status_t rocprofiler_query_buffer_tracing_kind_name(rocprofiler_buffer_tracing_kind_t kind, const char **name, uint64_t *name_len)
Query the name of the buffer tracing kind. The name retrieved from this function is a string literal ...
rocprofiler_status_t rocprofiler_query_buffer_tracing_kind_operation_name(rocprofiler_buffer_tracing_kind_t kind, uint32_t operation, const char **name, uint64_t *name_len)
Query the name of the buffer tracing kind. The name retrieved from this function is a string literal ...
rocprofiler_status_t rocprofiler_iterate_buffer_tracing_kind_operations(rocprofiler_buffer_tracing_kind_t kind, rocprofiler_buffer_tracing_kind_operation_cb_t callback, void *data)
Iterates over all the operations for a given rocprofiler_buffer_tracing_kind_t and invokes the callba...
rocprofiler_status_t rocprofiler_query_callback_tracing_kind_operation_name(rocprofiler_callback_tracing_kind_t kind, uint32_t operation, const char **name, uint64_t *name_len)
Query the name of the callback tracing kind. The name retrieved from this function is a string litera...
rocprofiler_status_t rocprofiler_query_callback_tracing_kind_name(rocprofiler_callback_tracing_kind_t kind, const char **name, uint64_t *name_len)
Query the name of the callback tracing kind. The name retrieved from this function is a string litera...
rocprofiler_status_t rocprofiler_iterate_callback_tracing_kind_operations(rocprofiler_callback_tracing_kind_t kind, rocprofiler_callback_tracing_kind_operation_cb_t callback, void *data)
Iterates over all the mappings of the operations for a given rocprofiler_callback_tracing_kind_t and ...
rocprofiler_status_t rocprofiler_iterate_callback_tracing_kinds(rocprofiler_callback_tracing_kind_cb_t callback, void *data)
Iterate over all the mappings of the callback tracing kinds and get a callback for each kind.
callback_name_info_t< Tp > get_callback_tracing_names()
buffer_name_info_t< Tp > get_buffer_tracing_names()
constexpr auto success_v
std::vector< item_type > item_array_t
Definition name_info.hpp:48
std::vector< item_type > item_array_t
Definition name_info.hpp:72
typename value_type::support_type support_type
Definition name_info.hpp:69
typename value_type::return_type return_type
Definition name_info.hpp:70
void emplace(EnumT idx, const char *name)
Definition name_info.hpp:58
return_type at(EnumT idx) const
Definition name_info.hpp:78