Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

648 خطوط
22 KiB
C++

2022-08-31 01:24:31 -05:00
// MIT License
//
2025-01-15 13:06:12 -05:00
// Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All Rights Reserved.
2022-08-31 01:24:31 -05: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 "library/components/backtrace_metrics.hpp"
2025-08-19 22:01:04 -04:00
#include "core/common.hpp"
#include "core/components/fwd.hpp"
#include "core/config.hpp"
#include "core/perfetto.hpp"
#include "core/trace_cache/cache_manager.hpp"
#include "core/trace_cache/cacheable.hpp"
#include "core/trace_cache/metadata_registry.hpp"
2022-08-31 01:24:31 -05:00
#include "library/components/ensure_storage.hpp"
#include "library/ptl.hpp"
#include "library/runtime.hpp"
#include "library/thread_info.hpp"
#include "library/tracing.hpp"
#include <functional>
2022-08-31 01:24:31 -05:00
#include <timemory/backends/papi.hpp>
#include <timemory/backends/threading.hpp>
#include <timemory/components/data_tracker/components.hpp>
#include <timemory/components/macros.hpp>
#include <timemory/components/papi/extern.hpp>
#include <timemory/components/papi/papi_array.hpp>
#include <timemory/components/papi/papi_vector.hpp>
#include <timemory/components/rusage/components.hpp>
#include <timemory/components/rusage/types.hpp>
#include <timemory/components/timing/backends.hpp>
#include <timemory/components/trip_count/extern.hpp>
#include <timemory/macros.hpp>
#include <timemory/math.hpp>
#include <timemory/mpl.hpp>
#include <timemory/mpl/quirks.hpp>
#include <timemory/mpl/type_traits.hpp>
2023-02-03 14:10:42 -06:00
#include <timemory/mpl/types.hpp>
2022-08-31 01:24:31 -05:00
#include <timemory/operations.hpp>
#include <timemory/storage.hpp>
#include <timemory/units.hpp>
#include <timemory/utility/backtrace.hpp>
#include <timemory/utility/demangle.hpp>
#include <timemory/utility/types.hpp>
#include <timemory/variadic.hpp>
#include "logger/debug.hpp"
2022-08-31 01:24:31 -05:00
#include <array>
#include <cstring>
#include <ctime>
#include <initializer_list>
#include <mutex>
#include <regex>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
#include <pthread.h>
#include <signal.h>
namespace tracing
{
using namespace ::rocprofsys::tracing;
2022-08-31 01:24:31 -05:00
}
namespace rocprofsys
2022-08-31 01:24:31 -05:00
{
namespace component
{
using hw_counters = typename backtrace_metrics::hw_counters;
using signal_type_instances = thread_data<std::set<int>, category::sampling>;
using backtrace_metrics_init_instances =
thread_data<backtrace_metrics, category::sampling>;
using sampler_running_instances = thread_data<bool, category::sampling>;
using papi_vector_instances = thread_data<hw_counters, category::sampling>;
using papi_label_instances = thread_data<std::vector<std::string>, category::sampling>;
namespace
{
struct perfetto_rusage
{};
unique_ptr_t<std::vector<std::string>>&
get_papi_labels(int64_t _tid)
{
2023-10-16 18:04:47 -05:00
return papi_label_instances::instance(construct_on_thread{ _tid });
2022-08-31 01:24:31 -05:00
}
unique_ptr_t<hw_counters>&
get_papi_vector(int64_t _tid)
{
2023-10-16 18:04:47 -05:00
return papi_vector_instances::instance(construct_on_thread{ _tid });
2022-08-31 01:24:31 -05:00
}
unique_ptr_t<backtrace_metrics>&
get_backtrace_metrics_init(int64_t _tid)
{
2023-10-16 18:04:47 -05:00
return backtrace_metrics_init_instances::instance(construct_on_thread{ _tid });
2022-08-31 01:24:31 -05:00
}
unique_ptr_t<bool>&
get_sampler_running(int64_t _tid)
{
2023-10-16 18:04:47 -05:00
return sampler_running_instances::instance(construct_on_thread{ _tid }, false);
2022-08-31 01:24:31 -05:00
}
} // namespace
std::string
backtrace_metrics::label()
{
return "backtrace_metrics";
}
std::string
backtrace_metrics::description()
{
return "Records sampling data";
}
2022-11-17 08:43:45 -06:00
std::vector<std::string>
backtrace_metrics::get_hw_counter_labels(int64_t _tid)
{
auto& _v = get_papi_labels(_tid);
return (_v) ? *_v : std::vector<std::string>{};
}
2022-08-31 01:24:31 -05:00
void
backtrace_metrics::start()
{}
void
backtrace_metrics::stop()
{}
2023-02-03 14:10:42 -06:00
namespace
{
template <typename... Tp>
auto
get_enabled(tim::type_list<Tp...>)
2023-02-03 14:10:42 -06:00
{
constexpr size_t N = sizeof...(Tp);
auto _v = std::bitset<N>{};
size_t _n = 0;
(_v.set(_n++, trait::runtime_enabled<Tp>::get()), ...);
return _v;
}
2025-08-19 22:01:04 -04:00
void
metadata_init_categories()
2025-08-19 22:01:04 -04:00
{
static bool _is_initialized = false;
if(_is_initialized) return;
trace_cache::get_metadata_registry().add_string(
trait::name<category::thread_cpu_time>::value);
trace_cache::get_metadata_registry().add_string(
trait::name<category::thread_peak_memory>::value);
trace_cache::get_metadata_registry().add_string(
trait::name<category::thread_context_switch>::value);
trace_cache::get_metadata_registry().add_string(
trait::name<category::thread_page_fault>::value);
trace_cache::get_metadata_registry().add_string(
trait::name<category::thread_hardware_counter>::value);
2025-08-19 22:01:04 -04:00
_is_initialized = true;
}
template <typename Category>
void
apply_for_all_thread_names(int64_t _tid, std::function<void(const std::string&)> _apply)
2025-08-19 22:01:04 -04:00
{
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
{
auto _hw_cnt_labels = *get_papi_labels(_tid);
for(auto& itr : _hw_cnt_labels)
{
std::string _desc = tim::papi::get_event_info(itr).short_descr;
if(_desc.empty()) _desc = itr;
if(get_is_continuous_integration() && _desc.empty())
{
throw std::runtime_error(
fmt::format("Empty description for {}", itr.c_str()));
}
2025-08-19 22:01:04 -04:00
std::stringstream track_name_ss;
track_name_ss << "Thread " << _desc << " [" << _tid << "] (S)";
_apply(track_name_ss.str());
2025-08-19 22:01:04 -04:00
}
}
else
{
std::stringstream track_name_ss;
track_name_ss << trait::name<Category>::value << " [" << _tid << "]";
_apply(track_name_ss.str());
}
2025-08-19 22:01:04 -04:00
}
template <typename Category>
void
metadata_init_tracks(int64_t _tid)
2025-08-19 22:01:04 -04:00
{
const auto& t_info = thread_info::get(_tid, SequentTID);
auto thread_id = static_cast<uint64_t>(t_info->index_data->system_value);
2025-08-19 22:01:04 -04:00
trace_cache::get_metadata_registry().add_thread_info(
{ getppid(), getpid(), thread_id, static_cast<uint32_t>(t_info->get_start()),
static_cast<uint32_t>(t_info->get_stop()), "{}" });
2025-08-19 22:01:04 -04:00
apply_for_all_thread_names<Category>(_tid, [&](const std::string& _track_name) {
trace_cache::get_metadata_registry().add_track({ _track_name, thread_id, "{}" });
});
}
2025-08-19 22:01:04 -04:00
template <typename Category>
void
metadata_initialize_backtrace_metrics_pmc(size_t dev_id, const char* _units, int64_t _tid)
{
constexpr size_t EVENT_CODE = 0;
constexpr size_t INSTANCE_ID = 0;
const char* LONG_DESCRIPTION = "";
const char* COMPONENT = "";
const char* BLOCK = "";
const char* EXPRESSION = "";
const char* TARGET_ARCH = "CPU";
apply_for_all_thread_names<Category>(_tid, [&](const std::string& _track_name) {
trace_cache::get_metadata_registry().add_pmc_info(
{ agent_type::CPU, dev_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID, _track_name,
trait::name<Category>::value, trait::name<Category>::description,
LONG_DESCRIPTION, COMPONENT, _units, trace_cache::ABSOLUTE, BLOCK,
EXPRESSION, 0, 0, "{}" });
});
2025-08-19 22:01:04 -04:00
}
template <typename Category, typename Value>
void
cache_backtrace_metrics_events(const uint32_t device_id, uint64_t timestamp_ns,
Value value, int64_t _tid)
2025-08-19 22:01:04 -04:00
{
auto _tid_name = fmt::format("[{}]", _tid);
size_t stack_id = 0;
size_t parent_stack_id = 0;
size_t correlation_id = 0;
const auto* event_metadata = "";
const auto* call_stack = "";
const auto* line_info = "";
auto insert_event_and_sample = [&](const char* _track_name, double _value) {
trace_cache::get_buffer_storage().store(trace_cache::pmc_event_with_sample{
2025-12-01 15:59:16 +01:00
static_cast<size_t>(category_enum_id<Category>::value), _track_name,
timestamp_ns, event_metadata, stack_id, parent_stack_id, correlation_id,
call_stack, line_info, device_id, static_cast<uint8_t>(agent_type::CPU),
_track_name, _value });
2025-08-19 22:01:04 -04:00
};
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
{
const auto& hw_counters =
static_cast<backtrace_metrics::hw_counter_data_t>(value);
size_t idx = 0;
apply_for_all_thread_names<Category>(_tid, [&](const std::string& _track_name) {
if(idx < hw_counters.size())
{
insert_event_and_sample(_track_name.c_str(), hw_counters.at(idx));
}
++idx;
});
2025-08-19 22:01:04 -04:00
}
else
{
apply_for_all_thread_names<Category>(_tid, [&](const std::string& _track_name) {
insert_event_and_sample(_track_name.c_str(), value);
});
}
2025-08-19 22:01:04 -04:00
}
2023-02-03 14:10:42 -06:00
} // namespace
2025-08-19 22:01:04 -04:00
2022-08-31 01:24:31 -05:00
void
backtrace_metrics::sample(int)
{
2023-02-03 14:10:42 -06:00
if(!get_enabled(type_list<category::process_sampling, backtrace_metrics>{}).all())
{
m_valid.reset();
return;
}
m_valid = get_enabled(categories_t{});
// return if everything is disabled
if(!m_valid.any()) return;
2022-08-31 01:24:31 -05:00
auto _cache = tim::rusage_cache{ RUSAGE_THREAD };
m_cpu = tim::get_clock_thread_now<int64_t, std::nano>();
m_mem_peak = _cache.get_peak_rss();
m_ctx_swch = _cache.get_num_priority_context_switch() +
_cache.get_num_voluntary_context_switch();
m_page_flt = _cache.get_num_major_page_faults() + _cache.get_num_minor_page_faults();
if constexpr(tim::trait::is_available<hw_counters>::value)
{
2023-02-03 14:10:42 -06:00
constexpr auto hw_counters_idx = tim::index_of<hw_counters, categories_t>::value;
constexpr auto hw_category_idx =
tim::index_of<category::thread_hardware_counter, categories_t>::value;
auto _tid = threading::get_id();
if(m_valid.test(hw_category_idx) && m_valid.test(hw_counters_idx))
2022-08-31 01:24:31 -05:00
{
assert(get_papi_vector(_tid).get() != nullptr);
m_hw_counter = get_papi_vector(_tid)->record();
}
}
}
void
backtrace_metrics::configure(bool _setup, int64_t _tid)
{
auto& _running = get_sampler_running(_tid);
bool _is_running = (!_running) ? false : *_running;
ensure_storage<comp::trip_count, sampling_wall_clock, sampling_cpu_clock, hw_counters,
sampling_percent>{}();
if(_setup && !_is_running)
{
(void) get_debug_sampling(); // make sure query in sampler does not allocate
assert(_tid == threading::get_id());
if constexpr(tim::trait::is_available<hw_counters>::value)
{
perfetto_counter_track<hw_counters>::init();
LOG_DEBUG("HW COUNTER: starting...");
2022-08-31 01:24:31 -05:00
if(get_papi_vector(_tid))
{
get_papi_vector(_tid)->start();
2022-11-17 08:43:45 -06:00
*get_papi_labels(_tid) = get_papi_vector(_tid)->get_config()->labels;
2022-08-31 01:24:31 -05:00
}
}
}
else if(!_setup && _is_running)
{
LOG_DEBUG("Destroying sampler for thread {}...", _tid);
2022-08-31 01:24:31 -05:00
*_running = false;
if constexpr(tim::trait::is_available<hw_counters>::value)
{
if(_tid == threading::get_id())
{
if(get_papi_vector(_tid)) get_papi_vector(_tid)->stop();
LOG_DEBUG("HW COUNTER: stopped...");
2022-08-31 01:24:31 -05:00
}
}
LOG_DEBUG("Sampler destroyed for thread {}...", _tid);
2022-08-31 01:24:31 -05:00
}
}
void
2023-02-03 14:10:42 -06:00
backtrace_metrics::init_perfetto(int64_t _tid, valid_array_t _valid)
2022-08-31 01:24:31 -05:00
{
auto _hw_cnt_labels = *get_papi_labels(_tid);
auto _tid_name = fmt::format("[{}]", _tid);
2022-08-31 01:24:31 -05:00
if(!perfetto_counter_track<perfetto_rusage>::exists(_tid))
{
2023-10-16 18:04:47 -05:00
if(get_valid(category::thread_cpu_time{}, _valid))
perfetto_counter_track<perfetto_rusage>::emplace(
_tid, fmt::format("Thread CPU time {} (S)", _tid_name), "sec");
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_peak_memory{}, _valid))
perfetto_counter_track<perfetto_rusage>::emplace(
_tid, fmt::format("Thread Peak Memory Usage {} (S)", _tid_name), "MB");
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_context_switch{}, _valid))
perfetto_counter_track<perfetto_rusage>::emplace(
_tid, fmt::format("Thread Context Switches {} (S)", _tid_name));
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_page_fault{}, _valid))
perfetto_counter_track<perfetto_rusage>::emplace(
_tid, fmt::format("Thread Page Faults {} (S)", _tid_name));
2022-08-31 01:24:31 -05:00
}
if(!perfetto_counter_track<hw_counters>::exists(_tid) &&
2023-02-03 14:10:42 -06:00
get_valid(type_list<hw_counters>{}, _valid) &&
get_valid(category::thread_hardware_counter{}, _valid))
2022-08-31 01:24:31 -05:00
{
for(auto& itr : _hw_cnt_labels)
{
std::string _desc = tim::papi::get_event_info(itr).short_descr;
if(_desc.empty()) _desc = itr;
if(get_is_continuous_integration() && _desc.empty())
{
throw std::runtime_error(
fmt::format("Empty description for {}", itr.c_str()));
}
2022-08-31 01:24:31 -05:00
perfetto_counter_track<hw_counters>::emplace(
_tid, fmt::format("Thread {} {} (S)", _desc, _tid_name));
2022-08-31 01:24:31 -05:00
}
}
}
void
2023-02-03 14:10:42 -06:00
backtrace_metrics::fini_perfetto(int64_t _tid, valid_array_t _valid)
2022-08-31 01:24:31 -05:00
{
auto _hw_cnt_labels = *get_papi_labels(_tid);
2022-09-21 13:58:14 -05:00
const auto& _thread_info = thread_info::get(_tid, SequentTID);
2022-08-31 01:24:31 -05:00
if(get_is_continuous_integration() && !_thread_info)
{
throw std::runtime_error(
fmt::format("Error! missing thread info for tid={}", _tid));
}
2022-08-31 01:24:31 -05:00
if(!_thread_info) return;
2023-10-16 18:04:47 -05:00
uint64_t _ts = _thread_info->get_stop();
uint64_t _rusage_idx = 0;
if(get_valid(category::thread_cpu_time{}, _valid))
{
TRACE_COUNTER(trait::name<category::thread_cpu_time>::value,
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, 0);
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_peak_memory{}, _valid))
{
TRACE_COUNTER(trait::name<category::thread_peak_memory>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, 0);
2023-02-03 14:10:42 -06:00
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_context_switch{}, _valid))
{
TRACE_COUNTER(trait::name<category::thread_context_switch>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, 0);
2023-02-03 14:10:42 -06:00
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if(get_valid(category::thread_page_fault{}, _valid))
{
TRACE_COUNTER(trait::name<category::thread_page_fault>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, 0);
2023-02-03 14:10:42 -06:00
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if(get_valid(type_list<hw_counters>{}, _valid) &&
get_valid(category::thread_hardware_counter{}, _valid))
2022-08-31 01:24:31 -05:00
{
for(size_t i = 0; i < perfetto_counter_track<hw_counters>::size(_tid); ++i)
{
if(i < _hw_cnt_labels.size())
{
2023-02-03 14:10:42 -06:00
TRACE_COUNTER(trait::name<category::thread_hardware_counter>::value,
2022-08-31 01:24:31 -05:00
perfetto_counter_track<hw_counters>::at(_tid, i), _ts, 0.0);
}
}
}
}
2025-07-28 17:33:52 +02:00
void
backtrace_metrics::init_cache(int64_t _tid, valid_array_t _valid)
2025-07-28 17:33:52 +02:00
{
metadata_init_categories();
2025-07-28 17:33:52 +02:00
if(get_valid(category::thread_cpu_time{}, _valid))
{
metadata_init_tracks<category::thread_cpu_time>(_tid);
metadata_initialize_backtrace_metrics_pmc<category::thread_cpu_time>(0, "sec",
2025-07-28 17:33:52 +02:00
_tid);
}
if(get_valid(category::thread_peak_memory{}, _valid))
{
metadata_init_tracks<category::thread_peak_memory>(_tid);
metadata_initialize_backtrace_metrics_pmc<category::thread_peak_memory>(0, "MB",
_tid);
2025-07-28 17:33:52 +02:00
}
if(get_valid(category::thread_context_switch{}, _valid))
{
metadata_init_tracks<category::thread_context_switch>(_tid);
metadata_initialize_backtrace_metrics_pmc<category::thread_context_switch>(0, "",
_tid);
2025-07-28 17:33:52 +02:00
}
if(get_valid(category::thread_page_fault{}, _valid))
{
metadata_init_tracks<category::thread_page_fault>(_tid);
metadata_initialize_backtrace_metrics_pmc<category::thread_page_fault>(0, "",
_tid);
2025-07-28 17:33:52 +02:00
}
if(get_valid(type_list<hw_counters>{}, _valid) &&
get_valid(category::thread_hardware_counter{}, _valid))
{
metadata_init_tracks<category::thread_hardware_counter>(_tid);
metadata_initialize_backtrace_metrics_pmc<category::thread_hardware_counter>(
0, "", _tid);
2025-07-28 17:33:52 +02:00
}
}
backtrace_metrics&
backtrace_metrics::operator-=(const backtrace_metrics& _rhs)
{
auto& _lhs = *this;
2023-10-16 18:04:47 -05:00
if(_lhs(category::thread_cpu_time{}))
{
_lhs.m_cpu -= _rhs.m_cpu;
}
if(_lhs(category::thread_peak_memory{}))
{
_lhs.m_mem_peak -= _rhs.m_mem_peak;
}
if(_lhs(category::thread_context_switch{}))
{
_lhs.m_ctx_swch -= _rhs.m_ctx_swch;
}
if(_lhs(category::thread_page_fault{}))
{
_lhs.m_page_flt -= _rhs.m_page_flt;
}
if(_lhs(type_list<hw_counters>{}) && _lhs(category::thread_hardware_counter{}))
{
for(size_t i = 0; i < _lhs.m_hw_counter.size(); ++i)
_lhs.m_hw_counter.at(i) -= _rhs.m_hw_counter.at(i);
}
return _lhs;
}
2022-08-31 01:24:31 -05:00
void
backtrace_metrics::post_process_perfetto(int64_t _tid, uint64_t _ts) const
{
2023-10-16 18:04:47 -05:00
uint64_t _rusage_idx = 0;
if((*this)(category::thread_cpu_time{}))
{
TRACE_COUNTER(trait::name<category::thread_cpu_time>::value,
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, m_cpu / units::sec);
}
2023-02-03 14:10:42 -06:00
if((*this)(category::thread_peak_memory{}))
{
TRACE_COUNTER(trait::name<category::thread_peak_memory>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, m_mem_peak / units::megabyte);
2023-02-03 14:10:42 -06:00
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if((*this)(category::thread_context_switch{}))
{
TRACE_COUNTER(trait::name<category::thread_context_switch>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, m_ctx_swch);
2023-02-03 14:10:42 -06:00
}
2022-08-31 01:24:31 -05:00
2023-02-03 14:10:42 -06:00
if((*this)(category::thread_page_fault{}))
{
TRACE_COUNTER(trait::name<category::thread_page_fault>::value,
2023-10-16 18:04:47 -05:00
perfetto_counter_track<perfetto_rusage>::at(_tid, _rusage_idx++),
_ts, m_page_flt);
2023-02-03 14:10:42 -06:00
}
2023-02-03 14:10:42 -06:00
if((*this)(type_list<hw_counters>{}) && (*this)(category::thread_hardware_counter{}))
2022-08-31 01:24:31 -05:00
{
for(size_t i = 0; i < perfetto_counter_track<hw_counters>::size(_tid); ++i)
{
if(i < m_hw_counter.size())
{
2023-02-03 14:10:42 -06:00
TRACE_COUNTER(trait::name<category::thread_hardware_counter>::value,
2022-08-31 01:24:31 -05:00
perfetto_counter_track<hw_counters>::at(_tid, i), _ts,
m_hw_counter.at(i));
}
}
}
}
2025-07-28 17:33:52 +02:00
void
backtrace_metrics::cache_backtrace_data([[maybe_unused]] int64_t _tid,
[[maybe_unused]] uint64_t _ts) const
2025-07-28 17:33:52 +02:00
{
2025-08-19 22:01:04 -04:00
#if ROCPROFSYS_USE_ROCM > 0
2025-07-28 17:33:52 +02:00
auto is_category_enabled = [&](const auto& _category) { return (*this)(_category); };
if(is_category_enabled(category::thread_cpu_time{}))
{
cache_backtrace_metrics_events<category::thread_cpu_time, double>(
2025-07-28 17:33:52 +02:00
0, _ts, m_cpu / units::sec, _tid);
}
if(is_category_enabled(category::thread_peak_memory{}))
{
cache_backtrace_metrics_events<category::thread_peak_memory, double>(
2025-07-28 17:33:52 +02:00
0, _ts, m_mem_peak / units::megabyte, _tid);
}
if(is_category_enabled(category::thread_context_switch{}))
{
cache_backtrace_metrics_events<category::thread_context_switch, int64_t>(
2025-07-28 17:33:52 +02:00
0, _ts, m_ctx_swch, _tid);
}
if(is_category_enabled(category::thread_page_fault{}))
{
cache_backtrace_metrics_events<category::thread_page_fault, int64_t>(
2025-07-28 17:33:52 +02:00
0, _ts, m_page_flt, _tid);
}
if(is_category_enabled(type_list<hw_counters>{}) &&
is_category_enabled(category::thread_hardware_counter{}))
{
cache_backtrace_metrics_events<category::thread_hardware_counter,
hw_counter_data_t>(0, _ts, m_hw_counter, _tid);
2025-07-28 17:33:52 +02:00
}
2025-08-19 22:01:04 -04:00
#endif
2025-07-28 17:33:52 +02:00
}
2022-08-31 01:24:31 -05:00
} // namespace component
} // namespace rocprofsys
2022-08-31 01:24:31 -05:00
ROCPROFSYS_INSTANTIATE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_wall_clock>), true,
2022-08-31 01:24:31 -05:00
double)
ROCPROFSYS_INSTANTIATE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_cpu_clock>), true,
2022-08-31 01:24:31 -05:00
double)
ROCPROFSYS_INSTANTIATE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_fraction>), true,
2022-08-31 01:24:31 -05:00
double)
TIMEMORY_INITIALIZE_STORAGE(rocprofsys::component::backtrace_metrics)