Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ write_perfetto(
return &pmc_info.at(pmc_id);
};

auto read_region_args = [&conn, &process, &ocfg](uint64_t region_id) {
if(!ocfg.annotate_args) return std::vector<types::region_arg>{};

return rocpd::read_sql_query<types::region_arg>(
conn,
fmt::format(
"SELECT * FROM region_args WHERE guid='{}' AND id={}", process.guid, region_id));
};

{
for(auto ditr : memory_copy_gen)
for(const auto& itr : memory_copy_gen.get(ditr))
Expand Down Expand Up @@ -437,6 +446,7 @@ write_perfetto(

auto _pmc_events = read_pmc_events(itr.event_id);
auto _event = (ocfg.annotate_kfd) ? read_event(itr.event_id) : types::event{};
auto _args = read_region_args(itr.id);

auto _category = ::perfetto::DynamicCategory{get_category_string(itr.category)};
TRACE_EVENT_BEGIN(
Expand Down Expand Up @@ -497,6 +507,11 @@ write_perfetto(
_extdata.kfd.value().record);
}
}

for(const auto& a : _args)
{
rocprofiler::sdk::add_perfetto_annotation(ctx, a.name, a.value);
}
});

TRACE_EVENT_END(_category, track, itr.end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,59 @@ def get_json_corr_id(x):

for a, b in zip(_csv_data_sorted, _js_data_sorted):
_perform_csv_json_match(a, b, keys_mapping[category], json_data)


def test_perfetto_arg_annotations(pftrace_reader):
"""
Test that function argument annotations are available in perfetto with --annotate-args.
This validates that all API call arguments are annotated as debug annotations
across all categories (hip_api, marker_api, etc.).
"""
import pytest

# Query for API function argument annotations from --annotate-args
# Filter for hip_api/hsa_api/marker_api (KFD/kernel have args from other sources)
# Exclude metadata fields (always present, even without --annotate-args)
query = """
SELECT
slice.name as slice_name,
slice.category as slice_category,
slice.id as slice_id,
args.key as arg_name,
args.string_value as arg_value
FROM slice
JOIN args ON slice.arg_set_id = args.arg_set_id
WHERE args.key LIKE 'debug.%'
AND slice.category IN ('hip_api', 'hsa_api', 'marker_api')
AND args.key NOT IN (
'debug.begin_ns', 'debug.end_ns', 'debug.delta_ns',
'debug.tid', 'debug.kind', 'debug.operation',
'debug.corr_id', 'debug.ancestor_id'
)
"""

result = pftrace_reader.query_tp(query)

# Function argument annotations must exist - perfetto was generated with --annotate-args
assert not result.empty, (
"No function argument annotations found - --annotate-args may be broken. "
"Only metadata fields were found, which are always present."
)

# Validate the structure
assert "slice_name" in result.columns
assert "slice_category" in result.columns
assert "arg_name" in result.columns
assert "arg_value" in result.columns

# Get statistics for debugging
unique_slices = result["slice_name"].nunique()
unique_args = result["arg_name"].nunique()
unique_categories = result["slice_category"].nunique()
categories = result["slice_category"].unique()

print(f"\nValidation passed: Found {len(result)} argument annotations")
print(f" - {unique_slices} unique API calls annotated")
print(f" - {unique_categories} categories: {list(categories)}")
print(f" - {unique_args} unique argument types")
print(f" - Sample argument names: {list(result['arg_name'].unique()[:10])}")
25 changes: 25 additions & 0 deletions projects/rocprofiler-sdk/tests/rocprofv3/rocpd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ rocprofiler_add_integration_execute_test(
FIXTURES_SETUP rocprofv3-test-rocpd-generation
FIXTURES_REQUIRED rocprofv3-test-rocpd)

rocprofiler_add_integration_execute_test(
rocprofv3-test-rocpd-perfetto-generation-annotations
COMMAND
${Python3_EXECUTABLE} -m rocpd convert -f pftrace --kernel-rename --annotate-args
-d ${CMAKE_CURRENT_BINARY_DIR}/rocpd-output-data-annotations -i
${CMAKE_CURRENT_BINARY_DIR}/rocpd-input-data/out_results.db
DEPENDS rocprofiler-sdk::rocprofv3
TIMEOUT 120
LABELS "integration-tests;rocpd"
PRELOAD "${ROCPROFILER_MEMCHECK_PRELOAD_ENV_VALUE}"
ENVIRONMENT "${rocprofv3-rocpd-env}"
FIXTURES_SETUP rocprofv3-test-rocpd-generation-annotations
FIXTURES_REQUIRED rocprofv3-test-rocpd)

Comment on lines +140 to +153
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like just a duplication of the prior execution_test, with the added --annotate-args param. Do you want to just add --annotate-args to the original test, and call your validate_annotations.py using that file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of keeping this separate because --annotate-args is optional mode rather than the default path. Also, if we add more options for rocpd convert and more tests in future, it may be cleaner to keep separate execute tests so it’s easier to debug issues. But I do see your point about avoiding duplications. I’m fine with whichever direction we want to standardize on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, my thought is that your validation is going to check the annotations later anyway. So we can save 1 test & time by just lumping the 2 generation tests into 1. Just thought I'd call it out, I'm ok either way on this one too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should minimize the generation tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait disregard the previous comment. I thought this was running an app on the GPU

rocprofiler_add_integration_execute_test(
rocprofv3-test-rocpd-perfetto-generation-multiproc
COMMAND
Expand Down Expand Up @@ -239,6 +253,17 @@ rocprofiler_add_integration_validate_test(
LABELS "integration-tests;rocpd"
FIXTURES_REQUIRED rocprofv3-test-rocpd-generation)

rocprofiler_add_integration_validate_test(
rocprofv3-test-rocpd-annotations
TEST_PATHS validate_annotations.py
COPY conftest.py
CONFIG pytest.ini
ARGS --pftrace-input
${CMAKE_CURRENT_BINARY_DIR}/rocpd-output-data-annotations/out_results.pftrace
TIMEOUT 120
LABELS "integration-tests;rocpd"
FIXTURES_REQUIRED rocprofv3-test-rocpd-generation-annotations)

#########################################################################################
#
# Package generation
Expand Down
9 changes: 7 additions & 2 deletions projects/rocprofiler-sdk/tests/rocprofv3/rocpd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ def json_data(request):


@pytest.fixture
def pftrace_data(request):
def pftrace_reader(request):
filename = request.config.getoption("--pftrace-input")
return PerfettoReader(filename).read()[0]
return PerfettoReader(filename)


@pytest.fixture
def pftrace_data(pftrace_reader):
return pftrace_reader.read()[0]


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

# MIT License
#
# Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# 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.

import sys
import pytest


def test_arg_annotations(pftrace_reader):
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3

rocprofv3.test_perfetto_arg_annotations(pftrace_reader)


if __name__ == "__main__":
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
sys.exit(exit_code)
Loading