#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import time import os import sys import platform import pty import threading import re import traceback import select import subprocess import queue import shutil from collections import defaultdict sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "mylogger.py")) from mylogger import get_logger, parse_json Log = get_logger("performance") log_info = Log.info log_error = Log.error script_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) config = parse_json() if not config: log_error("config file: build_example.json not exist") raise FileNotFoundError("config file: build_example.json not exist") class PerformanceAnalyse: try: TIMEOUT = int(config.get("performance").get("performance_exec_timeout")) select_timeout = float(config.get("performance").get("performance_select_timeout")) top_count = int(config.get("performance").get("performance_top_count")) overflow = float(config.get("performance").get("performance_overflow")) exclude = config.get("performance").get("exclude") log_info("TIMEOUT:{}".format(TIMEOUT)) log_info("select_timeout:{}".format(select_timeout)) log_info("top_count:{}".format(top_count)) log_info("overflow:{} sec".format(overflow)) except Exception as e: log_error("config file:build_example.json has error:{}".format(e)) raise FileNotFoundError("config file:build_example.json has error:{}".format(e)) def __init__(self, performance_cmd, output_path, report_title, ptyflag=False): self.performance_cmd = script_path + performance_cmd self.output_path = script_path + output_path self.report_title = report_title self.ptyflag = ptyflag self.out_queue = queue.Queue() self.system_info = list() self.ninjia_trace_list = list() self.gn_exec_li = list() self.gn_script_li = list() self.gn_end_li = list() self.ccache_li = list() self.c_targets_li = list() self.root_dir = None self.gn_dir = None self.gn_script_res = None self.gn_exec_res = None self.cost_time_res = list() self.gn_exec_flag = re.compile(r"File execute times") self.gn_script_flag = re.compile(r"Script execute times") self.gn_end_flag = re.compile(r"Done\. Made \d+ targets from \d+ files in (\d+)ms") self.root_dir_flag = re.compile(r"""loader args.*source_root_dir="([a-zA-Z\d/\\_]+)""""") self.gn_dir_flag = re.compile(r"""loader args.*gn_root_out_dir="([a-zA-Z\d/\\_]+)""""") self.ccache_start_flag = re.compile(r"ccache_dir =") self.ccache_end_flag = re.compile(r"c targets overlap rate statistics") self.c_targets_flag = re.compile(r"c overall build overlap rate") self.build_error = re.compile(r"=====build\s\serror=====") self.ohos_error = re.compile(r"OHOS ERROR") self.total_flag = re.compile(r"Cost time:.*(\d+:\d+:\d+)") self.total_cost_time = None self.error_message = list() self.during_time_dic = { "Preloader": {"start_pattern": re.compile(r"Set cache size"), "end_pattern": re.compile(r"generated compile_standard_whitelist"), "start_time": 0, "end_time": 0 }, "Loader": {"start_pattern": re.compile(r"Checking all build args"), "end_pattern": re.compile(r"generate target syscap"), "start_time": 0, "end_time": 0 }, "Ninjia": {"start_pattern": re.compile(r"Done\. Made \d+ targets from \d+ files in (\d+)ms"), "end_pattern": re.compile(r"ccache_dir ="), "start_time": 0, "end_time": 0 }} self.table_html = "" self.base_html = """
{} | ".format(header.capitalize()) self.table_html += "
---|
{} | ".format(data) self.table_html += "
{} | ".format(data) self.table_html += "