1#!/usr/bin/env python3 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. 15import os 16import subprocess 17import sys 18import argparse 19import logging 20from pathlib import Path 21 22THIS_FILE = os.path.basename(__file__) 23logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', 24 level=logging.INFO) 25logger = logging.getLogger(THIS_FILE) 26 27def main(): 28 parser = argparse.ArgumentParser( 29 description='FTrace C++ code generator.') 30 parser.add_argument('-v', dest='version', required=True, type=str, 31 help='device kernel version') 32 33 args = parser.parse_args(sys.argv[1:]) 34 version = args.version 35 36 version_path = "device_kernel_version/{}".format(version) 37 events_file = version_path + "/events" 38 if not Path(events_file).is_dir(): 39 logger.error('device kernel events directory does not exist({})'.format(events_file)) 40 exit(1) 41 42 # generate proto file 43 proto_path = "{}/../../../../protos/types/plugins/ftrace_data/{}/".format(os.getcwd(), version) 44 proto_cmd = "python ftrace_proto_generator.py -a allowlist.txt -e {} -o {}".format(events_file, proto_path) 45 if (subprocess.run(proto_cmd, shell=True) != 0): 46 logger.error('Execution python failed! cmd: {}'.format(proto_cmd)) 47 exit(2) 48 49 # generate parsers cpp 50 cpp_cmd = "python {}/ftrace_cpp_generator.py -a allowlist.txt -e {}".format(version_path, events_file) 51 parsers_cmd = "{} -p {}/event_parsers/".format(cpp_cmd, version_path) 52 if (subprocess.run(parsers_cmd, shell=True) != 0): 53 logger.error('Execution python failed! cmd: {}'.format(parsers_cmd)) 54 exit(3) 55 56 # generate formatters cpp 57 parsers_cmd = "{} -f {}/event_formatters/".format(cpp_cmd, version_path) 58 if (subprocess.run(parsers_cmd, shell=True) != 0): 59 logger.error('Execution python failed! cmd: {}'.format(parsers_cmd)) 60 exit(4) 61 62if __name__ == '__main__': 63 main() 64 print("refresh device kernel code sucess!") 65