diff --git a/category/get_perf_info.py b/category/get_perf_info.py index 840e4f29e54bf3307c9e0c62b489de2091182783..fb4e8e08c3e575445b3ef5fec3083e2b697d6c1e 100644 --- a/category/get_perf_info.py +++ b/category/get_perf_info.py @@ -269,17 +269,23 @@ class Perf(): Logger().debug("write perf flame svg info error") return False - # perf main function - @GlobalCall.monitor_info_thread_pool.threaded_pool - def do_perf_collect(self): - Logger().info("Perf数据采集开始") + def __check_and_execute_perf_steps(self): try: self.__set_perf_parameter() - if self.__check_perf_parameter(): - if self.__get_perf_collect(): - self.__do_perf_flamegraph() + if not self.__check_perf_parameter(): + return False + if not self.__get_perf_collect(): + return False + self.__do_perf_flamegraph() except Exception as e: Logger().debug("do perf collect error: {}".format(e)) + return True + + # perf main function + @GlobalCall.monitor_info_thread_pool.threaded_pool + def do_perf_collect(self): + Logger().info("Perf数据采集开始") + self.__check_and_execute_perf_steps() Logger().info("Perf数据采集结束") diff --git a/common/command.py b/common/command.py index 2abbe6fd25541ba9d59f9af7b86cf38197d18ec7..9d9ef299b0ab334b1d297e3fcfa79a48a8cd5160 100644 --- a/common/command.py +++ b/common/command.py @@ -10,6 +10,8 @@ from common.log import Logger from common.file import FileOperation class Command: + LANG = 'en_US.UTF-8' + BASH = "/bin/sh" @staticmethod def call(cmd, caller = ''): @@ -47,27 +49,28 @@ class Command: def cmd_run(cmd, caller = ''): ''' Encapsulate the general RUN function, get the result + return: cmd + '\n' + cmd结果 ''' command_result = '' try: env_c = os.environ - env_c['LANG'] = 'en_US.UTF-8' + env_c['LANG'] = Command.LANG check_cmd = cmd.split() if check_cmd[0] == 'cat' or check_cmd[0] == 'ls': if not os.path.exists(check_cmd[1]): - Logger().error("{} does not exist, cmd_run {} unable to execute".format(check_cmd[1], cmd)) + Logger().error("{} 不存在, cmd_run 命令 {} 无法执行".format(check_cmd[1], cmd)) return command_result if cmd == "top -b -n 3": env = os.environ.copy() env['COLUMNS'] = '132' # 设置输出宽度为132列 - ret = subprocess.Popen(["/bin/sh", "-c", cmd], stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env) + ret = subprocess.Popen([Command.BASH, "-c", cmd], stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env) else: - ret = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) + ret = subprocess.Popen([Command.BASH, "-c", cmd], stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) stdout,stderr = ret.communicate() - if not sys.version_info[0] >= 3: + if sys.version_info[0] < 3: stdout = stdout.replace('\x1b[7l', '') if Command.cmd_check(stdout, stderr, ret.returncode, cmd): command_result = cmd + '\n'+ stdout.decode('utf8') @@ -75,7 +78,7 @@ class Command: return command_result except Exception as err: - Logger().error("An exception occurred when executing [{}]: {}".format(cmd, err)) + Logger().error("001:An exception occurred when executing [{}]: {}".format(cmd, err)) return command_result @staticmethod