From 3f442f221a69097588beb7be8bdbffa0bbcd5448 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 7 Jun 2010 21:08:46 +0000 Subject: [PATCH] * by counting up threads starting at 3, we seem to get what top shows in the LWPID when pressing H. why isn't there always a ct? --- citadel/include/ctdl_module.h | 1 + citadel/sysdep.c | 18 +++++++++++++++++- citadel/threads.c | 4 +++- citadel/threads.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 0db356a6f..21550ed87 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -185,6 +185,7 @@ void CtdlThreadAllocTSD(void); #define MYCURSORS (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors) #define MYTID (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid) #define CT (((ThreadTSD*)pthread_getspecific(ThreadKey))->self) +#define CTP ((ThreadTSD*)pthread_getspecific(ThreadKey)) /** return the current context list as an array and do it in a safe manner * The returned data is a copy so only reading is useful diff --git a/citadel/sysdep.c b/citadel/sysdep.c index deb7f9182..a935c410b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -122,7 +122,17 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) time_t unixtime; StrBuf *lBuf; CitContext *CCC = CC; - + ThreadTSD *cTSD = CTP; + CtdlThreadNode *node = NULL; + long lwpid = 0; + + if (cTSD != NULL) + node = cTSD->self; + if ((node != NULL) && (node->reltid != 0)) + { + lwpid = node->pid + node->reltid; + } + gettimeofday(&tv, NULL); /* Promote to time_t; types differ on some OSes (like darwin) */ unixtime = tv.tv_sec; @@ -159,6 +169,12 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr) tim.tm_year + 1900, tim.tm_mon + 1, tim.tm_mday, tim.tm_hour, tim.tm_min, tim.tm_sec, (long)tv.tv_usec); + + + if (lwpid != 0) + StrBufAppendPrintf(lBuf, + "[LWP:%d] ", + lwpid); if (CCC != NULL) { if (CCC->cs_pid != 0) diff --git a/citadel/threads.c b/citadel/threads.c index fb854bf57..f6221019a 100644 --- a/citadel/threads.c +++ b/citadel/threads.c @@ -58,6 +58,7 @@ * remove the need for the calls to eCrashRegisterThread and friends */ +static int next_tid = 3; /* offset LWPID to PID */ static int num_threads = 0; /* Current number of threads */ static int num_workers = 0; /* Current number of worker threads */ long statcount = 0; /* are we doing a stats check? */ @@ -989,7 +990,8 @@ CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thre free(this_thread); return NULL; } - + this_thread->reltid = next_tid; + next_tid++; num_threads++; // Increase the count of threads in the system. if(this_thread->flags & CTDLTHREAD_WORKER) num_workers++; diff --git a/citadel/threads.h b/citadel/threads.h index 4f4830639..4103466f5 100644 --- a/citadel/threads.h +++ b/citadel/threads.h @@ -87,6 +87,7 @@ typedef struct CtdlThreadNode CtdlThreadNode; struct CtdlThreadNode{ citthread_t tid; /* id as returned by citthread_create() */ pid_t pid; /* pid, as best the OS will let us determine */ + long reltid; /* counting from start... */ time_t when; /* When to start a scheduled thread */ struct CitContext *Context; /* The session context that this thread mught be working on or NULL if none */ long number; /* A unigue number for this thread (not implimented yet) */ -- 2.30.2