Skip to content

Commit 1fe0a46

Browse files
committed
enable arg annotation for all instead of only event ID
1 parent 772fdf5 commit 1fe0a46

File tree

3 files changed

+40
-80
lines changed

3 files changed

+40
-80
lines changed

projects/rocprofiler-sdk/source/lib/python/rocpd/source/perfetto.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,6 @@ write_perfetto(
280280
"SELECT * FROM region_args WHERE guid='{}' AND id={}", process.guid, region_id));
281281
};
282282

283-
auto is_hip_event_api = [](std::string_view opname) {
284-
return (opname.rfind("hipEvent", 0) == 0) || (opname == "hipStreamWaitEvent");
285-
};
286-
287-
auto is_event_create_api = [](std::string_view opname) {
288-
return opname.rfind("hipEventCreate", 0) == 0;
289-
};
290-
291-
auto is_hip_event_handle_arg = [](std::string_view argname) {
292-
// - "event" for hipEventRecord/hipEventSynchronize/hipStreamWaitEvent
293-
// - "start"/"stop" for hipEventElapsedTime
294-
return (argname == "event") || (argname == "start") || (argname == "stop");
295-
};
296-
297283
{
298284
for(auto ditr : memory_copy_gen)
299285
for(const auto& itr : memory_copy_gen.get(ditr))
@@ -460,12 +446,7 @@ write_perfetto(
460446

461447
auto _pmc_events = read_pmc_events(itr.event_id);
462448
auto _event = (ocfg.annotate_kfd) ? read_event(itr.event_id) : types::event{};
463-
auto _api_name = std::string_view{itr.name};
464-
auto want_event_handle_annotations = ocfg.annotate_args &&
465-
is_hip_event_api(_api_name) &&
466-
!is_event_create_api(_api_name);
467-
auto _args = want_event_handle_annotations ? read_region_args(itr.id)
468-
: std::vector<types::region_arg>{};
449+
auto _args = read_region_args(itr.id);
469450

470451
auto _category = ::perfetto::DynamicCategory{get_category_string(itr.category)};
471452
TRACE_EVENT_BEGIN(
@@ -527,15 +508,9 @@ write_perfetto(
527508
}
528509
}
529510

530-
if(want_event_handle_annotations)
511+
for(const auto& a : _args)
531512
{
532-
for(const auto& a : _args)
533-
{
534-
if(is_hip_event_handle_arg(a.name))
535-
{
536-
rocprofiler::sdk::add_perfetto_annotation(ctx, a.name, a.value);
537-
}
538-
}
513+
rocprofiler::sdk::add_perfetto_annotation(ctx, a.name, a.value);
539514
}
540515
});
541516

projects/rocprofiler-sdk/tests/pytest-packages/tests/rocprofv3.py

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -518,29 +518,18 @@ def get_json_corr_id(x):
518518
_perform_csv_json_match(a, b, keys_mapping[category], json_data)
519519

520520

521-
def test_perfetto_hip_event_annotations(pftrace_data, pftrace_filename):
521+
def test_perfetto_arg_annotations(pftrace_data, pftrace_filename):
522522
"""
523-
Test that HIP event API calls have event handle annotations in perfetto.
524-
This validates the feature that adds event ID annotations for HIP event API arguments.
525-
526-
The feature adds annotations for:
527-
- hipEventRecord: 'event' argument
528-
- hipEventSynchronize: 'event' argument
529-
- hipEventElapsedTime: 'start' and 'stop' arguments
530-
- hipStreamWaitEvent: 'event' argument
531-
532-
Args:
533-
pftrace_data: DataFrame with perfetto trace data
534-
pftrace_filename: Path to the perfetto trace file for direct queries
523+
Test that function argument annotations are available in perfetto with --annotate-args.
524+
This validates that all API call arguments are annotated as debug annotations
525+
across all categories (hip_api, marker_api, etc.).
535526
"""
536527
import pytest
537528
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
538529

539-
# Filter for HIP API traces
540-
hip_api_data = pftrace_data.loc[pftrace_data["category"] == "hip_api"]
541-
542-
if hip_api_data.empty:
543-
pytest.skip("No HIP API traces found")
530+
# Check if trace has any data
531+
if pftrace_data.empty:
532+
pytest.skip("No trace data found")
544533

