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.5.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 = [](rocprofiler_callback_tracing_kind_t kindv,
114 void* data_v) {
115 auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data_v);
116
117 const char* name = nullptr;
119 kindv, operation, &name, nullptr);
120 if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
121 return 0;
122 };
123
124 //
125 // callback for each buffer kind (i.e. domain)
126 //
127 static auto tracing_kind_cb = [](rocprofiler_callback_tracing_kind_t kind, void* data) {
128 // store the buffer kind name
129 auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data);
130 const char* name = nullptr;
131 auto status = rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr);
132 if(status == success_v && name) name_info_v->emplace(kind, name);
133
134 rocprofiler_iterate_callback_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
135 return 0;
136 };
137
138 rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb, &cb_name_info);
139
140 return cb_name_info;
141}
142
143template <typename Tp>
144inline buffer_name_info_t<Tp>
146{
147 auto cb_name_info = buffer_name_info_t<Tp>{};
148 //
149 // callback for each kind operation
150 //
151 static auto tracing_kind_operation_cb = [](rocprofiler_buffer_tracing_kind_t kindv,
153 void* data_v) {
154 auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data_v);
155
156 const char* name = nullptr;
157 auto status =
158 rocprofiler_query_buffer_tracing_kind_operation_name(kindv, operation, &name, nullptr);
159 if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
160 return 0;
161 };
162
163 //
164 // callback for each buffer kind (i.e. domain)
165 //
166 static auto tracing_kind_cb = [](rocprofiler_buffer_tracing_kind_t kind, void* data) {
167 // store the buffer kind name
168 auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data);
169 const char* name = nullptr;
170 auto status = rocprofiler_query_buffer_tracing_kind_name(kind, &name, nullptr);
171 if(status == success_v && name) name_info_v->emplace(kind, name);
172
173 rocprofiler_iterate_buffer_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
174 return 0;
175 };
176
177 rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb, &cb_name_info);
178
179 return cb_name_info;
180}
181} // namespace sdk
182} // namespace rocprofiler
int32_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:452
rocprofiler_buffer_tracing_kind_t
Service Buffer Tracing Kind.
Definition fwd.h:182
rocprofiler_callback_tracing_kind_t
Service Callback Tracing Kind.
Definition fwd.h:157
@ 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, rocprofiler_tracing_operation_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, rocprofiler_tracing_operation_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