Skip to content

Commit 1daa904

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

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

devtools/inspector/_inspector.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,33 @@ def print_data_tabular(
11731173

11741174
display_or_print_df(filtered_column_df, file)
11751175

1176+
1177+
def save_data_to_csv(
1178+
self,
1179+
file: IO[str],
1180+
) -> None:
1181+
"""
1182+
Stores the underlying EventBlocks in a csv format with tab separator, to facilitate copy-paste into spreadsheets.
1183+
1184+
Args:
1185+
file: Which IO stream to print to. Do not use stdout, as tab separator is not preserved.
1186+
1187+
Returns:
1188+
None
1189+
"""
1190+
combined_df = self.to_dataframe()
1191+
1192+
# Filter out some columns and rows for better readability when printing
1193+
filtered_column_df = combined_df.drop(columns=EXCLUDED_COLUMNS_WHEN_PRINTING)
1194+
for filter_name in EXCLUDED_EVENTS_WHEN_PRINTING:
1195+
filtered_column_df = filtered_column_df[
1196+
~filtered_column_df["event_name"].str.contains(filter_name)
1197+
]
1198+
filtered_column_df.reset_index(drop=True, inplace=True)
1199+
1200+
filtered_column_df.to_csv(file, sep="\t")
1201+
1202+
11761203
# TODO: write unit test
11771204
def find_total_for_module(self, module_name: str) -> float:
11781205
"""

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+
"--csv_path",
48+
required=False,
49+
help="Provide an optional csv 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.csv_path:
64+
inspector.save_data_to_csv(args.csv_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)