From 21289634c1e9c45da6009f197807f5bc83fb2af5 Mon Sep 17 00:00:00 2001 From: sunzuhan Date: Sat, 13 Jan 2024 16:50:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9timeline=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8F=96=E5=80=BC=E9=97=AE=E9=A2=98=E5=92=8C=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=8A=A0=E5=9B=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/merge_profiling_timeline/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/profiler/merge_profiling_timeline/main.py b/profiler/merge_profiling_timeline/main.py index 3df7fc038..678f5d5a8 100644 --- a/profiler/merge_profiling_timeline/main.py +++ b/profiler/merge_profiling_timeline/main.py @@ -137,7 +137,7 @@ def merge_timeline_custom(args): timeline_files = natural_sort(os.listdir(args.input)) timeline_files_dict = {} for idx, timeline_file in enumerate(timeline_files): - timeline_files_dict[idx] = (os.path.join(args.input, timeline_file),0) + timeline_files_dict[idx] = os.path.join(args.input, timeline_file) # 合并部分profiling items process_list = args.items.split(",") if args.items else None merge_timeline_events(timeline_files_dict, process_list) @@ -183,8 +183,8 @@ def merge_timeline_events(timeline_file_dict, process_list): continue # convert tid to int - if isinstance(event.get("tid"), str): - event["tid"] = int(''.join(x for x in event["tid"] if x.isdigit())) + if not isinstance(event['tid'], int): + print(f"[WARNNING] {event['tid']} is not int type") # 进程名加上rank_id区分不同rank if event.get("name") == "process_name" and event.get("ph") == "M": @@ -204,7 +204,8 @@ def merge_timeline_events(timeline_file_dict, process_list): print(f"File {out_path} existed before and is now overwritten.") os.remove(out_path) try: - with open(out_path, 'w') as f: + # 设置文件权限为640,安全考虑 + with os.fdopen(os.open(out_path, os.O_WRONLY | os.O_CREAT, 0o640), 'w') as f: json.dump(new_events, f) except FileNotFoundError: print(f"Param -o (output path) is not exists, please check it.") -- Gitee