diff --git a/category/get_cpu_info.py b/category/get_cpu_info.py index 2f6f46fa900076a502831a2e81afabd1cf81504b..037e4d8a72beb5bc6982b5785f394782e26e29d8 100644 --- a/category/get_cpu_info.py +++ b/category/get_cpu_info.py @@ -134,24 +134,40 @@ class CPUInfo: return res_perf_stat + # top + def __get_top_info_task4(self): + cmd_name_top = 'top' + top_command = "top -b -n 3" + + cmd_result = Command.cmd_run(top_command) + cmd_results = cmd_result.split('\n\n') + # 保留top最后一次的结果 + last_two_result = cmd_results[-2:] + cmd_result = top_command + '\n' + '\n\n'.join(last_two_result) + res_top = FileOperation.wrap_output_format(cmd_name_top, cmd_result,'=') + + return res_top + @GlobalCall.monitor_info_thread_pool.threaded_pool def __get_top_info(self, interval , times): ''' - uptime,dstat,perf stat - ''' + uptime,dstat,perf stat,top + ''' task_uptime = CustomizeFunctionThread(self.__get_top_info_task1) task_dstat = CustomizeFunctionThread(self.__get_top_info_task2, (interval, times)) task_perf_stat = CustomizeFunctionThread(self.__get_top_info_task3) - + task_top = CustomizeFunctionThread(self.__get_top_info_task4) task_uptime.start() task_dstat.start() task_perf_stat.start() + task_top.start() task_uptime.join() task_dstat.join() task_perf_stat.join() - - res = task_uptime.get_result() + task_dstat.get_result() + task_perf_stat.get_result() - + task_top.join() + + res = task_uptime.get_result() + task_dstat.get_result() + task_perf_stat.get_result() + task_top.get_result() + return Command.cmd_write_file(res, self.__default_file_name) def __get_numastat_info(self):