[commit: ghc] master: Include original process name in worker thread name (#14153) (d07b8c7)

git at git.haskell.org git at git.haskell.org
Tue Sep 26 02:44:30 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d07b8c7ae8bc22a7c36c96cb3fd800aecdde6eac/ghc

>---------------------------------------------------------------

commit d07b8c7ae8bc22a7c36c96cb3fd800aecdde6eac
Author: Echo Nolan <echo at echonolan.net>
Date:   Mon Sep 25 18:33:30 2017 -0400

    Include original process name in worker thread name (#14153)
    
    Prior to this commit, worker OS thread were renamed to "ghc_worker" when
    spawned. This was annoying when reading debugging messages that print
    the process name because it doesn't tell you *which* Haskell program is
    generating the message.
    
    This commit changes it to "original_process_name:w", truncating the
    original name to fit in the kernel buffer if neccesary.
    
    Test Plan: ./validate
    
    Reviewers: austin, bgamari, erikd, simonmar
    
    Reviewed By: bgamari
    
    Subscribers: Phyx, rwbarton, thomie
    
    Differential Revision: https://phabricator.haskell.org/D4001


>---------------------------------------------------------------

d07b8c7ae8bc22a7c36c96cb3fd800aecdde6eac
 rts/Task.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/rts/Task.c b/rts/Task.c
index 4376148..fc928d5 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -19,6 +19,8 @@
 #include "Hash.h"
 #include "Trace.h"
 
+#include <string.h>
+
 #if HAVE_SIGNAL_H
 #include <signal.h>
 #endif
@@ -468,7 +470,26 @@ startWorkerTask (Capability *cap)
   ASSERT_LOCK_HELD(&cap->lock);
   cap->running_task = task;
 
-  r = createOSThread(&tid, "ghc_worker", (OSThreadProc*)workerStart, task);
+  // Set the name of the worker thread to the original process name followed by
+  // ":w", but only if we're on Linux where the program_invocation_short_name
+  // global is available.
+#if defined(linux_HOST_OS)
+  size_t procname_len = strlen(program_invocation_short_name);
+  char worker_name[16];
+  // The kernel only allocates 16 bytes for thread names, so we truncate if the
+  // original name is too long. Process names go in another table that has more
+  // capacity.
+  if (procname_len >= 13) {
+      strncpy(worker_name, program_invocation_short_name, 13);
+      strcpy(worker_name + 13, ":w");
+  } else {
+      strcpy(worker_name, program_invocation_short_name);
+      strcpy(worker_name + procname_len, ":w");
+  }
+#else
+  char * worker_name = "ghc_worker";
+#endif
+  r = createOSThread(&tid, worker_name, (OSThreadProc*)workerStart, task);
   if (r != 0) {
     sysErrorBelch("failed to create OS thread");
     stg_exit(EXIT_FAILURE);



More information about the ghc-commits mailing list