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

Cheng Shao (@TerrorJack) gitlab at gitlab.haskell.org
Thu Mar 7 08:17:02 UTC 2024



Cheng Shao pushed to branch wip/T24515 at Glasgow Haskell Compiler / GHC


Commits:
9c9994a2 by Ben Gamari at 2024-03-07T08:16:05+00: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.

- - - - -
3d9aed44 by Cheng Shao at 2024-03-07T08:16:30+00:00
Revert "testsuite: include target exe extension in heap profile filenames"

This reverts commit 6f511c36f9845a6e3731e658de4992bfd9806a52.

- - - - -


5 changed files:

- rts/ProfHeap.c
- rts/Profiling.c
- rts/RtsUtils.c
- rts/RtsUtils.h
- testsuite/driver/testlib.py


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(stem, ".exe");
+#elif defined(wasm32_HOST_ARCH)
+        dropExtension(stem, ".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(wasm32_HOST_ARCH)
+        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"


=====================================
testsuite/driver/testlib.py
=====================================
@@ -2332,11 +2332,11 @@ async def check_hp_ok(name: TestName) -> bool:
     actual_name = name + exe_extension() if not opts.ignore_extension else name
 
     # do not qualify for hp2ps because we should be in the right directory
-    hp2psCmd = 'cd "{opts.testdir}" && {{hp2ps}} {actual_name}'.format(**locals())
+    hp2psCmd = 'cd "{opts.testdir}" && {{hp2ps}} {name}'.format(**locals())
 
     hp2psResult = await runCmd(hp2psCmd, print_output=True)
 
-    actual_ps_path = in_testdir(actual_name, 'ps')
+    actual_ps_path = in_testdir(name, 'ps')
 
     if hp2psResult == 0:
         if actual_ps_path.exists():
@@ -2345,15 +2345,15 @@ async def check_hp_ok(name: TestName) -> bool:
                 if (gsResult == 0):
                     return True
                 else:
-                    print("hp2ps output for " + actual_name + " is not valid PostScript")
+                    print("hp2ps output for " + name + " is not valid PostScript")
                     return False
             else:
                 return True # assume postscript is valid without ghostscript
         else:
-            print("hp2ps did not generate PostScript for " + actual_name)
+            print("hp2ps did not generate PostScript for " + name)
             return  False
     else:
-        print("hp2ps error when processing heap profile for " + actual_name)
+        print("hp2ps error when processing heap profile for " + name)
         return False
 
 async def check_prof_ok(name: TestName, way: WayName) -> bool:



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/56c3cac08ae0d28e797527487699cbae858985d7...3d9aed44cf82ce2ebebcdca4d901f7f68913ce34

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/56c3cac08ae0d28e797527487699cbae858985d7...3d9aed44cf82ce2ebebcdca4d901f7f68913ce34
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/78930bfb/attachment-0001.html>


More information about the ghc-commits mailing list