@@ -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"\n Validation 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"\n Validation 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 ])} " )
0 commit comments