From 1c3db3886b91ffaf8252d84ffe547e67c19eea4e Mon Sep 17 00:00:00 2001 From: rpone Date: Sat, 31 Oct 2026 01:10:10 +0800 Subject: [PATCH] fix(metal): only a process that sampled writes cpu.profile A process without samples no longer rewrites the file, and none truncates it. Not yet confirmed on hardware: the last run's profile stayed at zero samples. --- NativeBridgeMetalFrontend.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NativeBridgeMetalFrontend.mm b/NativeBridgeMetalFrontend.mm index ca0900f..1587a6c 100644 --- a/NativeBridgeMetalFrontend.mm +++ b/NativeBridgeMetalFrontend.mm @@ -312,8 +312,8 @@ static void sampleWriteProfile(uint32_t &consumed,int &fd,const char *const *pat if(!dup){seen[count++]=name;inclusiveMap[name]++;} } } - if(++rounds%12)return; - if(fd<0)for(int i=0;i<2 && fd<0;i++)fd=open(paths[i],O_WRONLY|O_CREAT|O_TRUNC,0644); + if(++rounds%12 || !total)return; // a process that never sampled must not overwrite the one that did + if(fd<0)for(int i=0;i<2 && fd<0;i++)fd=open(paths[i],O_WRONLY|O_CREAT,0644); // no O_TRUNC: the file keeps its fixed size if(fd<0)return; auto top=[&](std::unordered_map &map,char tag,unsigned limit,std::string &out) { std::vector> rows;