From 6dde87f83ccd2eac808c1539ac40617695f2809f Mon Sep 17 00:00:00 2001 From: rsc Date: Mon, 26 Sep 2005 12:05:26 +0000 Subject: Print information on SIGQUIT, SIGINFO. --- src/libthread/thread.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/libthread/thread.c b/src/libthread/thread.c index da4afe12..145a5033 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -16,6 +16,7 @@ static void addthreadinproc(Proc*, _Thread*); static void delthreadinproc(Proc*, _Thread*); static void contextswitch(Context *from, Context *to); static void procscheduler(Proc*); +static int threadinfo(void*, char*); static void _threaddebug(char *fmt, ...) @@ -614,6 +615,7 @@ main(int argc, char **argv) _threadsetproc(p); if(mainstacksize == 0) mainstacksize = 256*1024; + atnotify(threadinfo, 1); _threadcreate(p, threadmainstart, nil, mainstacksize); procscheduler(p); sysfatal("procscheduler returned in threadmain!"); @@ -727,3 +729,42 @@ threadnotify(int (*f)(void*, char*), int in) { atnotify(f, in); } + +static int +onrunqueue(Proc *p, _Thread *t) +{ + _Thread *tt; + + for(tt=p->runqueue.head; tt; tt=tt->next) + if(tt == t) + return 1; + return 0; +} + +/* + * print state - called from SIGINFO + */ +static int +threadinfo(void *v, char *s) +{ + Proc *p; + _Thread *t; + + if(strcmp(s, "quit") != 0 && strcmp(s, "sys: status request") != 0) + return 0; + + for(p=_threadprocs; p; p=p->next){ + fprint(2, "proc %p %s%s\n", (void*)p->osprocid, p->msg, + p->sysproc ? " (sysproc)": ""); + for(t=p->allthreads.head; t; t=t->allnext){ + fprint(2, "\tthread %d %s: %s %s\n", + t->id, + t == p->thread ? "Running" : + onrunqueue(p, t) ? "Ready" : "Sleeping", + t->state, t->name); + } + } + return 1; +} + + -- cgit v1.2.3