From e60b07f94cb64801e026f48368d22a63f520b7df Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Sat, 18 Mar 2023 13:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao --- tools/rom_ram_analyzer/lite_small/__init__.py | 16 +++++++++ .../lite_small/pkgs/__init__.py | 16 +++++++++ .../lite_small/pkgs/basic_tool.py | 1 + .../lite_small/pkgs/gn_common_tool.py | 3 +- .../lite_small/pkgs/simple_excel_writer.py | 18 ++++++++++ .../lite_small/pkgs/simple_yaml_tool.py | 17 +++++++++ .../lite_small/src/__init__.py | 17 +++++++++ .../rom_ram_analyzer/lite_small/src/config.py | 19 ++++++++++ .../lite_small/src/config.yaml | 6 ++-- .../lite_small/src/get_subsystem_component.py | 35 ++++++++++++++----- tools/rom_ram_analyzer/lite_small/src/misc.py | 18 ++++++++++ .../lite_small/src/preprocess.py | 17 +++++++++ .../lite_small/src/rom_analysis.py | 17 +++++++++ .../lite_small/src/template_processor.py | 5 ++- tools/rom_ram_analyzer/standard/__init__.py | 16 +++++++++ .../rom_ram_analyzer/standard/ram_analyzer.py | 18 ++++++++++ .../rom_ram_analyzer/standard/rom_analyzer.py | 17 +++++++++ 17 files changed, 242 insertions(+), 14 deletions(-) diff --git a/tools/rom_ram_analyzer/lite_small/__init__.py b/tools/rom_ram_analyzer/lite_small/__init__.py index e69de29..dba1066 100644 --- a/tools/rom_ram_analyzer/lite_small/__init__.py +++ b/tools/rom_ram_analyzer/lite_small/__init__.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is only for indication this folder is a python package. \ No newline at end of file diff --git a/tools/rom_ram_analyzer/lite_small/pkgs/__init__.py b/tools/rom_ram_analyzer/lite_small/pkgs/__init__.py index e69de29..583ec11 100644 --- a/tools/rom_ram_analyzer/lite_small/pkgs/__init__.py +++ b/tools/rom_ram_analyzer/lite_small/pkgs/__init__.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file only indicates that the directory it resides is a python package \ No newline at end of file diff --git a/tools/rom_ram_analyzer/lite_small/pkgs/basic_tool.py b/tools/rom_ram_analyzer/lite_small/pkgs/basic_tool.py index b04afab..512ed59 100644 --- a/tools/rom_ram_analyzer/lite_small/pkgs/basic_tool.py +++ b/tools/rom_ram_analyzer/lite_small/pkgs/basic_tool.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tools/rom_ram_analyzer/lite_small/pkgs/gn_common_tool.py b/tools/rom_ram_analyzer/lite_small/pkgs/gn_common_tool.py index 66ebb21..d12eb4b 100644 --- a/tools/rom_ram_analyzer/lite_small/pkgs/gn_common_tool.py +++ b/tools/rom_ram_analyzer/lite_small/pkgs/gn_common_tool.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,8 +12,8 @@ # 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. -# +# This file contains some Classes for gn's BUILD.gn import os import logging diff --git a/tools/rom_ram_analyzer/lite_small/pkgs/simple_excel_writer.py b/tools/rom_ram_analyzer/lite_small/pkgs/simple_excel_writer.py index 94a9496..da6f3c6 100644 --- a/tools/rom_ram_analyzer/lite_small/pkgs/simple_excel_writer.py +++ b/tools/rom_ram_analyzer/lite_small/pkgs/simple_excel_writer.py @@ -1,3 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file contains a SimpleExcelWriter, which is a implemented based on xlwt for easy use. + + import xlwt from xlwt import Worksheet, Pattern as PTRN, Alignment as ALGT, Font as FT, XFStyle as XFSL import typing diff --git a/tools/rom_ram_analyzer/lite_small/pkgs/simple_yaml_tool.py b/tools/rom_ram_analyzer/lite_small/pkgs/simple_yaml_tool.py index 5edf612..32cb530 100644 --- a/tools/rom_ram_analyzer/lite_small/pkgs/simple_yaml_tool.py +++ b/tools/rom_ram_analyzer/lite_small/pkgs/simple_yaml_tool.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file contains a SimpleYamlTool, which is a implemented based on the package named yaml for easy use. + import yaml from typing import * from yaml.loader import SafeLoader diff --git a/tools/rom_ram_analyzer/lite_small/src/__init__.py b/tools/rom_ram_analyzer/lite_small/src/__init__.py index 341988c..aafe597 100644 --- a/tools/rom_ram_analyzer/lite_small/src/__init__.py +++ b/tools/rom_ram_analyzer/lite_small/src/__init__.py @@ -1 +1,18 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file only indicates that the directory it resides is a python package + VERSION = 1.0 diff --git a/tools/rom_ram_analyzer/lite_small/src/config.py b/tools/rom_ram_analyzer/lite_small/src/config.py index fd8af4a..a557af6 100644 --- a/tools/rom_ram_analyzer/lite_small/src/config.py +++ b/tools/rom_ram_analyzer/lite_small/src/config.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is a configuration for scaning the BUILD.gn to collection compile +# products. + + import os import sys import argparse diff --git a/tools/rom_ram_analyzer/lite_small/src/config.yaml b/tools/rom_ram_analyzer/lite_small/src/config.yaml index 17f5568..f3394b2 100644 --- a/tools/rom_ram_analyzer/lite_small/src/config.yaml +++ b/tools/rom_ram_analyzer/lite_small/src/config.yaml @@ -167,9 +167,9 @@ hispark_pegasus_mini_system: - lite_library - target -rk3568: # rk的目前从packages/phone/system_module_info.json中分析准确度更高,因为rk基本都使用的是ohos_xxx,而lite/small的更多的是使用的gn原生target template - product_infofile: rk3568_product.json - output_name: rk3568_result.json +rk3568_mini_system: # rk的目前从packages/phone/system_module_info.json中分析准确度更高,因为rk基本都使用的是ohos_xxx,而lite/small的更多的是使用的gn原生target template + product_infofile: rk3568_mini_system_product.json + output_name: rk3568_mini_system_result.json product_dir: root: out/rk3568/packages/phone/system relative: diff --git a/tools/rom_ram_analyzer/lite_small/src/get_subsystem_component.py b/tools/rom_ram_analyzer/lite_small/src/get_subsystem_component.py index 3ed3847..2dbd476 100644 --- a/tools/rom_ram_analyzer/lite_small/src/get_subsystem_component.py +++ b/tools/rom_ram_analyzer/lite_small/src/get_subsystem_component.py @@ -1,4 +1,20 @@ -#! /usr/bin/python +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is for get the mapping relationship of subsystem_name/component_name +# and their directory. The code is from Yude Chen. import argparse import os @@ -25,7 +41,7 @@ def get_subsystem_components(ohos_path: str): if not os.path.exists(subsystem_path): g_subsystem_path_error.append(subsystem_path) continue - cmd = 'find ' + subsystem_path + ' -name bundle.json' + cmd = 'find {} -name bundle.json'.format(subsystem_path) bundle_json_list = os.popen(cmd).readlines() # get components component_list = [] @@ -41,7 +57,7 @@ def get_subsystem_components(ohos_path: str): g_component_abs_path.append(destpath) else: component_item[bundle_json["component"]["name"] - ] = "Unknow. Please check " + bundle_path + ] = "Unknow. Please check {}".format(bundle_path) g_component_path_empty.append(bundle_path) component_list.append(component_item) subsystem_item[subsystem_name] = component_list @@ -65,7 +81,7 @@ def export_to_json(subsystem_item: dict, output_filename: str): subsystem_item, indent=4, separators=(', ', ': ')) with open(output_filename, 'w') as f: f.write(subsystem_item_json) - logging.info("output path: " + output_filename) + logging.info("output path: {}".format(output_filename)) def parse_args(): @@ -77,7 +93,7 @@ def parse_args(): ohos_path = os.path.abspath(args.project) if not is_project(ohos_path): - logging.error("'" + ohos_path + "' is not a valid project path.") + logging.error("'{}' is not a valid project path.".format(ohos_path)) exit(1) output_path = r'.' @@ -93,7 +109,7 @@ def is_project(path: str) -> bool: @note: 通过是否含有 .repo/manifests 目录粗略判断。 ''' p = os.path.normpath(path) - return os.path.exists(p + '/.repo/manifests') + return os.path.exists('{}/.repo/manifests'.format(p)) def print_warning_info(): @@ -126,6 +142,7 @@ __all__ = ["SC"] if __name__ == '__main__': ohos_path, output_path = parse_args() - info = get_subsystem_components_modified(ohos_path) - export_to_json(info, output_path) - print_warning_info() + # info = get_subsystem_components_modified(ohos_path) + # export_to_json(info, output_path) + # print_warning_info() + SC.run(ohos_path, output_path) diff --git a/tools/rom_ram_analyzer/lite_small/src/misc.py b/tools/rom_ram_analyzer/lite_small/src/misc.py index bc079a6..79af85b 100644 --- a/tools/rom_ram_analyzer/lite_small/src/misc.py +++ b/tools/rom_ram_analyzer/lite_small/src/misc.py @@ -1,3 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is for get the mapping relationship of subsystem_name/component_name +# and their directory. The code is from Yude Chen. + import logging import copy import os diff --git a/tools/rom_ram_analyzer/lite_small/src/preprocess.py b/tools/rom_ram_analyzer/lite_small/src/preprocess.py index 19b9ae9..6f8ce5e 100644 --- a/tools/rom_ram_analyzer/lite_small/src/preprocess.py +++ b/tools/rom_ram_analyzer/lite_small/src/preprocess.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is writting for do some preprocess work + import sys import os # 将上级目录加入到库的搜索路径 diff --git a/tools/rom_ram_analyzer/lite_small/src/rom_analysis.py b/tools/rom_ram_analyzer/lite_small/src/rom_analysis.py index e8e7b97..e925539 100644 --- a/tools/rom_ram_analyzer/lite_small/src/rom_analysis.py +++ b/tools/rom_ram_analyzer/lite_small/src/rom_analysis.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is for rom analyzation of lite/small devices. + import sys import argparse import json diff --git a/tools/rom_ram_analyzer/lite_small/src/template_processor.py b/tools/rom_ram_analyzer/lite_small/src/template_processor.py index 8e3a9e4..64d19a4 100644 --- a/tools/rom_ram_analyzer/lite_small/src/template_processor.py +++ b/tools/rom_ram_analyzer/lite_small/src/template_processor.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,7 +12,9 @@ # 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. -# + +# This file contains some template processor to collection information +# from some gn's template in BUILD.gn from typing import * from abc import ABC, abstractmethod diff --git a/tools/rom_ram_analyzer/standard/__init__.py b/tools/rom_ram_analyzer/standard/__init__.py index e69de29..dba1066 100644 --- a/tools/rom_ram_analyzer/standard/__init__.py +++ b/tools/rom_ram_analyzer/standard/__init__.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is only for indication this folder is a python package. \ No newline at end of file diff --git a/tools/rom_ram_analyzer/standard/ram_analyzer.py b/tools/rom_ram_analyzer/standard/ram_analyzer.py index c3863af..a68d77f 100644 --- a/tools/rom_ram_analyzer/standard/ram_analyzer.py +++ b/tools/rom_ram_analyzer/standard/ram_analyzer.py @@ -1,3 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file is to implement the rom analyzation of standard device. +# + import argparse import copy import glob diff --git a/tools/rom_ram_analyzer/standard/rom_analyzer.py b/tools/rom_ram_analyzer/standard/rom_analyzer.py index 30085ab..35504fa 100644 --- a/tools/rom_ram_analyzer/standard/rom_analyzer.py +++ b/tools/rom_ram_analyzer/standard/rom_analyzer.py @@ -1,3 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 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. + +# This file contains a RomAnalyzer for rom analyzation of standard device. + import argparse import json import os -- Gitee