xref: /aosp_15_r20/external/executorch/profiler/profiler_results_cli.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1*523fa7a6SAndroid Build Coastguard Worker# Copyright (c) Meta Platforms, Inc. and affiliates.
2*523fa7a6SAndroid Build Coastguard Worker# All rights reserved.
3*523fa7a6SAndroid Build Coastguard Worker#
4*523fa7a6SAndroid Build Coastguard Worker# This source code is licensed under the BSD-style license found in the
5*523fa7a6SAndroid Build Coastguard Worker# LICENSE file in the root directory of this source tree.
6*523fa7a6SAndroid Build Coastguard Worker
7*523fa7a6SAndroid Build Coastguard Workerimport argparse
8*523fa7a6SAndroid Build Coastguard Workerimport sys
9*523fa7a6SAndroid Build Coastguard Worker
10*523fa7a6SAndroid Build Coastguard Workerfrom executorch.profiler.parse_profiler_results import (
11*523fa7a6SAndroid Build Coastguard Worker    deserialize_profile_results,
12*523fa7a6SAndroid Build Coastguard Worker    mem_profile_table,
13*523fa7a6SAndroid Build Coastguard Worker    profile_aggregate_framework_tax,
14*523fa7a6SAndroid Build Coastguard Worker    profile_framework_tax_table,
15*523fa7a6SAndroid Build Coastguard Worker    profile_table,
16*523fa7a6SAndroid Build Coastguard Worker)
17*523fa7a6SAndroid Build Coastguard Worker
18*523fa7a6SAndroid Build Coastguard Worker
19*523fa7a6SAndroid Build Coastguard Workerdef main() -> int:
20*523fa7a6SAndroid Build Coastguard Worker    parser = argparse.ArgumentParser()
21*523fa7a6SAndroid Build Coastguard Worker    parser.add_argument("--prof_results_bin", help="profiling results binary file")
22*523fa7a6SAndroid Build Coastguard Worker    args = parser.parse_args()
23*523fa7a6SAndroid Build Coastguard Worker
24*523fa7a6SAndroid Build Coastguard Worker    with open(args.prof_results_bin, "rb") as prof_results_file:
25*523fa7a6SAndroid Build Coastguard Worker        out_bytes = prof_results_file.read()
26*523fa7a6SAndroid Build Coastguard Worker
27*523fa7a6SAndroid Build Coastguard Worker    prof_data, mem_allocations = deserialize_profile_results(out_bytes)
28*523fa7a6SAndroid Build Coastguard Worker    framework_tax_data = profile_aggregate_framework_tax(prof_data)
29*523fa7a6SAndroid Build Coastguard Worker
30*523fa7a6SAndroid Build Coastguard Worker    prof_tables = profile_table(prof_data)
31*523fa7a6SAndroid Build Coastguard Worker    for table in prof_tables:
32*523fa7a6SAndroid Build Coastguard Worker        print(table)
33*523fa7a6SAndroid Build Coastguard Worker
34*523fa7a6SAndroid Build Coastguard Worker    prof_tables_agg = profile_framework_tax_table(framework_tax_data)
35*523fa7a6SAndroid Build Coastguard Worker    for table in prof_tables_agg:
36*523fa7a6SAndroid Build Coastguard Worker        print(table)
37*523fa7a6SAndroid Build Coastguard Worker
38*523fa7a6SAndroid Build Coastguard Worker    mem_prof_tables = mem_profile_table(mem_allocations)
39*523fa7a6SAndroid Build Coastguard Worker    for table in mem_prof_tables:
40*523fa7a6SAndroid Build Coastguard Worker        print(table)
41*523fa7a6SAndroid Build Coastguard Worker    return 0
42*523fa7a6SAndroid Build Coastguard Worker
43*523fa7a6SAndroid Build Coastguard Worker
44*523fa7a6SAndroid Build Coastguard Workerdef invoke_main() -> None:
45*523fa7a6SAndroid Build Coastguard Worker    sys.exit(main())
46*523fa7a6SAndroid Build Coastguard Worker
47*523fa7a6SAndroid Build Coastguard Worker
48*523fa7a6SAndroid Build Coastguard Workerif __name__ == "__main__":
49*523fa7a6SAndroid Build Coastguard Worker    invoke_main()  # pragma: no cover
50