Files
rocm-systems/projects/rocprofiler-systems/source/lib/rocprof-sys/regions.cpp
T

忽略 .git-blame-ignore-revs 中的修訂。點擊 這裡 以繞過並查看正常的 Blame 視圖。

180 行
6.5 KiB
C++
原始文件 標準檢視 歷史記錄

2022-11-16 09:48:15 -06:00
// MIT License
//
2025-01-15 13:06:12 -05:00
// Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All Rights Reserved.
2022-11-16 09:48:15 -06:00
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "api.hpp"
#include "core/categories.hpp"
#include "core/config.hpp"
2022-11-16 09:48:15 -06:00
#include "library/components/category_region.hpp"
#include "library/tracing.hpp"
#if defined(__GNUC__) && (__GNUC__ == 7)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
namespace rocprofsys
2022-11-16 09:48:15 -06:00
{
namespace impl
{
namespace
{
template <size_t Idx, size_t... Tail>
void
invoke_category_region_start(rocprofsys_category_t _category, const char* name,
rocprofsys_annotation_t* _annotations,
2022-11-16 09:48:15 -06:00
size_t _annotation_count, std::index_sequence<Idx, Tail...>)
{
static_assert(Idx > ROCPROFSYS_CATEGORY_NONE && Idx < ROCPROFSYS_CATEGORY_LAST,
2022-11-16 09:48:15 -06:00
"Error! index sequence should only contain values which are greater "
"than ROCPROFSYS_CATEGORY_NONE and less than ROCPROFSYS_CATEGORY_LAST");
2022-11-16 09:48:15 -06:00
if(_category == Idx)
{
using category_type = category_type_id_t<Idx>;
// skip if category is disabled
if(!trait::runtime_enabled<category_type>::get()) return;
component::category_region<category_type>::start(
name, [&](::perfetto::EventContext ctx) {
if(_annotations && config::get_perfetto_annotations())
{
for(size_t i = 0; i < _annotation_count; ++i)
tracing::add_perfetto_annotation(ctx, _annotations[i]);
}
});
}
else
{
constexpr size_t remaining = sizeof...(Tail);
if constexpr(remaining > 0)
invoke_category_region_start(_category, name, _annotations, _annotation_count,
std::index_sequence<Tail...>{});
}
}
template <size_t Idx, size_t... Tail>
void
invoke_category_region_stop(rocprofsys_category_t _category, const char* name,
rocprofsys_annotation_t* _annotations,
2022-11-16 09:48:15 -06:00
size_t _annotation_count, std::index_sequence<Idx, Tail...>)
{
static_assert(Idx > ROCPROFSYS_CATEGORY_NONE && Idx < ROCPROFSYS_CATEGORY_LAST,
2022-11-16 09:48:15 -06:00
"Error! index sequence should only contain values which are greater "
"than ROCPROFSYS_CATEGORY_NONE and less than ROCPROFSYS_CATEGORY_LAST");
2022-11-16 09:48:15 -06:00
if(_category == Idx)
{
using category_type = category_type_id_t<Idx>;
// skip if category is disabled
if(!trait::runtime_enabled<category_type>::get()) return;
component::category_region<category_type>::stop(
name, [&](::perfetto::EventContext ctx) {
if(_annotations && config::get_perfetto_annotations())
{
for(size_t i = 0; i < _annotation_count; ++i)
tracing::add_perfetto_annotation(ctx, _annotations[i]);
}
});
}
else
{
constexpr size_t remaining = sizeof...(Tail);
if constexpr(remaining > 0)
invoke_category_region_stop(_category, name, _annotations, _annotation_count,
std::index_sequence<Tail...>{});
}
}
} // namespace
} // namespace impl
} // namespace rocprofsys
2022-11-16 09:48:15 -06:00
//======================================================================================//
extern "C" void
rocprofsys_push_trace_hidden(const char* name)
2022-11-16 09:48:15 -06:00
{
rocprofsys::component::category_region<rocprofsys::category::host>::start(name);
2022-11-16 09:48:15 -06:00
}
extern "C" void
rocprofsys_pop_trace_hidden(const char* name)
2022-11-16 09:48:15 -06:00
{
rocprofsys::component::category_region<rocprofsys::category::host>::stop(name);
2022-11-16 09:48:15 -06:00
}
extern "C" void
rocprofsys_flush_pending_region_cache_hidden()
{
flush_pending_cached_entries();
}
2022-11-16 09:48:15 -06:00
//======================================================================================//
///
///
///
//======================================================================================//
extern "C" void
rocprofsys_push_region_hidden(const char* name)
2022-11-16 09:48:15 -06:00
{
rocprofsys::component::category_region<rocprofsys::category::user>::start(name);
2022-11-16 09:48:15 -06:00
}
extern "C" void
rocprofsys_pop_region_hidden(const char* name)
2022-11-16 09:48:15 -06:00
{
rocprofsys::component::category_region<rocprofsys::category::user>::stop(name);
2022-11-16 09:48:15 -06:00
}
//======================================================================================//
///
///
///
//======================================================================================//
extern "C" void
rocprofsys_push_category_region_hidden(rocprofsys_category_t _category, const char* name,
rocprofsys_annotation_t* _annotations,
size_t _annotation_count)
2022-11-16 09:48:15 -06:00
{
rocprofsys::impl::invoke_category_region_start(
2022-11-16 09:48:15 -06:00
_category, name, _annotations, _annotation_count,
rocprofsys::utility::make_index_sequence_range<1, ROCPROFSYS_CATEGORY_LAST>{});
2022-11-16 09:48:15 -06:00
}
extern "C" void
rocprofsys_pop_category_region_hidden(rocprofsys_category_t _category, const char* name,
rocprofsys_annotation_t* _annotations,
size_t _annotation_count)
2022-11-16 09:48:15 -06:00
{
rocprofsys::impl::invoke_category_region_stop(
2022-11-16 09:48:15 -06:00
_category, name, _annotations, _annotation_count,
rocprofsys::utility::make_index_sequence_range<1, ROCPROFSYS_CATEGORY_LAST>{});
2022-11-16 09:48:15 -06:00
}
#if defined(__GNUC__) && (__GNUC__ == 7)
# pragma GCC diagnostic pop
#endif