Skip to content

Commit 805fd76

Browse files
committed
[ET] Add tsv_path to inspector_cli
Pull Request resolved: #7035 Per https://fb.workplace.com/groups/pytorch.edge.users/posts/1640064163530537/?comment_id=1640127190190901 ghstack-source-id: 255101390 @exported-using-ghexport Differential Revision: [D66379005](https://our.internmc.facebook.com/intern/diff/D66379005/)
1 parent fc42a4e commit 805fd76

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

devtools/inspector/_inspector.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,23 +1143,18 @@ def to_dataframe(
11431143
]
11441144
return pd.concat(df_list, ignore_index=True)
11451145

1146-
def print_data_tabular(
1146+
def _prepare_dataframe(
11471147
self,
1148-
file: IO[str] = sys.stdout,
11491148
include_units: bool = True,
11501149
include_delegate_debug_data: bool = False,
1151-
) -> None:
1150+
) -> pd.DataFrame:
11521151
"""
1153-
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
1154-
11551152
Args:
1156-
file: Which IO stream to print to. Defaults to stdout.
1157-
Not used if this is in an IPython environment such as a Jupyter notebook.
11581153
include_units: Whether headers should include units (default true)
11591154
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
11601155
11611156
Returns:
1162-
None
1157+
Returns a pandas DataFrame of the Events in each EventBlock in the inspector, with additional filtering.
11631158
"""
11641159
combined_df = self.to_dataframe(include_units, include_delegate_debug_data)
11651160

@@ -1171,7 +1166,44 @@ def print_data_tabular(
11711166
]
11721167
filtered_column_df.reset_index(drop=True, inplace=True)
11731168

1174-
display_or_print_df(filtered_column_df, file)
1169+
return filtered_column_df
1170+
1171+
def print_data_tabular(
1172+
self,
1173+
file: IO[str] = sys.stdout,
1174+
include_units: bool = True,
1175+
include_delegate_debug_data: bool = False,
1176+
) -> None:
1177+
"""
1178+
Displays the underlying EventBlocks in a structured tabular format, with each row representing an Event.
1179+
1180+
Args:
1181+
file: Which IO stream to print to. Defaults to stdout.
1182+
Not used if this is in an IPython environment such as a Jupyter notebook.
1183+
include_units: Whether headers should include units (default true)
1184+
include_delegate_debug_data: Whether to include delegate debug metadata (default false)
1185+
1186+
Returns:
1187+
None
1188+
"""
1189+
df = self._prepare_dataframe(include_units, include_delegate_debug_data)
1190+
display_or_print_df(df, file)
1191+
1192+
def save_data_to_tsv(
1193+
self,
1194+
file: IO[str],
1195+
) -> None:
1196+
"""
1197+
Stores the underlying EventBlocks in tsv format to facilitate copy-paste into spreadsheets.
1198+
1199+
Args:
1200+
file: Which IO stream to print to. Do not use stdout, as tab separator is not preserved.
1201+
1202+
Returns:
1203+
None
1204+
"""
1205+
df = self._prepare_dataframe()
1206+
df.to_csv(file, sep="\t")
11751207

11761208
# TODO: write unit test
11771209
def find_total_for_module(self, module_name: str) -> float:

devtools/inspector/inspector_cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def main() -> None:
4343
required=False,
4444
help="Provide an optional buffer file path.",
4545
)
46+
parser.add_argument(
47+
"--tsv_path",
48+
required=False,
49+
help="Provide an optional tsv file path.",
50+
)
4651
parser.add_argument("--compare_results", action="store_true")
4752

4853
args = parser.parse_args()
@@ -55,6 +60,8 @@ def main() -> None:
5560
target_time_scale=TimeScale(args.target_time_scale),
5661
)
5762
inspector.print_data_tabular()
63+
if args.tsv_path:
64+
inspector.save_data_to_tsv(args.tsv_path)
5865
if args.compare_results:
5966
for event_block in inspector.event_blocks:
6067
if event_block.name == "Execute":

0 commit comments

Comments
 (0)