From 7f240c7095c3997a8475f404a0d52c26a8dc9d55 Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Sun, 29 Jan 2023 10:12:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9project=5Fpath=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E5=BC=8F,=E9=80=9A=E8=BF=87=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao --- tools/rom_ram_analyzer/L0L1/README.md | 16 +++++++++--- .../rom_ram_analyzer/L0L1/pkgs/basic_tool.py | 1 - tools/rom_ram_analyzer/L0L1/src/config.py | 21 +++++++++++++-- tools/rom_ram_analyzer/L0L1/src/config.yaml | 2 +- .../L0L1/src/gn_lineno_collector.py | 8 +++--- .../L0L1/src/info_handlers.py | 2 +- .../L0L1/src/post_handlers.py | 1 - .../rom_ram_analyzer/L0L1/src/rom_analysis.py | 26 ++++++++----------- .../L0L1/src/template_processor.py | 1 - tools/rom_ram_analyzer/L2/README.md | 2 +- 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/tools/rom_ram_analyzer/L0L1/README.md b/tools/rom_ram_analyzer/L0L1/README.md index 43f951d..b82fb56 100644 --- a/tools/rom_ram_analyzer/L0L1/README.md +++ b/tools/rom_ram_analyzer/L0L1/README.md @@ -19,10 +19,18 @@ ## 使用 -1. 修改config.yaml - - project_path:oh项目根路径 - - output_file:保存结果的文件的名字[optional] -2. `python3 rom_analysis.py --product_name {your_product_name} [--recollect_gn bool]`运行代码,其中recollect_gn表示是需要重新扫描BUILD.gn还是直接使用已有结果.eg: `python3 rom_analysis.py --product_name ipcamera_hispark_taurus` +前置条件: + +1. 获取整个rom_ram_analyzer目录 +1. 对系统进行编译 +1. linux平台 +1. python3.8及以后 +1. 安装requirements + ```txt + xlwt==1.3.0 + ``` + +1. `python3 rom_analysis.py --product_name {your_product_name} --oh_path {root_path_of_oh} [--recollect_gn bool]`运行代码,其中recollect_gn表示是需要重新扫描BUILD.gn还是直接使用已有结果.eg: `python3 rom_analysis.py --product_name ipcamera_hispark_taurus` 3. 运行完毕会产生4个json文件及一个xls文件,如果是默认配置,各文件描述如下: - gn_info.json:BUILD.gn的分析结果 - sub_com_info.json:从bundle.json中进行分析获得的各部件及其对应根目录的信息 diff --git a/tools/rom_ram_analyzer/L0L1/pkgs/basic_tool.py b/tools/rom_ram_analyzer/L0L1/pkgs/basic_tool.py index 0fe0ea6..5711a81 100644 --- a/tools/rom_ram_analyzer/L0L1/pkgs/basic_tool.py +++ b/tools/rom_ram_analyzer/L0L1/pkgs/basic_tool.py @@ -19,7 +19,6 @@ import os import re import glob import logging -from deprecated.sphinx import deprecated from typing import * diff --git a/tools/rom_ram_analyzer/L0L1/src/config.py b/tools/rom_ram_analyzer/L0L1/src/config.py index d2e9918..de88c63 100644 --- a/tools/rom_ram_analyzer/L0L1/src/config.py +++ b/tools/rom_ram_analyzer/L0L1/src/config.py @@ -4,7 +4,6 @@ import argparse import json from typing import * -# from gn_lineno_collector import gn_lineno_collect import preprocess from pkgs.simple_yaml_tool import SimpleYamlTool from pkgs.basic_tool import do_nothing, BasicTool @@ -17,11 +16,29 @@ from info_handlers import extension_handler, hap_name_handler, target_type_handl 只给rom_analysis.py使用 """ +def parse_args(): + parser = argparse.ArgumentParser( + description="analysis rom size of L0 and L1 product") + parser.add_argument("-p", "--product_name", type=str, default="ipcamera_hispark_taurus_linux", + help="product name. eg: -p ipcamera_hispark_taurus") + parser.add_argument("-o", "--oh_path", type=str, + default=".", help="root path of openharmony") + parser.add_argument("-r", "--recollect_gn", type=bool, + default=True, help="if recollect gn info or not") + args = parser.parse_args() + return args + + +_args = parse_args() + # # global variables configs = SimpleYamlTool.read_yaml("config.yaml") result_dict: Dict[str, Any] = dict() -project_path = BasicTool.abspath(configs.get("project_path")) +# project_path = BasicTool.abspath(configs.get("project_path")) +project_path = BasicTool.abspath(_args.oh_path) +product_name = _args.product_name +recollect_gn = _args.recollect_gn _sc_json: Dict[Text, Text] = configs.get("subsystem_component_json") _sc_save = _sc_json.get("save") _target_type = configs["target_type"] diff --git a/tools/rom_ram_analyzer/L0L1/src/config.yaml b/tools/rom_ram_analyzer/L0L1/src/config.yaml index 0a55ae6..3d30716 100644 --- a/tools/rom_ram_analyzer/L0L1/src/config.yaml +++ b/tools/rom_ram_analyzer/L0L1/src/config.yaml @@ -12,7 +12,7 @@ # limitations under the License. # root: -project_path: ~/oh +# project_path: ~/oh # 从bundle.json中取出的component和subsystem_name的信息 # used by get_subsystem_component.py config.py subsystem_component_json: diff --git a/tools/rom_ram_analyzer/L0L1/src/gn_lineno_collector.py b/tools/rom_ram_analyzer/L0L1/src/gn_lineno_collector.py index b8ffeee..05f54c0 100644 --- a/tools/rom_ram_analyzer/L0L1/src/gn_lineno_collector.py +++ b/tools/rom_ram_analyzer/L0L1/src/gn_lineno_collector.py @@ -5,10 +5,6 @@ import preprocess from pkgs.basic_tool import BasicTool from pkgs.simple_yaml_tool import SimpleYamlTool -config = SimpleYamlTool.read_yaml("config.yaml") -project_path = config.get("project_path") -black_list = map(lambda x: os.path.join( - project_path, x), config.get("black_list")) def gn_lineno_collect(match_pattern: str, project_path: str) -> DefaultDict[str, List[int]]: """ @@ -17,6 +13,10 @@ def gn_lineno_collect(match_pattern: str, project_path: str) -> DefaultDict[str, :param project_path: 项目路径(搜索路径) :return: {gn_file: [line_no_1, line_no_2, ..]} """ + config = SimpleYamlTool.read_yaml("config.yaml") + # project_path = config.get("project_path") + black_list = map(lambda x: os.path.join( + project_path, x), config.get("black_list")) def handler(content: Text) -> List[str]: return list(filter(lambda y: len(y) > 0, list(map(lambda x: x.strip(), content.split("\n"))))) diff --git a/tools/rom_ram_analyzer/L0L1/src/info_handlers.py b/tools/rom_ram_analyzer/L0L1/src/info_handlers.py index 28f8884..bfdd12f 100644 --- a/tools/rom_ram_analyzer/L0L1/src/info_handlers.py +++ b/tools/rom_ram_analyzer/L0L1/src/info_handlers.py @@ -15,5 +15,5 @@ def hap_name_handler(paragraph: Text): def target_type_handler(paragraph: Text): tt = GnVariableParser.string_parser("target_type", paragraph).strip('"') if not tt: - logging.warning("parse 'target_type' failed, maybe it's a variable") + logging.info("parse 'target_type' failed, maybe it's a variable") return tt diff --git a/tools/rom_ram_analyzer/L0L1/src/post_handlers.py b/tools/rom_ram_analyzer/L0L1/src/post_handlers.py index f5fa3af..c4cf9ac 100644 --- a/tools/rom_ram_analyzer/L0L1/src/post_handlers.py +++ b/tools/rom_ram_analyzer/L0L1/src/post_handlers.py @@ -3,7 +3,6 @@ from abc import ABC, abstractmethod import copy import logging import preprocess -from pprint import pprint from pkgs.simple_yaml_tool import SimpleYamlTool _config = SimpleYamlTool.read_yaml("./config.yaml") diff --git a/tools/rom_ram_analyzer/L0L1/src/rom_analysis.py b/tools/rom_ram_analyzer/L0L1/src/rom_analysis.py index 7ef3d0a..11b8ce6 100644 --- a/tools/rom_ram_analyzer/L0L1/src/rom_analysis.py +++ b/tools/rom_ram_analyzer/L0L1/src/rom_analysis.py @@ -5,7 +5,6 @@ import logging import os from typing import * import copy -from pprint import pprint import preprocess from time import time from concurrent.futures import ThreadPoolExecutor, Future @@ -13,7 +12,7 @@ from threading import RLock import collections from gn_lineno_collector import gn_lineno_collect -from config import result_dict, collector_config, configs, project_path, sub_com_dict +from config import result_dict, collector_config, configs, project_path, sub_com_dict, product_name, recollect_gn # from gn_info_collect import GnInfoCollector from pkgs.basic_tool import BasicTool from pkgs.gn_common_tool import GnCommonTool @@ -31,15 +30,15 @@ from pkgs.simple_excel_writer import SimpleExcelWriter """ -def parse_args(): - parser = argparse.ArgumentParser( - description="analysis rom size of L0 and L1 product") - parser.add_argument("-p", "--product_name", type=str, default="ipcamera_hispark_taurus_linux", - help="product name. eg: -p ipcamera_hispark_taurus") - parser.add_argument("-r", "--recollect_gn", type=bool, - default=True, help="if recollect gn info or not") - args = parser.parse_args() - return args +# def parse_args(): +# parser = argparse.ArgumentParser( +# description="analysis rom size of L0 and L1 product") +# parser.add_argument("-p", "--product_name", type=str, default="ipcamera_hispark_taurus_linux", +# help="product name. eg: -p ipcamera_hispark_taurus") +# parser.add_argument("-r", "--recollect_gn", type=bool, +# default=True, help="if recollect gn info or not") +# args = parser.parse_args() +# return args class RomAnalysisTool: @@ -270,10 +269,7 @@ class RomAnalysisTool: def main(): - args = parse_args() - product_name = args.product_name - re_collect_gn_info = args.recollect_gn - if re_collect_gn_info: + if recollect_gn: RomAnalysisTool.collect_gn_info() product_dict: Dict[str, List[str] ] = RomAnalysisTool.collect_product_info(product_name) diff --git a/tools/rom_ram_analyzer/L0L1/src/template_processor.py b/tools/rom_ram_analyzer/L0L1/src/template_processor.py index bfd0ac2..47d5697 100644 --- a/tools/rom_ram_analyzer/L0L1/src/template_processor.py +++ b/tools/rom_ram_analyzer/L0L1/src/template_processor.py @@ -17,7 +17,6 @@ from threading import RLock from typing import * from abc import ABC, abstractmethod from collections import defaultdict -from pprint import pprint import os import logging diff --git a/tools/rom_ram_analyzer/L2/README.md b/tools/rom_ram_analyzer/L2/README.md index 7aac190..7496583 100644 --- a/tools/rom_ram_analyzer/L2/README.md +++ b/tools/rom_ram_analyzer/L2/README.md @@ -14,7 +14,7 @@ 1. 获取整个rom_ram_analyzer目录 1. 对系统进行编译 -1. linux平台 +1. rom分析在linux平台,ram分析在windows平台 1. python3.8及以后 1. 安装requirements ```txt -- Gitee