[Git][ghc/ghc][wip/ghc-9.10] 2 commits: rts: Drop .wasm suffix from .prof file names

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Thu Mar 7 13:55:59 UTC 2024



Ben Gamari pushed to branch wip/ghc-9.10 at Glasgow Haskell Compiler / GHC


Commits:
30ca8bdf by Ben Gamari at 2024-03-06T23:49:36-05:00
rts: Drop .wasm suffix from .prof file names

This replicates the behavior on Windows, where `Hi.exe` will produce
profiling output named `Hi.prof` instead of `Hi.exe.prof`.

While in the area I also fixed the extension-stripping logic, which
incorrectly rewrote `Hi.exefoo` to `Hi.foo`.

Closes #24515.

- - - - -
2efba97d by Ben Gamari at 2024-03-06T23:49:54-05:00
rts: Fix SET_HDR initialization of retainer set

This fixes a regression in retainer set profiling introduced by
b0293f78cb6acf2540389e22bdda420d0ab874da. Prior to that commit
the heap traversal word would be initialized by `SET_HDR` using
`LDV_RECORD_CREATE`. However, the commit added a `doingLDVProfiling`
check in `LDV_RECORD_CREATE`, meaning that this initialization no longer
happened.

Given that this initialization was awkwardly indirectly anyways, I have
fixed this by explicitly initializating the heap traversal word to
`NULL` in `SET_PROF_HDR`. This is equivalent to the previous behavior,
but much more direct.

Fixes #24513.

- - - - -


5 changed files:

- rts/ProfHeap.c
- rts/Profiling.c
- rts/RtsUtils.c
- rts/RtsUtils.h
- rts/include/rts/storage/ClosureMacros.h


Changes:

=====================================
rts/ProfHeap.c
=====================================
@@ -448,18 +448,14 @@ initHeapProfiling(void)
         stem = stgMallocBytes(strlen(RtsFlags.CcFlags.outputFileNameStem) + 1, "initHeapProfiling");
         strcpy(stem, RtsFlags.CcFlags.outputFileNameStem);
     } else {
-
         stem = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling");
         strcpy(stem, prog_name);
+
+        // Drop the platform's executable suffix if there is one
 #if defined(mingw32_HOST_OS)
-            // on Windows, drop the .exe suffix if there is one
-            {
-                char *suff;
-                suff = strrchr(stem,'.');
-                if (suff != NULL && !strcmp(suff,".exe")) {
-                    *suff = '\0';
-                }
-            }
+        dropExtension(prog, ".exe");
+#elif defined(wasi32_HOST_OS)
+        dropExtension(prog, ".wasm");
 #endif
     }
 


=====================================
rts/Profiling.c
=====================================
@@ -245,19 +245,14 @@ initProfilingLogFile(void)
     if (RtsFlags.CcFlags.outputFileNameStem) {
         stem = RtsFlags.CcFlags.outputFileNameStem;
     } else {
-        char *prog;
-
-        prog = arenaAlloc(prof_arena, strlen(prog_name) + 1);
+        char *prog = arenaAlloc(prof_arena, strlen(prog_name) + 1);
         strcpy(prog, prog_name);
+
+        // Drop the platform's executable suffix if there is one
 #if defined(mingw32_HOST_OS)
-        // on Windows, drop the .exe suffix if there is one
-        {
-            char *suff;
-            suff = strrchr(prog,'.');
-            if (suff != NULL && !strcmp(suff,".exe")) {
-                *suff = '\0';
-            }
-        }
+        dropExtension(prog, ".exe");
+#elif defined(wasi32_HOST_OS)
+        dropExtension(prog, ".wasm");
 #endif
         stem = prog;
     }


=====================================
rts/RtsUtils.c
=====================================
@@ -456,3 +456,15 @@ void checkFPUStack(void)
     }
 #endif
 }
+
+// Drop the given extension from a filepath.
+void dropExtension(char *path, const char *extension) {
+    int ext_len = strlen(extension);
+    int path_len = strlen(path);
+    if (ext_len < path_len) {
+        char *s = &path[path_len - ext_len];
+        if (strcmp(s, extension) == 0) {
+            *s = '\0';
+        }
+    }
+}


=====================================
rts/RtsUtils.h
=====================================
@@ -62,4 +62,7 @@ void checkFPUStack(void);
 #define xstr(s) str(s)
 #define str(s) #s
 
+// Drop the given extension from a filepath.
+void dropExtension(char *path, const char *extension);
+
 #include "EndPrivate.h"


=====================================
rts/include/rts/storage/ClosureMacros.h
=====================================
@@ -147,17 +147,10 @@ EXTERN_INLINE StgHalfWord GET_TAG(const StgClosure *con)
 #if defined(PROFILING)
 /*
   The following macro works for both retainer profiling and LDV profiling. For
- retainer profiling, 'era' remains 0, so by setting the 'ldvw' field we also set
- 'rs' to zero.
-
- Note that we don't have to bother handling the 'flip' bit properly[1] since the
- retainer profiling code will just set 'rs' to NULL upon visiting a closure with
- an invalid 'flip' bit anyways.
-
- See Note [Profiling heap traversal visited bit] for details.
-
- [1]: Technically we should set 'rs' to `NULL | flip`.
+ retainer profiling, we set 'trav' to 0, which is an invalid
+ RetainerSet.
  */
+
 /*
   MP: Various other places use the check era > 0 to check whether LDV profiling
   is enabled. The use of these predicates here is the reason for including RtsFlags.h in
@@ -168,17 +161,14 @@ EXTERN_INLINE StgHalfWord GET_TAG(const StgClosure *con)
 */
 #define SET_PROF_HDR(c, ccs_) \
   { \
-  (c)->header.prof.ccs = ccs_; \
-  if (doingLDVProfiling()) { \
-    LDV_RECORD_CREATE((c)); \
-  } \
-\
-  if (doingRetainerProfiling()) { \
-    LDV_RECORD_CREATE((c)); \
-  }; \
-  if (doingErasProfiling()){ \
-    ERA_RECORD_CREATE((c)); \
-  }; \
+    (c)->header.prof.ccs = ccs_; \
+    if (doingLDVProfiling()) { \
+      LDV_RECORD_CREATE((c)); \
+    } else if (doingRetainerProfiling()) { \
+      (c)->header.prof.hp.trav = 0; \
+    } else if (doingErasProfiling()){ \
+      ERA_RECORD_CREATE((c)); \
+    } \
   }
 
 #else



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a6054b425e2bde8c246ca9a8d59b3c5bbfc39d23...2efba97d84ce32d50dd48a41955bcb2753b0e186

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a6054b425e2bde8c246ca9a8d59b3c5bbfc39d23...2efba97d84ce32d50dd48a41955bcb2753b0e186
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240307/303f2584/attachment-0001.html>


More information about the ghc-commits mailing list