]> err.no Git - varnish/commitdiff
Attempt to name threads if possible.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Dec 2007 09:03:51 +0000 (09:03 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Dec 2007 09:03:51 +0000 (09:03 +0000)
On FreeBSD this means that for instance "top -H" will show the
varnish threads as "cache-foo" for various values of foo, hopefully
giving us another debugging hint.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2293 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_acceptor_epoll.c
varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
varnish-cache/bin/varnishd/cache_acceptor_poll.c
varnish-cache/bin/varnishd/cache_expire.c
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cache_pool.c

index 46a95809dbfd9e9d850a23690a22bfbf6ae31f97..8ff828d842cd6f493fc048f70359a30c03fbcbc7 100644 (file)
@@ -506,6 +506,9 @@ int HTC_Complete(struct http_conn *htc);
 #include "http_headers.h"
 #undef HTTPH
 
+/* cache_main.c */
+void THR_Name(const char *name);
+
 /* cache_pipe.c */
 void PipeSession(struct sess *sp);
 
index 9a82bc073ec73f8dcf9ee742fa1a8fc893262743..1e014e97356d41afb0de47b05431c9611ab344ef 100644 (file)
@@ -154,6 +154,7 @@ vca_acct(void *arg)
        unsigned u;
        double now;
 
+       THR_Name("cache-acceptor");
        (void)arg;
 
        /* Set up the poll argument */
index 34c1c9bf55f5e2f3159e48001aff4c8cc983daa2..21e62a8ce9cb8294ec9f9f4902ad1c79e6f4a693 100644 (file)
@@ -73,6 +73,7 @@ vca_main(void *arg)
        struct sess *sp, *sp2;
        int i;
 
+       THR_Name("cache-epoll");
        (void)arg;
 
        epfd = epoll_create(16);
index 128e79489af270f67ae400c89a4aaef47ade5a91..943ac37fb6dc4506d55f97e0b88c0924a2ddc753 100644 (file)
@@ -233,6 +233,7 @@ vca_kqueue_main(void *arg)
        double deadline;
        struct sess *sp;
 
+       THR_Name("cache-kqueue");
        (void)arg;
 
        kq = kqueue();
index f0f82ddd708d78cd858d629bda5fa2b237449dcc..b74f89a2ed39550ffc51ee7e6da388985c2bfbbd 100644 (file)
@@ -112,6 +112,7 @@ vca_main(void *arg)
        double deadline;
        int i, fd;
 
+       THR_Name("cache-poll");
        (void)arg;
 
        vca_poll(vca_pipes[0]);
index 5595fe708e9f29441bd89ec0a0ba54b23c095f46..3f8318a5277ebd35a172cf44155b5fb92da7cd7a 100644 (file)
@@ -114,6 +114,7 @@ exp_hangman(void *arg)
        struct object *o;
        double t;
 
+       THR_Name("cache-hangman");
        (void)arg;
 
        t = TIM_real();
@@ -167,6 +168,7 @@ exp_prefetch(void *arg)
        struct object *o2;
        unsigned char log[1024];                /* XXX size ? */
 
+       THR_Name("cache-timeout");
        (void)arg;
 
        sp = SES_New(NULL, 0);
index 4882d2b16fa2a9a80e8625a212d8e977927b7383..7b41eb60293a28c1ec7adefc12c8fef9a1c02520 100644 (file)
 #include "heritage.h"
 #include "stevedore.h"
 
+/*--------------------------------------------------------------------
+ * Name threads if our pthreads implementation supports it.
+ */
+
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+
+void
+THR_Name(const char *name)
+{
+#ifdef HAVE_PTHREAD_SET_NAME_NP
+       pthread_set_name_np(pthread_self(), name);
+#else
+       /*
+        * XXX: we could stash it somewhere else (TLS ?)
+        */
+       (void)name;
+#endif
+}
+
 /*--------------------------------------------------------------------
  * XXX: Think more about which order we start things
  */
@@ -51,6 +72,8 @@ child_main(void)
        setbuf(stderr, NULL);
        printf("Child starts\n");
 
+       THR_Name("cache-main");
+
 #define SZOF(foo)      printf("sizeof(%s) = %zd\n", #foo, sizeof(foo));
        SZOF(struct ws);
        SZOF(struct http);
index 96c6bb308737e92b807c542adc706984950469c6..dba99507c90fae4eec56e6b2a9b1d64cb88b8083 100644 (file)
@@ -205,6 +205,7 @@ wrk_thread(void *priv)
        char c;
        unsigned char wlog[8192];       /* XXX: size */
 
+       THR_Name("cache-worker");
        w = &ww;
        qp = priv;
        memset(w, 0, sizeof *w);