Skip to content

Debug event populates event name #5142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions devtools/etdump/etdump_schema_flatcc.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ table DebugEvent {

// String based delegate debug identifier.
delegate_debug_id_str:string;

// Name assigned to this debug event by the runtime. If it is an operator
// call this will just be the name of the operator that was executed.
name:string;
}

// All the details pertaining to an allocation done in the runtime. The main
Expand Down
1 change: 1 addition & 0 deletions devtools/etdump/schema_flatcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Value:

@dataclass
class DebugEvent:
name: Optional[str]
chain_index: int
instruction_id: int
delegate_debug_id_int: Optional[int]
Expand Down
1 change: 1 addition & 0 deletions devtools/etdump/tests/serialize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_sample_etdump_flatcc() -> flatcc.ETDumpFlatCC:
profile_event=None,
allocation_event=None,
debug_event=flatcc.DebugEvent(
name="test_debug_event",
chain_index=1,
instruction_id=0,
delegate_debug_id_str="56",
Expand Down
59 changes: 42 additions & 17 deletions devtools/inspector/_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _gen_from_event(event: ProfileEvent) -> "ProfileEventSignature":
# Signature of a DebugEvent
@dataclass(frozen=True, order=True)
class DebugEventSignature:
name: str = ""
instruction_id: Optional[int] = -1
delegate_id: Optional[int] = None
delegate_id_str: Optional[str] = None
Expand All @@ -165,6 +166,7 @@ def _gen_from_event(event: DebugEvent) -> "DebugEventSignature":
The Signature will convert these back to the intended None value
"""
return DebugEventSignature(
event.name or "",
event.instruction_id if event.instruction_id != -1 else None,
event.delegate_debug_id_int if event.delegate_debug_id_int != -1 else None,
event.delegate_debug_id_str if event.delegate_debug_id_str != "" else None,
Expand Down Expand Up @@ -470,46 +472,63 @@ def _calculate_elapsed_time(start_time, end_time):
return elapsed_time

@staticmethod
def _populate_profiling_related_fields(
def _populate_event_signature_fields(
ret_event: "Event",
profile_event_signature: Optional[ProfileEventSignature],
events: List[InstructionEvent],
scale_factor: float,
event_signature: Optional[Union[ProfileEventSignature, DebugEventSignature]],
) -> None:
"""
Given a partially constructed Event, populate the fields related to
the profile events
the profile event signature or debug event signature

Fields Updated:
name
delegate_debug_identifier
is_delegated_op
perf_data
delegate_debug_metadatas
"""

# Fill out fields from profile event signature
if profile_event_signature is not None:
if profile_event_signature.delegate_id is not None: # 0 is a valid value
delegate_debug_identifier = profile_event_signature.delegate_id
# TODO: T201347372 Push the None check to ealier in the stack.
if event_signature is not None:
if event_signature.delegate_id is not None: # 0 is a valid value
delegate_debug_identifier = event_signature.delegate_id
else:
delegate_debug_identifier = (
profile_event_signature.delegate_id_str or None
)
delegate_debug_identifier = event_signature.delegate_id_str or None

# Use the delegate identifier as the event name if delegated
is_delegated_op = delegate_debug_identifier is not None
name = (
profile_event_signature.name
event_signature.name
if not is_delegated_op
else str(delegate_debug_identifier)
)

# Update fields
ret_event.name = name
# This is for older version of etdump that doesn't have the name field for debug events, we don't update the name field
if name:
ret_event.name = name
ret_event.delegate_debug_identifier = delegate_debug_identifier
ret_event.is_delegated_op = is_delegated_op

@staticmethod
def _populate_profiling_related_fields(
ret_event: "Event",
profile_event_signature: Optional[ProfileEventSignature],
events: List[InstructionEvent],
scale_factor: float,
) -> None:
"""
Given a partially constructed Event, populate the fields related to
the profile events

Fields Updated:
name
delegate_debug_identifier
is_delegated_op
perf_data
delegate_debug_metadatas
"""

# Fill out fields from profile event signature
Event._populate_event_signature_fields(ret_event, profile_event_signature)

# Fill out fields from profile event
data = []
delegate_debug_metadatas = []
Expand Down Expand Up @@ -577,9 +596,15 @@ def _populate_debugging_related_fields(
the debug events

Fields Updated:
name
delegate_debug_identifier
is_delegated_op
debug_data
"""

# Fill out fields from debug event signature
Event._populate_event_signature_fields(ret_event, debug_event_signature)

debug_data: List[flatcc.Value] = []
for event in events:
if (debug_events := event.debug_events) is None:
Expand Down
62 changes: 62 additions & 0 deletions devtools/inspector/tests/event_blocks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _gen_sample_profile_event(
def _gen_sample_debug_event(
instruction_id: int,
delegate_debug_id: Optional[Union[int, str]] = None,
name: str = "test_debug_event",
) -> flatcc.DebugEvent:
"""
Helper for generating test DebugEvents
Expand All @@ -77,6 +78,7 @@ def _gen_sample_debug_event(
)

return flatcc.DebugEvent(
name=name,
chain_index=0,
instruction_id=instruction_id,
delegate_debug_id_int=delegate_debug_id_int,
Expand Down Expand Up @@ -299,6 +301,42 @@ def _get_sample_etdump_flatcc_profiling_and_debugging() -> flatcc.ETDumpFlatCC:

return ETDumpFlatCC(version=0, run_data=[run_data_1, run_data_2, run_data_3])

@staticmethod
def _get_sample_etdump_flatcc_debug_events_only(
event_name: str,
delegate_debug_id: str,
) -> flatcc.ETDumpFlatCC:
"""
Helper for getting a sample ETDumpFlatCC object with RunData signature_a
and (debug_event_delegated, debug_event_non_delegated, no profile event)
"""

debug_event_delegated = TestEventBlock._gen_sample_debug_event(
instruction_id=1, delegate_debug_id=delegate_debug_id, name=event_name
)
debug_event_non_delegated = TestEventBlock._gen_sample_debug_event(
instruction_id=1, name=event_name
)
run_data_1 = flatcc.RunData(
name="signature_a",
bundled_input_index=-1,
allocators=[],
events=[
flatcc.Event(
allocation_event=None,
debug_event=debug_event_delegated,
profile_event=None,
),
flatcc.Event(
allocation_event=None,
debug_event=debug_event_non_delegated,
profile_event=None,
),
],
)

return ETDumpFlatCC(version=0, run_data=[run_data_1])

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def test_gen_from_etdump(self) -> None:
Expand Down Expand Up @@ -370,6 +408,30 @@ def test_gen_from_etdump_inconsistent_debug_data(self) -> None:
with self.assertRaises(AssertionError):
EventBlock._gen_from_etdump(etdump)

def test_gen_from_etdump_debug_events_only(self) -> None:
"""
Test generation of EventBlocks given an ETDump with only debugging events

Specifically it tests:
- Correct number of EventBlocks and Events
- Correct name of each Event
"""
event_name = "test_debug_event_only"
delegate_debug_id = "debug_id"
etdump: ETDumpFlatCC = (
TestEventBlock._get_sample_etdump_flatcc_debug_events_only(
event_name=event_name,
delegate_debug_id=delegate_debug_id,
)
)
event_blocks = EventBlock._gen_from_etdump(etdump)
self.assertEqual(len(event_blocks), 1)
self.assertEqual(len(event_blocks[0].events), 2)
# Delegated event uses delegate_debug_id as event name
self.assertEqual(event_blocks[0].events[0].name, delegate_debug_id)
# Non delegated event uses event_name as event name
self.assertEqual(event_blocks[0].events[1].name, event_name)

def test_inspector_event_generation(self) -> None:
"""
Test Inspector.Event derivation from various ProfileEvent cases
Expand Down
4 changes: 4 additions & 0 deletions devtools/inspector/tests/inspector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def test_populate_debugging_related_fields_raises_for_inconsistent_events(self):
)

debug_event_0 = flatcc.DebugEvent(
name="event",
chain_index=1,
instruction_id=0,
delegate_debug_id_int=1,
Expand All @@ -341,6 +342,7 @@ def test_populate_debugging_related_fields_raises_for_inconsistent_events(self):

# Note the sizes of this tensor are different from the previous one
debug_event_1 = flatcc.DebugEvent(
name="event",
chain_index=1,
instruction_id=0,
delegate_debug_id_int=1,
Expand Down Expand Up @@ -385,6 +387,7 @@ def test_populate_debugging_related_fields_passes_for_consistent_events(self):
)

debug_event_0 = flatcc.DebugEvent(
name="event",
chain_index=1,
instruction_id=0,
delegate_debug_id_int=1,
Expand All @@ -408,6 +411,7 @@ def test_populate_debugging_related_fields_passes_for_consistent_events(self):

# Same as the event above except for offset
debug_event_1 = flatcc.DebugEvent(
name="event",
chain_index=1,
instruction_id=0,
delegate_debug_id_int=1,
Expand Down
1 change: 1 addition & 0 deletions devtools/inspector/tests/inspector_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_find_populated_event(self):
end_time=2002,
)
debug_event = flatcc.DebugEvent(
name="test_debug_event",
chain_index=1,
instruction_id=0,
delegate_debug_id_str="56",
Expand Down
Loading