545534
# Get the PerfettoReader to query the args table
546535
reader = PerfettoReader(pftrace_filename)
@@ -549,53 +538,49 @@ def test_perfetto_hip_event_annotations(pftrace_data, pftrace_filename):
549538
if not reader.trace_processor:
550539
pytest.skip("Trace processor not available")
551540

552-
# Query for HIP event API slices and their arguments
553-
# The args table joins with slice table on arg_set_id
541+
# Query for API function argument annotations from --annotate-args
542+
# Filter for hip_api/hsa_api/marker_api (KFD/kernel have args from other sources)
543+
# Exclude metadata fields (always present, even without --annotate-args)
554544
query = """
555545
SELECT
556546
slice.name as slice_name,
547+
slice.category as slice_category,
557548
slice.id as slice_id,
558549
args.key as arg_name,
559550
args.string_value as arg_value
560551
FROM slice
561552
JOIN args ON slice.arg_set_id = args.arg_set_id
562-
WHERE slice.category = 'hip_api'
563-
AND (
564-
slice.name LIKE '%hipEventRecord%' OR
565-
slice.name LIKE '%hipEventSynchronize%' OR
566-
slice.name LIKE '%hipEventElapsedTime%' OR
567-
slice.name LIKE '%hipStreamWaitEvent%'
568-
)
569-
AND (
570-
args.key = 'debug.event' OR
571-
args.key = 'debug.start' OR
572-
args.key = 'debug.stop'
553+
WHERE args.key LIKE 'debug.%'
554+
AND slice.category IN ('hip_api', 'hsa_api', 'marker_api')
555+
AND args.key NOT IN (
556+
'debug.begin_ns', 'debug.end_ns', 'debug.delta_ns',
557+
'debug.tid', 'debug.kind', 'debug.operation',
558+
'debug.corr_id', 'debug.ancestor_id'
573559
)
574560
"""
575561

576562
result = reader.query_tp(query)
577563

578-
# Annotations must exist - perfetto was generated with --annotate-args
579-
assert (
580-
not result.empty
581-
), "No HIP event annotations found - --annotate-args may be broken"
564+
# Function argument annotations must exist - perfetto was generated with --annotate-args
565+
assert not result.empty, (
566+
"No function argument annotations found - --annotate-args may be broken. "
567+
"Only metadata fields were found, which are always present."
568+
)
582569

583570
# Validate the structure
571+
assert "slice_name" in result.columns
572+
assert "slice_category" in result.columns
584573
assert "arg_name" in result.columns
585574
assert "arg_value" in result.columns
586575

587-
# Validate that we have expected argument names
588-
found_arg_names = set(result["arg_name"].unique())
589-
expected_arg_names = {"debug.event", "debug.start", "debug.stop"}
590-
assert found_arg_names.issubset(
591-
expected_arg_names
592-
), f"Found unexpected arg names: {found_arg_names - expected_arg_names}"
593-
594-
# Validate that event values are present (non-null)
595-
null_values = result[result["arg_value"].isna()]
596-
assert null_values.empty, f"Found {len(null_values)} event arguments with null values"
597-
598-
print(
599-
f"\nValidation passed: Found {len(result)} event handle annotations "
600-
f"with arg names: {found_arg_names}"
601-
)
576+
# Get statistics for debugging
577+
unique_slices = result["slice_name"].nunique()
578+
unique_args = result["arg_name"].nunique()
579+
unique_categories = result["slice_category"].nunique()
580+
categories = result["slice_category"].unique()
581+
582+
print(f"\nValidation passed: Found {len(result)} argument annotations")
583+
print(f" - {unique_slices} unique API calls annotated")
584+
print(f" - {unique_categories} categories: {list(categories)}")
585+
print(f" - {unique_args} unique argument types")
586+
print(f" - Sample argument names: {list(result['arg_name'].unique()[:10])}")

projects/rocprofiler-sdk/tests/rocprofv3/rocpd/validate_annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import pytest
2727

2828

29-
def test_hip_event_annotations(pftrace_data, request):
29+
def test_arg_annotations(pftrace_data, request):
3030
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
3131

3232
pftrace_filename = request.config.getoption("--pftrace-input")
33-
rocprofv3.test_perfetto_hip_event_annotations(pftrace_data, pftrace_filename)
33+
rocprofv3.test_perfetto_arg_annotations(pftrace_data, pftrace_filename)
3434

3535

3636
if __name__ == "__main__":

0 commit comments

Comments
 (0)