|
| 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 | +#pragma once |
| 24 | + |
| 25 | +#include "lib/common/demangle.hpp" |
| 26 | +#include "lib/common/logging.hpp" |
| 27 | + |
| 28 | +#include <rocprofiler-sdk/callback_tracing.h> |
| 29 | +#include <rocprofiler-sdk/fwd.h> |
| 30 | +#include <rocprofiler-sdk/cxx/hash.hpp> |
| 31 | +#include <rocprofiler-sdk/cxx/name_info.hpp> |
| 32 | +#include <rocprofiler-sdk/cxx/operators.hpp> |
| 33 | +#include <rocprofiler-sdk/cxx/serialization.hpp> |
| 34 | + |
| 35 | +#include <cstdint> |
| 36 | +#include <string> |
| 37 | +#include <unordered_map> |
| 38 | +#include <vector> |
| 39 | + |
| 40 | +namespace rocprofiler |
| 41 | +{ |
| 42 | +namespace tool |
| 43 | +{ |
| 44 | +using rocprofiler_host_kernel_symbol_data_t = |
| 45 | + rocprofiler_callback_tracing_code_object_host_kernel_symbol_register_data_t; |
| 46 | + |
| 47 | +struct host_function_info : rocprofiler_host_kernel_symbol_data_t |
| 48 | +{ |
| 49 | + using base_type = rocprofiler_host_kernel_symbol_data_t; |
| 50 | + |
| 51 | + template <typename FuncT> |
| 52 | + host_function_info(const base_type& _base, FuncT&& _formatter) |
| 53 | + : base_type{_base} |
| 54 | + , formatted_host_function_name{_formatter(CHECK_NOTNULL(_base.device_function))} |
| 55 | + , demangled_host_function_name{common::cxx_demangle(CHECK_NOTNULL(_base.device_function))} |
| 56 | + , truncated_host_function_name{common::truncate_name(demangled_host_function_name)} |
| 57 | + {} |
| 58 | + |
| 59 | + host_function_info(); |
| 60 | + ~host_function_info() = default; |
| 61 | + host_function_info(const host_function_info&) = default; |
| 62 | + host_function_info(host_function_info&&) noexcept = default; |
| 63 | + host_function_info& operator=(const host_function_info&) = default; |
| 64 | + host_function_info& operator=(host_function_info&&) noexcept = default; |
| 65 | + |
| 66 | + std::string formatted_host_function_name = {}; |
| 67 | + std::string demangled_host_function_name = {}; |
| 68 | + std::string truncated_host_function_name = {}; |
| 69 | +}; |
| 70 | + |
| 71 | +using host_function_data_vec_t = std::vector<host_function_info>; |
| 72 | +using host_function_info_map_t = std::unordered_map<uint64_t, host_function_info>; |
| 73 | +} // namespace tool |
| 74 | +} // namespace rocprofiler |
| 75 | + |
| 76 | +namespace cereal |
| 77 | +{ |
| 78 | +#define SAVE_DATA_FIELD(FIELD) ar(make_nvp(#FIELD, data.FIELD)) |
| 79 | + |
| 80 | +template <typename ArchiveT> |
| 81 | +void |
| 82 | +save(ArchiveT& ar, const ::rocprofiler::tool::host_function_info& data) |
| 83 | +{ |
| 84 | + cereal::save( |
| 85 | + ar, static_cast<const ::rocprofiler::tool::rocprofiler_host_kernel_symbol_data_t&>(data)); |
| 86 | + SAVE_DATA_FIELD(formatted_host_function_name); |
| 87 | + SAVE_DATA_FIELD(demangled_host_function_name); |
| 88 | + SAVE_DATA_FIELD(truncated_host_function_name); |
| 89 | +} |
| 90 | + |
| 91 | +#undef SAVE_DATA_FIELD |
| 92 | +} // namespace cereal |
0 commit comments