diff --git a/common/tool_cmd.py b/common/tool_cmd.py index 75dcc58a9936852977a6c46b12181948be9500a0..9bfe41bed9872f8d189850517185bd027495b4d1 100644 --- a/common/tool_cmd.py +++ b/common/tool_cmd.py @@ -97,46 +97,28 @@ class ToolCmd: # end add for perf/offcpu command line parser check def args_help(self): - #共享可选参数wpath ipath opath - parent_parser = argparse.ArgumentParser(add_help=False) - parent_parser.add_argument('--work_path', type = str, default = '.', - help=argparse.SUPPRESS) - #help = 'User can specify the conf path. default is /usr/share/extuner/conf') - parent_parser.add_argument('--inst_path', type = str, default = '.', - help = argparse.SUPPRESS) - parent_parser.add_argument('-o','--out_path', type = str, default = '.', - help = 'include log and report, default is current directory') - #共享可选参数version - vparent_parser = argparse.ArgumentParser(add_help=False) - vparent_parser.add_argument('-v','--version' , action = 'version', version = self.__get_version(), - help = 'version') - - #共享可选参数cust_col 收集脚本 - cparent_parser = argparse.ArgumentParser(add_help=False) - cparent_parser.add_argument('--add', help = 'Extra collection data') - - #extuner命令 - parser = argparse.ArgumentParser( - description='''description:\n extuner is an expert tuning tool for Kylin system''', - formatter_class=argparse.RawDescriptionHelpFormatter, - prog='extuner', - parents=[vparent_parser], - usage=''' \n extuner [options] ''', - epilog='''examples:\n extuner collection --perf --pid -1''') - - subparsers = parser.add_subparsers(title = 'commands',prog='extuner',metavar=' ') - #子命令extuner collection - desc_c = 'collect the system data,such as CPU/MEM/NET/IO' - parser_col = subparsers.add_parser('collection', - parents=[parent_parser], - description='''description:\n {}'''.format(desc_c), - formatter_class=argparse.RawDescriptionHelpFormatter, - help='* {}'.format(desc_c)) - - parser_col.add_argument('--func', type = str, default = 'col', - help = argparse.SUPPRESS) + + usage_msg = 'extuner [options]\n' + usage_msg += ' --work_path Extuner working path\n' + usage_msg += ' --inst_path Extuner installed path\n' + usage_msg += ' --inst_path Output file path, including data, log and report\n' + usage_msg += ' --func Running function:\n' + usage_msg += ' col collect system info\n' + usage_msg += ' ana analyze system info\n' + + + # parrent + parent_parser = argparse.ArgumentParser(usage = usage_msg) + parent_parser.add_argument('--work_path' , type = str, default = '.', + help = 'Work path for extuner') + parent_parser.add_argument('--inst_path' , type = str, default = '.', + help = 'Install path for extuner tool') + parent_parser.add_argument('-o', '--out_path', type = str, default = '.', + help = 'Include log and report, default is current directory') + parent_parser.add_argument('--func' , type = str, default = 'col', + help = 'Running func in [\'col\', \'ana\']') - args = parser.parse_args() + args = parent_parser.parse_args() return args diff --git a/extuner.py b/extuner.py index 56c275181ae5894ee4faf0b1b871eb863c28ec7f..2f900ced26a12bb5a407e4f02fff5437457312e1 100644 --- a/extuner.py +++ b/extuner.py @@ -6,6 +6,7 @@ from common.log import Logger from common.tool_cmd import ToolCmd from summary_info import SummaryInfo from common.threadpool import ThreadPool +from kyreport.ky_report import KyReport import time # main function @@ -34,10 +35,7 @@ def main(): Logger().info("Extuner 开始执行") Timer["start"] = time.strftime("%Y-%m-%d %H:%M:%S") - if 'pro' == func[:3]: - SummaryInfo.set_scene(func,args) - - if 'col' == func or 'ana' == func: + if 'col' == func: #get 功能 ret = SummaryInfo.get_info() @@ -46,6 +44,8 @@ def main(): Timer["stop"] = time.strftime("%Y-%m-%d %H:%M:%S") - + + KyReport().ky_build(Timer) + Logger().info("Extuner 执行成功") # Logger().info("结果输出目录为 : {}".format(Config.path_format(os.path.abspath(Config.get_output_path())))) \ No newline at end of file diff --git a/kyreport/ky_report.py b/kyreport/ky_report.py index 2f1f86fdd0923a9ca4a014ce654617fb23e8c6db..53ca97a6e2dff9b29effb261da7857db0ba85179 100644 --- a/kyreport/ky_report.py +++ b/kyreport/ky_report.py @@ -3,13 +3,19 @@ # cython:language_level=3 # Copyright (c) 2023 KylinSoft  Co., Ltd. All Rights Reserved. +import os import time +import shutil +import json5 +from common.log import Logger from common.config import Config +from common.command import Command +from common.global_parameter import GlobalParameter from kyreport.ky_data_collection import DATACOLLECTION class KyReport: - - def ky_build(self, work, inst, tm): + @classmethod + def ky_build(self, tm): curr_time = time.strftime("%m%d%H%M") srcfile = Config.get_inst_path() + 'kyreport/extuner_report.html' outfile = Config.get_output_path() + 'extuner_report_' + curr_time + '.html' @@ -40,6 +46,7 @@ class KyReport: 'sys_param': [], 'sys_msg' : [], 'hotspot_info': [], + 'common_cmd': {} } # setting timer info @@ -69,22 +76,22 @@ class KyReport: # setting menu info if os.path.exists(Config.get_output_path() + 'CPUInfo.txt'): info['cpu_info'] = DATACOLLECTION().get_cpu_tag_data() - if os.path.exists(Config.get_output_path() + 'memInfo.txt'): - info['mem_info'] = self.build_info(Config.get_output_path() + 'memInfo.txt') - if os.path.exists(Config.get_output_path() + 'netInfo.txt'): - info['net_info'] = self.build_info(Config.get_output_path() + 'netInfo.txt') - if os.path.exists(Config.get_output_path() + 'diskInfo.txt'): - info['io_info'] = self.build_info(Config.get_output_path() + 'diskInfo.txt') - if os.path.exists(Config.get_output_path() + 'CPUInfo.txt'): - info['synthesis_info'] = DATACOLLECTION().get_synthesis_tag_data() - if os.path.exists(Config.get_output_path() + 'sysParamInfo.txt'): - info['sys_param'] = self.build_info(Config.get_output_path() + 'sysParamInfo.txt') - if os.path.exists(Config.get_output_path() + 'systemMessage.txt'): - info['sys_msg'] = self.build_info(Config.get_output_path() + 'systemMessage.txt') - if os.path.exists(Config.get_output_path() + 'hotspotInfo.txt'): - if os.path.getsize(Config.get_output_path() + 'hotspotInfo.txt'): - info['hotspot_info'] = self.build_info(Config.get_output_path() + 'hotspotInfo.txt') - + #if os.path.exists(Config.get_output_path() + 'memInfo.txt'): + # info['mem_info'] = self.build_info(Config.get_output_path() + 'memInfo.txt') + #if os.path.exists(Config.get_output_path() + 'netInfo.txt'): + # info['net_info'] = self.build_info(Config.get_output_path() + 'netInfo.txt') + #if os.path.exists(Config.get_output_path() + 'diskInfo.txt'): + # info['io_info'] = self.build_info(Config.get_output_path() + 'diskInfo.txt') + #if os.path.exists(Config.get_output_path() + 'CPUInfo.txt'): + # info['synthesis_info'] = DATACOLLECTION().get_synthesis_tag_data() + #if os.path.exists(Config.get_output_path() + 'sysParamInfo.txt'): + # info['sys_param'] = self.build_info(Config.get_output_path() + 'sysParamInfo.txt') + #if os.path.exists(Config.get_output_path() + 'systemMessage.txt'): + # info['sys_msg'] = self.build_info(Config.get_output_path() + 'systemMessage.txt') + #if os.path.exists(Config.get_output_path() + 'hotspotInfo.txt'): + # if os.path.getsize(Config.get_output_path() + 'hotspotInfo.txt'): + # info['hotspot_info'] = self.build_info(Config.get_output_path() + 'hotspotInfo.txt') + info['common_cmd']['pidstatinfo'] = GlobalParameter().pidstat_cmd info['common_cmd']['subsarinfo'] = GlobalParameter().sub_sarall # ending menu info