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 7import argparse 8import sys 9 10from executorch.profiler.parse_profiler_results import ( 11 deserialize_profile_results, 12 mem_profile_table, 13 profile_aggregate_framework_tax, 14 profile_framework_tax_table, 15 profile_table, 16) 17 18 19def main() -> int: 20 parser = argparse.ArgumentParser() 21 parser.add_argument("--prof_results_bin", help="profiling results binary file") 22 args = parser.parse_args() 23 24 with open(args.prof_results_bin, "rb") as prof_results_file: 25 out_bytes = prof_results_file.read() 26 27 prof_data, mem_allocations = deserialize_profile_results(out_bytes) 28 framework_tax_data = profile_aggregate_framework_tax(prof_data) 29 30 prof_tables = profile_table(prof_data) 31 for table in prof_tables: 32 print(table) 33 34 prof_tables_agg = profile_framework_tax_table(framework_tax_data) 35 for table in prof_tables_agg: 36 print(table) 37 38 mem_prof_tables = mem_profile_table(mem_allocations) 39 for table in mem_prof_tables: 40 print(table) 41 return 0 42 43 44def invoke_main() -> None: 45 sys.exit(main()) 46 47 48if __name__ == "__main__": 49 invoke_main() # pragma: no cover 50