1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import sys 18import time 19import argparse 20from hiperf_utils import get_lib 21from hiperf_utils import dir_check 22from hiperf_utils import file_check 23 24 25def get_used_binaries(perf_data, command): 26 get_lib().Report(perf_data.encode("utf-8"), 27 'report.txt'.encode("utf-8"), command.encode()) 28 29 with open('report.txt', 'r') as report_file: 30 print(report_file.read()) 31 32 dirname, _ = os.path.split(os.path.abspath(sys.argv[0])) 33 abs_path = os.path.join(dirname, 'report.txt') 34 print("save to %s success" % abs_path) 35 36 37def main(): 38 parser = argparse.ArgumentParser(description=""" To make a report, you 39 need to enter the data source and the path of the report.""") 40 parser.add_argument('-i', '--perf_data', default='perf.data', 41 type=file_check, help=""" The path of profiling 42 data.""") 43 parser.add_argument('-l', '--local_lib_dir', type=dir_check, 44 help="""Path to find symbol dir use to 45 do offline unwind stack""") 46 parser.add_argument('-s', '--call_stack', action='store_true', 47 help="""print the call_stack""") 48 args = parser.parse_args() 49 50 command = "" 51 if args.call_stack: 52 command += "-s " 53 if args.local_lib_dir: 54 command += "--symbol-dir " + args.local_lib_dir 55 56 get_used_binaries(args.perf_data, command) 57 58 59if __name__ == '__main__': 60 main() 61