From 4002d2d272092c644dadaef69a28e49fb2945cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 27 Oct 2004 12:50:48 +0000 Subject: [PATCH] Improved state_to_text() output to match the states in get_thread_info(). Improved the threads list: despite looking much better, it now also prints out the semaphore number a thread is waiting on. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9530 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/thread.c | 49 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 5d4f680924..8a11701ef7 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -409,19 +409,29 @@ create_thread(const char *name, team_id teamID, thread_entry_func entry, static const char * -state_to_text(int state) +state_to_text(struct thread *thread, int32 state) { switch (state) { case B_THREAD_READY: - return "READY"; + return "ready"; + case B_THREAD_RUNNING: - return "RUNNING"; + return "running"; + case B_THREAD_WAITING: - return "WAITING"; + if (thread->sem.blocking == sSnoozeSem) + return "zzz"; + if (thread->sem.blocking == thread->msg.read_sem) + return "receive"; + + return "waiting"; + case B_THREAD_SUSPENDED: - return "SUSPEND"; + return "suspended"; + case THREAD_STATE_FREE_ON_RESCHED: - return "DEATH"; + return "death"; + default: return "UNKNOWN"; } @@ -439,8 +449,8 @@ _dump_thread_info(struct thread *t) dprintf("all_next: %p\nteam_next: %p\nq_next: %p\n", t->all_next, t->team_next, t->queue_next); dprintf("priority: 0x%lx\n", t->priority); - dprintf("state: %s\n", state_to_text(t->state)); - dprintf("next_state: %s\n", state_to_text(t->next_state)); + dprintf("state: %s\n", state_to_text(t, t->state)); + dprintf("next_state: %s\n", state_to_text(t, t->next_state)); dprintf("cpu: %p ", t->cpu); if (t->cpu) dprintf("(%d)\n", t->cpu->info.cpu_num); @@ -517,20 +527,25 @@ dump_thread_list(int argc, char **argv) struct thread *t; struct hash_iterator i; + dprintf("thread id state sem cpu stack name\n"); + hash_open(sThreadHash, &i); while ((t = hash_next(sThreadHash, &i)) != NULL) { - dprintf("%p", t); - if (t->name != NULL) - dprintf("\t%32s", t->name); + dprintf("%p %6lx %-9s", t, t->id, state_to_text(t, t->state)); + + // does it block on a semaphore? + if (t->state == B_THREAD_WAITING) + dprintf("%6lx ", t->sem.blocking); else - dprintf("\t%32s", ""); - dprintf("\t0x%lx", t->id); - dprintf("\t%16s", state_to_text(t->state)); + dprintf(" - "); + + // on which CPU does it run? if (t->cpu) - dprintf("\t%d", t->cpu->info.cpu_num); + dprintf("%2d", t->cpu->info.cpu_num); else - dprintf("\tNOCPU"); - dprintf("\t0x%lx\n", t->kernel_stack_base); + dprintf(" -"); + + dprintf(" %p %s\n", (void *)t->kernel_stack_base, t->name != NULL ? t->name : ""); } hash_close(sThreadHash, &i, false); return 0;