Skip to content
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
13 changes: 10 additions & 3 deletions devtools/inspector/_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ class Inspector:
def __init__(
self,
etdump_path: Optional[str] = None,
etdump_data: Optional[bytes] = None,
etrecord: Optional[Union[ETRecord, str]] = None,
source_time_scale: TimeScale = TimeScale.NS,
target_time_scale: TimeScale = TimeScale.MS,
Expand All @@ -980,11 +981,12 @@ def __init__(
enable_module_hierarchy: bool = False,
) -> None:
r"""
Initialize an `Inspector` instance with the underlying `EventBlock`\ s populated with data from the provided ETDump path
Initialize an `Inspector` instance with the underlying `EventBlock`\ s populated with data from the provided ETDump path or binary,
and optional ETRecord path.

Args:
etdump_path: Path to the ETDump file.
etdump_path: Path to the ETDump file. Either this parameter or etdump_data should be provided.
etdump_data: ETDump binary. Either this parameter or etdump_path should be provided.
etrecord: Optional ETRecord object or path to the ETRecord file.
source_time_scale: The time scale of the performance data retrieved from the runtime. The default time hook implentation in the runtime returns NS.
target_time_scale: The target time scale to which the users want their performance data converted to. Defaults to MS.
Expand Down Expand Up @@ -1025,8 +1027,13 @@ def __init__(
else:
raise TypeError("Unsupported ETRecord type")

if (etdump_path is None) == (etdump_data is None):
raise ValueError(
"Expecting exactly one of etdump_path or etdump_data to be specified."
)

# Create EventBlocks from ETDump
etdump = gen_etdump_object(etdump_path=etdump_path)
etdump = gen_etdump_object(etdump_path=etdump_path, etdump_data=etdump_data)
if debug_buffer_path is not None:
with open(debug_buffer_path, "rb") as f:
output_buffer = f.read()
Expand Down
19 changes: 13 additions & 6 deletions devtools/inspector/_inspector_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,20 @@ def _extract_debug_handles(graph: OperatorGraph):
return debug_handle_to_op_node_map


def gen_etdump_object(etdump_path: Optional[str] = None) -> ETDumpFlatCC:
def gen_etdump_object(
etdump_path: Optional[str] = None, etdump_data: Optional[bytes] = None
) -> ETDumpFlatCC:
# Gen event blocks from etdump
if etdump_path is None:
raise ValueError("Etdump_path must be specified.")
with open(etdump_path, "rb") as buff:
etdump = deserialize_from_etdump_flatcc(buff.read())
return etdump
if etdump_data is None and etdump_path is not None:
with open(etdump_path, "rb") as buff:
etdump_data = buff.read()

if etdump_data is None:
raise ValueError(
"Unable to get ETDump data. One and only one of etdump_path and etdump_data must be specified."
)

return deserialize_from_etdump_flatcc(etdump_data)


def plot_metric(result: List[float], metric_name: str):
Expand Down
4 changes: 3 additions & 1 deletion devtools/inspector/tests/inspector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def test_inspector_constructor(self):

# Assert that expected functions are called
mock_parse_etrecord.assert_called_once_with(etrecord_path=ETRECORD_PATH)
mock_gen_etdump.assert_called_once_with(etdump_path=ETDUMP_PATH)
mock_gen_etdump.assert_called_once_with(
etdump_path=ETDUMP_PATH, etdump_data=None
)
mock_gen_from_etdump.assert_called_once()
# Because we mocked parse_etrecord() to return None, this method shouldn't be called
mock_gen_graphs_from_etrecord.assert_not_called()
Expand Down
Loading