ROCpd support [Part 2] (#109)
* Rocpd part 2, caching * Fix shadowed variables * backward compatibility * Fixed designated initializers * Fix timemory include * Remove benchmark & Fix build issues for rhel * Add missing bracket * Fix shadowing and pedantic * Fix pedantic pt2 * Fix duplicated SDK calls * Add decay in get_size_impl * Rename sample cache to trace cache * Add cache storage supported types * Resolving track naming in sampling module * fix sampling of flushing thread * fix sampling of flushing thread 2 * throw exception upon store while buffer storage is not running * Prevent fork crashing * Fix rebase issue * Applied suggestions from code review * Change flushing thread to use PTL * Fix agent creation order * Fix stream id ci throw * Remove force setup of rocprofiler-sdk * Code cleanup * Change initialization for agent * Add missing namespace * Fix the mismatch within the tool_agent->device_id * Switch from using handle to use agent type index * Fix pmc info comparator in metadata registry --------- Co-authored-by: Aleksandar <aleksandar.djordjevic@amd.com> Co-authored-by: Milan Radosavljevic <milan.radosavljevic@amd.com> Co-authored-by: Marjan Antic <marantic@amd.com>
This commit is contained in:
committed by
GitHub
parent
351d598869
commit
1f86010ca2
+139
-141
@@ -23,6 +23,7 @@
|
||||
#include "library/components/backtrace_metrics.hpp"
|
||||
#include "core/agent.hpp"
|
||||
#include "core/agent_manager.hpp"
|
||||
#include "core/common.hpp"
|
||||
#include "core/components/fwd.hpp"
|
||||
#include "core/config.hpp"
|
||||
#include "core/debug.hpp"
|
||||
@@ -167,7 +168,141 @@ get_enabled(tim::type_list<Tp...>)
|
||||
(_v.set(_n++, trait::runtime_enabled<Tp>::get()), ...);
|
||||
return _v;
|
||||
}
|
||||
|
||||
void
|
||||
rocpd_init_categories()
|
||||
{
|
||||
static bool _is_initialized = false;
|
||||
if(_is_initialized) return;
|
||||
|
||||
auto& data_processor = get_data_processor();
|
||||
|
||||
data_processor.insert_string(trait::name<category::thread_cpu_time>::value);
|
||||
data_processor.insert_string(trait::name<category::thread_peak_memory>::value);
|
||||
data_processor.insert_string(trait::name<category::thread_context_switch>::value);
|
||||
data_processor.insert_string(trait::name<category::thread_page_fault>::value);
|
||||
data_processor.insert_string(trait::name<category::thread_hardware_counter>::value);
|
||||
|
||||
_is_initialized = true;
|
||||
}
|
||||
|
||||
template <typename Category>
|
||||
void
|
||||
rocpd_init_tracks(int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto& n_info = node_info::get_instance();
|
||||
const auto& t_info = thread_info::get(_tid, SequentTID);
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
|
||||
auto thread_idx = data_processor.insert_thread_info(
|
||||
n_info.id, getppid(), getpid(), t_info->index_data->system_value,
|
||||
JOIN(" ", "Thread", _tid).c_str(), t_info->get_start(), t_info->get_stop(), "{}");
|
||||
|
||||
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
|
||||
{
|
||||
// Initialize hw_counter_tracks and create one track for each 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;
|
||||
ROCPROFSYS_CI_THROW(_desc.empty(), "Empty description for %s\n", itr.c_str());
|
||||
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
data_processor.insert_track(track_name.c_str(), n_info.id, getpid(),
|
||||
thread_idx, "{}");
|
||||
}
|
||||
}
|
||||
else
|
||||
data_processor.insert_track(
|
||||
JOIN('_', trait::name<Category>::value, _tid_name).c_str(), n_info.id,
|
||||
getpid(), thread_idx, "{}");
|
||||
}
|
||||
|
||||
template <typename Category>
|
||||
void
|
||||
rocpd_initialize_backtrace_metrics_pmc(size_t dev_id, const char* units, int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
|
||||
size_t EVENT_CODE = 0;
|
||||
size_t INSTANCE_ID = 0;
|
||||
const char* LONG_DESCRIPTION = "";
|
||||
const char* COMPONENT = "";
|
||||
const char* BLOCK = "";
|
||||
const char* EXPRESSION = "";
|
||||
auto ni = node_info::get_instance();
|
||||
const auto TARGET_ARCH = "CPU";
|
||||
|
||||
auto& agent_mngr = agent_manager::get_instance();
|
||||
auto base_id = agent_mngr.get_agent_by_id(dev_id, agent_type::CPU).base_id;
|
||||
|
||||
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;
|
||||
ROCPROFSYS_CI_THROW(_desc.empty(), "Empty description for %s\n", itr.c_str());
|
||||
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
|
||||
data_processor.insert_pmc_description(
|
||||
ni.id, getpid(), base_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID,
|
||||
track_name.c_str(), trait::name<Category>::value,
|
||||
trait::name<Category>::description, LONG_DESCRIPTION, COMPONENT, units,
|
||||
"ABS", BLOCK, EXPRESSION, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
data_processor.insert_pmc_description(
|
||||
ni.id, getpid(), base_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID,
|
||||
JOIN("_", trait::name<Category>::value, _tid_name).c_str(),
|
||||
trait::name<Category>::value, trait::name<Category>::description,
|
||||
LONG_DESCRIPTION, COMPONENT, units, "ABS", BLOCK, EXPRESSION, 0, 0);
|
||||
}
|
||||
|
||||
template <typename Category, typename Value>
|
||||
void
|
||||
rocpd_process_backtrace_metrics_events(const uint32_t device_id, uint64_t timestamp,
|
||||
Value value, int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
|
||||
auto string_primary_key = data_processor.insert_string(trait::name<Category>::value);
|
||||
auto event_id = data_processor.insert_event(string_primary_key, 0, 0, 0);
|
||||
auto& agent_mngr = agent_manager::get_instance();
|
||||
auto base_id = agent_mngr.get_agent_by_id(device_id, agent_type::CPU).base_id;
|
||||
|
||||
auto insert_event_and_sample = [&](const char* _name, double _value) {
|
||||
data_processor.insert_pmc_event(event_id, base_id, _name, _value);
|
||||
data_processor.insert_sample(_name, timestamp, event_id);
|
||||
};
|
||||
|
||||
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
|
||||
{
|
||||
auto _hw_cnt_labels = *get_papi_labels(_tid);
|
||||
const auto& hw_counters =
|
||||
static_cast<backtrace_metrics::hw_counter_data_t>(value);
|
||||
for(size_t i = 0; i < _hw_cnt_labels.size() && i < hw_counters.size(); ++i)
|
||||
{
|
||||
std::string _desc = tim::papi::get_event_info(_hw_cnt_labels[i]).short_descr;
|
||||
if(_desc.empty()) _desc = _hw_cnt_labels[i];
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
|
||||
insert_event_and_sample(track_name.c_str(), hw_counters.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
insert_event_and_sample(
|
||||
JOIN("_", trait::name<Category>::value, _tid_name).c_str(), value);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void
|
||||
backtrace_metrics::sample(int)
|
||||
{
|
||||
@@ -337,146 +472,6 @@ backtrace_metrics::fini_perfetto(int64_t _tid, valid_array_t _valid)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rocpd_init_categories()
|
||||
{
|
||||
static bool _is_initialized = false;
|
||||
if(_is_initialized) return;
|
||||
|
||||
get_data_processor().insert_category(
|
||||
category_enum_id<category::thread_cpu_time>::value,
|
||||
trait::name<category::thread_cpu_time>::value);
|
||||
get_data_processor().insert_category(
|
||||
category_enum_id<category::thread_peak_memory>::value,
|
||||
trait::name<category::thread_peak_memory>::value);
|
||||
get_data_processor().insert_category(
|
||||
category_enum_id<category::thread_context_switch>::value,
|
||||
trait::name<category::thread_context_switch>::value);
|
||||
get_data_processor().insert_category(
|
||||
category_enum_id<category::thread_page_fault>::value,
|
||||
trait::name<category::thread_page_fault>::value);
|
||||
get_data_processor().insert_category(
|
||||
category_enum_id<category::thread_hardware_counter>::value,
|
||||
trait::name<category::thread_hardware_counter>::value);
|
||||
|
||||
_is_initialized = true;
|
||||
}
|
||||
|
||||
template <typename Category>
|
||||
void
|
||||
rocpd_init_tracks(int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto& n_info = node_info::get_instance();
|
||||
const auto& t_info = thread_info::get(_tid, SequentTID);
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
|
||||
auto thread_idx = data_processor.insert_thread_info(
|
||||
n_info.id, getppid(), getpid(), t_info->index_data->system_value,
|
||||
JOIN(" ", "Thread", _tid).c_str(), t_info->get_start(), t_info->get_stop(), "{}");
|
||||
|
||||
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
|
||||
{
|
||||
// Initialize hw_counter_tracks and create one track for each 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;
|
||||
ROCPROFSYS_CI_THROW(_desc.empty(), "Empty description for %s\n", itr.c_str());
|
||||
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
data_processor.insert_track(track_name.c_str(), n_info.id, getpid(),
|
||||
thread_idx, "{}");
|
||||
}
|
||||
}
|
||||
else
|
||||
data_processor.insert_track(
|
||||
JOIN('_', trait::name<Category>::value, _tid_name).c_str(), n_info.id,
|
||||
getpid(), thread_idx, "{}");
|
||||
}
|
||||
|
||||
template <typename Category>
|
||||
void
|
||||
rocpd_initialize_backtrace_metrics_pmc(size_t dev_id, const char* units, int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
|
||||
size_t EVENT_CODE = 0;
|
||||
size_t INSTANCE_ID = 0;
|
||||
const char* LONG_DESCRIPTION = "";
|
||||
const char* COMPONENT = "";
|
||||
const char* BLOCK = "";
|
||||
const char* EXPRESSION = "";
|
||||
auto ni = node_info::get_instance();
|
||||
const auto* TARGET_ARCH = "CPU";
|
||||
|
||||
auto& _agent_manager = agent_manager::get_instance();
|
||||
auto _base_id = _agent_manager.get_agent_by_id(dev_id, agent_type::CPU).base_id;
|
||||
|
||||
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;
|
||||
ROCPROFSYS_CI_THROW(_desc.empty(), "Empty description for %s\n", itr.c_str());
|
||||
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
|
||||
data_processor.insert_pmc_description(
|
||||
ni.id, getpid(), _base_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID,
|
||||
track_name.c_str(), trait::name<Category>::value,
|
||||
trait::name<Category>::description, LONG_DESCRIPTION, COMPONENT, units,
|
||||
"ABS", BLOCK, EXPRESSION, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
data_processor.insert_pmc_description(
|
||||
ni.id, getpid(), _base_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID,
|
||||
JOIN("_", trait::name<Category>::value, _tid_name).c_str(),
|
||||
trait::name<Category>::value, trait::name<Category>::description,
|
||||
LONG_DESCRIPTION, COMPONENT, units, "ABS", BLOCK, EXPRESSION, 0, 0);
|
||||
}
|
||||
|
||||
template <typename Category, typename Value>
|
||||
void
|
||||
rocpd_process_backtrace_metrics_events(const uint32_t device_id, uint64_t timestamp,
|
||||
Value value, int64_t _tid)
|
||||
{
|
||||
auto& data_processor = get_data_processor();
|
||||
auto _tid_name = JOIN("", '[', _tid, ']');
|
||||
auto event_id =
|
||||
data_processor.insert_event(category_enum_id<Category>::value, 0, 0, 0);
|
||||
auto& agent_mngr = agent_manager::get_instance();
|
||||
auto base_id = agent_mngr.get_agent_by_id(device_id, agent_type::CPU).base_id;
|
||||
|
||||
auto insert_event_and_sample = [&](const char* name, double _value) {
|
||||
data_processor.insert_pmc_event(event_id, base_id, name, _value);
|
||||
data_processor.insert_sample(name, timestamp, event_id);
|
||||
};
|
||||
|
||||
if constexpr(std::is_same_v<Category, category::thread_hardware_counter>)
|
||||
{
|
||||
auto _hw_cnt_labels = *get_papi_labels(_tid);
|
||||
const auto& _hw_counters =
|
||||
static_cast<backtrace_metrics::hw_counter_data_t>(value);
|
||||
for(size_t i = 0; i < _hw_cnt_labels.size() && i < _hw_counters.size(); ++i)
|
||||
{
|
||||
std::string _desc = tim::papi::get_event_info(_hw_cnt_labels[i]).short_descr;
|
||||
if(_desc.empty()) _desc = _hw_cnt_labels[i];
|
||||
std::string track_name = JOIN(' ', "Thread", _desc, _tid_name, "(S)");
|
||||
|
||||
insert_event_and_sample(track_name.c_str(), _hw_counters.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
insert_event_and_sample(
|
||||
JOIN("_", trait::name<Category>::value, _tid_name).c_str(), value);
|
||||
}
|
||||
|
||||
void
|
||||
backtrace_metrics::init_rocpd(int64_t _tid, valid_array_t _valid)
|
||||
{
|
||||
@@ -641,8 +636,10 @@ backtrace_metrics::post_process_perfetto(int64_t _tid, uint64_t _ts) const
|
||||
}
|
||||
|
||||
void
|
||||
backtrace_metrics::post_process_rocpd(int64_t _tid, uint64_t _ts) const
|
||||
backtrace_metrics::post_process_rocpd([[maybe_unused]] int64_t _tid,
|
||||
[[maybe_unused]] uint64_t _ts) const
|
||||
{
|
||||
#if ROCPROFSYS_USE_ROCM > 0
|
||||
auto is_category_enabled = [&](const auto& _category) { return (*this)(_category); };
|
||||
|
||||
if(is_category_enabled(category::thread_cpu_time{}))
|
||||
@@ -675,6 +672,7 @@ backtrace_metrics::post_process_rocpd(int64_t _tid, uint64_t _ts) const
|
||||
hw_counter_data_t>(0, _ts, m_hw_counter,
|
||||
_tid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace component
|
||||
} // namespace rocprofsys
|
||||
|
||||
Reference in New Issue
Block a user