xref: /aosp_15_r20/external/executorch/devtools/inspector/inspector_cli.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the BSD-style license found in the
5# LICENSE file in the root directory of this source tree.
6
7# pyre-unsafe
8
9import argparse
10
11from executorch.devtools import Inspector
12from executorch.devtools.inspector import compare_results, TimeScale
13
14
15def main() -> None:
16    parser = argparse.ArgumentParser()
17    parser.add_argument(
18        "--etdump_path",
19        required=True,
20        help="Provide an ETDump file path.",
21    )
22    parser.add_argument(
23        "--source_time_scale",
24        type=str,
25        choices=[ts.value for ts in TimeScale],
26        help="Enter the source time scale (ns, us, ms, s, cycles)",
27        default=TimeScale.NS.value,
28    )
29    parser.add_argument(
30        "--target_time_scale",
31        type=str,
32        choices=[ts.value for ts in TimeScale],
33        help="Enter the target time scale (ns, us, ms, s, cycles)",
34        default=TimeScale.MS.value,
35    )
36    parser.add_argument(
37        "--etrecord_path",
38        required=False,
39        help="Provide an optional ETRecord file path.",
40    )
41    parser.add_argument(
42        "--debug_buffer_path",
43        required=False,
44        help="Provide an optional buffer file path.",
45    )
46    parser.add_argument("--compare_results", action="store_true")
47
48    args = parser.parse_args()
49
50    inspector = Inspector(
51        etdump_path=args.etdump_path,
52        etrecord=args.etrecord_path,
53        debug_buffer_path=args.debug_buffer_path,
54        source_time_scale=TimeScale(args.source_time_scale),
55        target_time_scale=TimeScale(args.target_time_scale),
56    )
57    inspector.print_data_tabular()
58    if args.compare_results:
59        for event_block in inspector.event_blocks:
60            if event_block.name == "Execute":
61                compare_results(
62                    reference_output=event_block.reference_output,
63                    run_output=event_block.run_output,
64                    plot=True,
65                )
66
67
68if __name__ == "__main__":
69    main()  # pragma: no cover
70