Perfetto traces from cached data (#1704)

## Motivation

The idea is to unify the way and place where we store our traces. Current implementation uses `trace_cache` for rocpd traces, but perfetto is in lined inside of each module. This change allows us to have a single point in code where we will collect data, process it and store it in the desired format. This means that we can declutter the code further and have single point of responsibility and single point of failure.

## Technical Details

New `processor` (perfetto_post_processing.cpp) is added to the `trace_cache` which purpose is to use the cached data to populate perfetto tracks. Cache manager is responsible for keeping the instance of this processor and for its lifetime.
Este commit está contenido en:
marantic-amd
2025-12-01 15:59:16 +01:00
cometido por GitHub
padre b506c75f28
commit 3b11e01716
Se han modificado 22 ficheros con 1889 adiciones y 178 borrados
@@ -321,6 +321,10 @@ configure_settings(bool _init)
ROCPROFSYS_CONFIG_SETTING(bool, "ROCPROFSYS_USE_ROCPD", "Enable rocpd backend", false,
"backend", "rocpd");
ROCPROFSYS_CONFIG_SETTING(bool, "ROCPROFSYS_TRACE_CACHED",
"Enable perfetto with trace cache", false, "backend",
"perfetto_caching");
ROCPROFSYS_CONFIG_SETTING(bool, "ROCPROFSYS_USE_ROCM",
"Enable ROCm API and kernel tracing", true, "backend",
"rocm");
@@ -711,6 +715,11 @@ configure_settings(bool _init)
"written to a file and re-loaded during finalization",
true, "io", "data", "advanced");
ROCPROFSYS_CONFIG_SETTING(bool, "ROCPROFSYS_MERGE_PERFETTO_FILES",
"Merge Perfetto traces. If not explicitly set, it will "
"default to the value of ROCPROFSYS_COLLAPSE_PROCESSES",
false, "perfetto", "data", "advanced");
ROCPROFSYS_CONFIG_SETTING(
std::string, "ROCPROFSYS_TMPDIR", "Base directory for temporary files",
get_env<std::string>("TMPDIR", "/tmp"), "io", "data", "advanced");
@@ -2370,6 +2379,13 @@ get_use_tmp_files()
return static_cast<tim::tsettings<bool>&>(*_v->second).get();
}
bool
get_merge_perfetto_files()
{
static auto _v = get_config()->find("ROCPROFSYS_MERGE_PERFETTO_FILES");
return static_cast<tim::tsettings<bool>&>(*_v->second).get();
}
std::string
get_tmpdir()
{
@@ -2404,6 +2420,51 @@ get_database_absolute_path(std::string_view database_name, std::string_view suff
return _val;
}
std::string
get_perfetto_output_filename_with_suffix(std::string_view suffix)
{
static auto _v = get_config()->find("ROCPROFSYS_PERFETTO_FILE");
auto _val = static_cast<tim::tsettings<std::string>&>(*_v->second).get();
// If absolute path is provided, return it as-is
if(!_val.empty() && _val.at(0) == '/') return _val;
auto _pos_dir = _val.find_last_of('/');
auto _dir = std::string{};
auto _ext = std::string{ "proto" };
if(_pos_dir != std::string::npos)
{
_dir = _val.substr(0, _pos_dir + 1);
_val = _val.substr(_pos_dir + 1);
}
auto _pos_ext = _val.find_last_of('.');
if(_pos_ext + 1 < _val.length())
{
_ext = _val.substr(_pos_ext + 1);
_val = _val.substr(0, _pos_ext);
}
// Check if explicitly set via environment OR config file
// If explicitly set, don't add suffix; otherwise use provided suffix
bool _explicitly_set =
(_v->second->get_environ_updated() || _v->second->get_config_updated());
auto _cfg = settings::compose_filename_config{
!_explicitly_set && !suffix.empty(), // use_suffix only if not explicitly set
suffix, // suffix value
true, // make_dir
_dir // explicit_path
};
_val = settings::compose_output_filename(_val, _ext, _cfg);
if(!_val.empty() && _val.at(0) != '/')
return settings::format(JOIN('/', "%env{PWD}%", _val), get_config()->get_tag());
return _val;
}
bool&
get_use_rocpd()
{
@@ -2411,6 +2472,13 @@ get_use_rocpd()
return static_cast<tim::tsettings<bool>&>(*_v).get();
}
bool&
get_caching_perfetto()
{
static auto _v = get_config()->at("ROCPROFSYS_TRACE_CACHED");
return static_cast<tim::tsettings<bool>&>(*_v).get();
}
tmp_file::tmp_file(std::string _v)
: filename{ std::move(_v) }
{}