From c93c88affe57af8429878c042a4881425aea2363 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Sat, 6 Dec 2025 21:06:18 -0500 Subject: [PATCH 1/3] Fix perfmap output --- src/coreclr/vm/perfmap.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 74be61ed435527..04a5b9ce1cbd5f 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -261,14 +261,16 @@ void PerfMap::WriteLine(SString& line) EX_TRY { // Write the line. - - if (fprintf(m_fp, "%s", line.GetUTF8()) != 0) + int fd = fileno(m_fp); + const char* buf = line.GetUTF8(); + size_t len = line.GetCount(); + ssize_t written = write(fd, buf, len); + if (written < 0 || (size_t)written != len) { // This will cause us to stop writing to the file. // The file will still remain open until shutdown so that we don't have to take a lock at this level when we touch the file stream. m_ErrorEncountered = true; } - } EX_CATCH{} EX_END_CATCH } From d18f1ca3cb42f11e2ea9f61b9d20b510581590f8 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Mon, 8 Dec 2025 01:39:43 -0500 Subject: [PATCH 2/3] Use fprintf as it is more performant than write for perfmaps --- src/coreclr/vm/perfmap.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 04a5b9ce1cbd5f..27fc0d4ca8927f 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -261,11 +261,7 @@ void PerfMap::WriteLine(SString& line) EX_TRY { // Write the line. - int fd = fileno(m_fp); - const char* buf = line.GetUTF8(); - size_t len = line.GetCount(); - ssize_t written = write(fd, buf, len); - if (written < 0 || (size_t)written != len) + if (fprintf(m_fp, "%s", line.GetUTF8()) != line.GetCount()) { // This will cause us to stop writing to the file. // The file will still remain open until shutdown so that we don't have to take a lock at this level when we touch the file stream. From f5a49ad5a169013e8b41b666621d76633a97e328 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Mon, 8 Dec 2025 11:08:19 -0500 Subject: [PATCH 3/3] Avoid potential inadvertant conversation to unicode with SString.GetCount --- src/coreclr/vm/perfmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index 27fc0d4ca8927f..f2cc1212595891 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -261,7 +261,7 @@ void PerfMap::WriteLine(SString& line) EX_TRY { // Write the line. - if (fprintf(m_fp, "%s", line.GetUTF8()) != line.GetCount()) + if (fprintf(m_fp, "%s", line.GetUTF8()) < 0) { // This will cause us to stop writing to the file. // The file will still remain open until shutdown so that we don't have to take a lock at this level when we touch the file stream.