nsprpub/pr/src/threads/prdump.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/threads/prdump.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "primpl.h"
    1.10 +
    1.11 +#if defined(WIN95)
    1.12 +/*
    1.13 +** Some local variables report warnings on Win95 because the code paths 
    1.14 +** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
    1.15 +** The pragma suppresses the warning.
    1.16 +** 
    1.17 +*/
    1.18 +#pragma warning(disable : 4101)
    1.19 +#endif
    1.20 +
    1.21 +/* XXX use unbuffered nspr stdio */
    1.22 +
    1.23 +PRFileDesc *_pr_dumpOut;
    1.24 +
    1.25 +PRUint32 _PR_DumpPrintf(PRFileDesc *fd, const char *fmt, ...)
    1.26 +{
    1.27 +    char buf[100];
    1.28 +    PRUint32 nb;
    1.29 +    va_list ap;
    1.30 +
    1.31 +    va_start(ap, fmt);
    1.32 +    nb = PR_vsnprintf(buf, sizeof(buf), fmt, ap);
    1.33 +    va_end(ap);
    1.34 +    PR_Write(fd, buf, nb);
    1.35 +
    1.36 +    return nb;
    1.37 +}
    1.38 +
    1.39 +void _PR_DumpThread(PRFileDesc *fd, PRThread *thread)
    1.40 +{
    1.41 +
    1.42 +#ifndef _PR_GLOBAL_THREADS_ONLY
    1.43 +    _PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x",
    1.44 +                   thread->id, thread, thread->priority, thread->flags);
    1.45 +    switch (thread->state) {
    1.46 +      case _PR_RUNNABLE:
    1.47 +      case _PR_RUNNING:
    1.48 +        break;
    1.49 +      case _PR_LOCK_WAIT:
    1.50 +        _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
    1.51 +        break;
    1.52 +      case _PR_COND_WAIT:
    1.53 +        _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
    1.54 +                       thread->wait.cvar, thread->sleep);
    1.55 +        break;
    1.56 +      case _PR_SUSPENDED:
    1.57 +        _PR_DumpPrintf(fd, " suspended");
    1.58 +        break;
    1.59 +    }
    1.60 +    PR_Write(fd, "\n", 1);
    1.61 +#endif
    1.62 +
    1.63 +    /* Now call dump routine */
    1.64 +    if (thread->dump) {
    1.65 +	thread->dump(fd, thread, thread->dumpArg);
    1.66 +    }
    1.67 +}
    1.68 +
    1.69 +static void DumpThreadQueue(PRFileDesc *fd, PRCList *list)
    1.70 +{
    1.71 +#ifndef _PR_GLOBAL_THREADS_ONLY
    1.72 +    PRCList *q;
    1.73 +
    1.74 +    q = list->next;
    1.75 +    while (q != list) {
    1.76 +        PRThread *t = _PR_THREAD_PTR(q);
    1.77 +        _PR_DumpThread(fd, t);
    1.78 +        q = q->next;
    1.79 +    }
    1.80 +#endif
    1.81 +}
    1.82 +
    1.83 +void _PR_DumpThreads(PRFileDesc *fd)
    1.84 +{
    1.85 +    PRThread *t;
    1.86 +    PRIntn i;
    1.87 +
    1.88 +    _PR_DumpPrintf(fd, "Current Thread:\n");
    1.89 +    t = _PR_MD_CURRENT_THREAD();
    1.90 +    _PR_DumpThread(fd, t);
    1.91 +
    1.92 +    _PR_DumpPrintf(fd, "Runnable Threads:\n");
    1.93 +    for (i = 0; i < 32; i++) {
    1.94 +        DumpThreadQueue(fd, &_PR_RUNQ(t->cpu)[i]);
    1.95 +    }
    1.96 +
    1.97 +    _PR_DumpPrintf(fd, "CondVar timed wait Threads:\n");
    1.98 +    DumpThreadQueue(fd, &_PR_SLEEPQ(t->cpu));
    1.99 +
   1.100 +    _PR_DumpPrintf(fd, "CondVar wait Threads:\n");
   1.101 +    DumpThreadQueue(fd, &_PR_PAUSEQ(t->cpu));
   1.102 +
   1.103 +    _PR_DumpPrintf(fd, "Suspended Threads:\n");
   1.104 +    DumpThreadQueue(fd, &_PR_SUSPENDQ(t->cpu));
   1.105 +}
   1.106 +
   1.107 +PR_IMPLEMENT(void) PR_ShowStatus(void)
   1.108 +{
   1.109 +    PRIntn is;
   1.110 +
   1.111 +    if ( _PR_MD_CURRENT_THREAD()
   1.112 +    && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_INTSOFF(is);
   1.113 +    _pr_dumpOut = _pr_stderr;
   1.114 +    _PR_DumpThreads(_pr_dumpOut);
   1.115 +    if ( _PR_MD_CURRENT_THREAD()
   1.116 +    && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_FAST_INTSON(is);
   1.117 +}
   1.118 +
   1.119 +PR_IMPLEMENT(void)
   1.120 +PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void *arg)
   1.121 +{
   1.122 +    thread->dump = dump;
   1.123 +    thread->dumpArg = arg;
   1.124 +}

mercurial