Skip to content

Commit 6d42b29

Browse files
Add missing counter events handling for ROCPD (#1305)
* Add missing counter events handling for ROCPD * Update projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp * Update projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp * Fixed formatting Signed-off-by: David Galiffi <[email protected]> --------- Signed-off-by: Marjan Antic <[email protected]> Co-authored-by: David Galiffi <[email protected]>
1 parent bcd5500 commit 6d42b29

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// SOFTWARE.
2222

2323
#include "library/rocprofiler-sdk/counters.hpp"
24+
#include "core/trace_cache/cache_manager.hpp"
25+
#include "core/trace_cache/metadata_registry.hpp"
2426
#include "library/rocprofiler-sdk/fwd.hpp"
2527

2628
#include <memory>
@@ -32,6 +34,39 @@ namespace rocprofiler_sdk
3234
{
3335
namespace
3436
{
37+
void
38+
metadata_initialize_counter_category()
39+
{
40+
trace_cache::get_metadata_registry().add_string(
41+
trait::name<category::rocm_counter_collection>::value);
42+
}
43+
44+
void
45+
metadata_initialize_counter_track(const char* name)
46+
{
47+
trace_cache::get_metadata_registry().add_track({ name, std::nullopt, "{}" });
48+
}
49+
50+
void
51+
metadata_initialize_counters_pmc(size_t dev_id, const std::string& name,
52+
const std::string& metric_description)
53+
{
54+
const size_t EVENT_CODE = 0;
55+
const size_t INSTANCE_ID = 0;
56+
const char* LONG_DESCRIPTION = "";
57+
const char* COMPONENT = "";
58+
const char* BLOCK = "";
59+
const char* EXPRESSION = "";
60+
const auto* TARGET_ARCH = "GPU";
61+
62+
trace_cache::get_metadata_registry().add_pmc_info(
63+
{ agent_type::GPU, dev_id, TARGET_ARCH, EVENT_CODE, INSTANCE_ID, name.c_str(),
64+
name.c_str(), metric_description.c_str(), LONG_DESCRIPTION, COMPONENT,
65+
"Unit Count", rocprofsys::trace_cache::ABSOLUTE, BLOCK, EXPRESSION, 0, 0 });
66+
}
67+
} // namespace
68+
namespace
69+
{
3570
std::string
3671
get_counter_description(const client_data* tool_data, std::string_view _v)
3772
{
@@ -49,7 +84,8 @@ get_counter_description(const client_data* tool_data, std::string_view _v)
4984

5085
void
5186
counter_event::operator()(const client_data* tool_data, ::perfetto::CounterTrack* _track,
52-
timing_interval _timing, scope::config _scope) const
87+
const std::string& track_name, timing_interval _timing,
88+
scope::config _scope) const
5389
{
5490
if(!record.dispatch_data) return;
5591

@@ -71,6 +107,21 @@ counter_event::operator()(const client_data* tool_data, ::perfetto::CounterTrack
71107
_timing.start, record.record_counter.counter_value);
72108
TRACE_COUNTER(trait::name<category::rocm_counter_collection>::value, *_track,
73109
_timing.end, 0);
110+
111+
const std::string event_metadata = "{}";
112+
const size_t stack_id = 0;
113+
const size_t parent_stack_id = 0;
114+
const size_t correlation_id = 0;
115+
const std::string call_stack = "{}";
116+
const std::string line_info = "{}";
117+
const size_t agent_handle = record.record_counter.agent_id.handle;
118+
const size_t value = record.record_counter.counter_value;
119+
120+
trace_cache::get_buffer_storage().store(
121+
trace_cache::entry_type::pmc_event_with_sample, track_name.c_str(),
122+
_timing.start, event_metadata.c_str(), stack_id, parent_stack_id,
123+
correlation_id, call_stack.c_str(), line_info.c_str(), agent_handle,
124+
track_name.c_str(), value);
74125
}
75126
}
76127

@@ -94,11 +145,17 @@ counter_storage::counter_storage(const client_data* _tool_data, uint64_t _devid,
94145
if(storage_ptr)
95146
counter_storage::write(storage_ptr, metric_name, metric_description);
96147
});
148+
97149
{
98150
constexpr auto _unit = ::perfetto::CounterTrack::Unit::UNIT_COUNT;
99151
track_name = JOIN(" ", "GPU", _metric_name, JOIN("", '[', device_id, ']'));
100152
track = std::make_unique<counter_track_type>(
101153
::perfetto::StaticString(track_name.c_str()));
154+
155+
metadata_initialize_counter_category();
156+
metadata_initialize_counters_pmc(device_id, track_name.c_str(),
157+
metric_description);
158+
metadata_initialize_counter_track(track_name.c_str());
102159
track->set_is_incremental(false);
103160
track->set_unit(_unit);
104161
track->set_unit_multiplier(1);
@@ -110,7 +167,7 @@ counter_storage::operator()(const counter_event& _event, timing_interval _timing
110167
scope::config _scope) const
111168
{
112169
operation::set_storage<counter_data_tracker>{}(storage.get());
113-
_event(tool_data, track.get(), _timing, _scope);
170+
_event(tool_data, track.get(), track_name, _timing, _scope);
114171
}
115172

116173
void

projects/rocprofiler-systems/source/lib/rocprof-sys/library/rocprofiler-sdk/counters.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ struct counter_event
7373
{}
7474

7575
void operator()(const client_data* tool_data, counter_track_type*,
76-
timing_interval _timing, scope::config _scope) const;
76+
const std::string& track_name, timing_interval _timing,
77+
scope::config _scope) const;
7778

7879
counter_dispatch_record record = {};
7980
};

0 commit comments

Comments
 (0)