From 066433681a6500057e0f02419c7dfcfa23ebd5ac Mon Sep 17 00:00:00 2001 From: Dave West Date: Tue, 27 Nov 2007 20:00:11 +0000 Subject: [PATCH] Added --with-threadlog. Use this if you want the thread table written to the log. Fixed CtdlThreadName(char *name) now renames thread to name if name is set and always returns old name caller frees old name. Added a couple of macros to change the thread names in some places for debugging. --- citadel/configure.ac | 9 +++++++++ citadel/housekeeping.c | 12 ++++++++---- citadel/include/ctdl_module.h | 11 +++++++++++ citadel/journaling.c | 4 ++++ citadel/serv_extensions.c | 23 +++++++++++++++++++++++ citadel/sysdep.c | 23 ++++++++++++++++------- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/citadel/configure.ac b/citadel/configure.ac index 74e707208..566eb7df4 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -333,6 +333,15 @@ AC_ARG_WITH(gprof, ] ) +dnl disable thread table reporting +AC_ARG_WITH(threadlog, + [ --with-threadlog enable logging of thread table], + [ if test "x$withval" != "xno" ; then + AC_DEFINE(WITH_THREADLOG, [], [Define if you want logging of the thread tables.]) + fi + ] +) + if test "$ac_cv_func_gethostbyname" = no; then AC_CHECK_LIB(nsl, gethostbyname) diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 1dd18d61e..8d65e0ec7 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -71,14 +71,14 @@ void terminate_idle_sessions(void) { } end_critical_section(S_SESSION_TABLE); if (killed > 0) - lprintf(CTDL_INFO, "Terminated %d idle sessions\n", killed); + CtdlLogPrintf(CTDL_INFO, "Terminated %d idle sessions\n", killed); } void check_sched_shutdown(void) { if ((ScheduledShutdown == 1) && (ContextList == NULL)) { - lprintf(CTDL_NOTICE, "Scheduled shutdown initiating.\n"); + CtdlLogPrintf(CTDL_NOTICE, "Scheduled shutdown initiating.\n"); CtdlThreadStopAll(); } } @@ -104,7 +104,7 @@ void check_ref_counts(void) { int new_refcounts[MAXFLOORS]; - lprintf(CTDL_DEBUG, "Checking floor reference counts\n"); + CtdlLogPrintf(CTDL_DEBUG, "Checking floor reference counts\n"); for (a=0; anext) { if (fcn->eventtype == EventType) { (*fcn->h_function_pointer) (); } } + CtdlThreadPopName(); + } void PerformUserHooks(struct ctdluser *usbuf, int EventType) { struct UserFunctionHook *fcn = NULL; + CtdlThreadPushName("PerformUserHooks"); + for (fcn = UserHookTable; fcn != NULL; fcn = fcn->next) { if (fcn->eventtype == EventType) { (*fcn->h_function_pointer) (usbuf); } } + CtdlThreadPopName(); } int PerformMessageHooks(struct CtdlMessage *msg, int EventType) @@ -945,6 +952,8 @@ int PerformMessageHooks(struct CtdlMessage *msg, int EventType) struct MessageFunctionHook *fcn = NULL; int total_retval = 0; + CtdlThreadPushName("PerformMessageHooks"); + /* Other code may elect to protect this message from server-side * handlers; if this is the case, don't do anything. lprintf(CTDL_DEBUG, "** Event type is %d, flags are %d\n", @@ -952,6 +961,7 @@ int PerformMessageHooks(struct CtdlMessage *msg, int EventType) */ if (msg->cm_flags & CM_SKIP_HOOKS) { lprintf(CTDL_DEBUG, "Skipping hooks\n"); + CtdlThreadPopName(); return(0); } @@ -968,6 +978,7 @@ int PerformMessageHooks(struct CtdlMessage *msg, int EventType) * this is an EVT_BEFORESAVE event, a nonzero return code will cause * the save operation to abort. */ + CtdlThreadPopName(); return total_retval; } @@ -977,6 +988,8 @@ int PerformRoomHooks(struct ctdlroom *target_room) struct RoomFunctionHook *fcn; int total_retval = 0; + CtdlThreadPushName("PerformRoomHooks"); + lprintf(CTDL_DEBUG, "Performing room hooks for <%s>\n", target_room->QRname); for (fcn = RoomHookTable; fcn != NULL; fcn = fcn->next) { @@ -985,6 +998,7 @@ int PerformRoomHooks(struct ctdlroom *target_room) /* Return the sum of the return codes from the hook functions. */ + CtdlThreadPopName(); return total_retval; } @@ -994,6 +1008,8 @@ int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room) struct NetprocFunctionHook *fcn; int total_retval = 0; + CtdlThreadPushName("PerformNetprocHooks"); + for (fcn = NetprocHookTable; fcn != NULL; fcn = fcn->next) { total_retval = total_retval + (*fcn->h_function_pointer) (msg, target_room); @@ -1002,6 +1018,7 @@ int PerformNetprocHooks(struct CtdlMessage *msg, char *target_room) /* Return the sum of the return codes from the hook functions. * A nonzero return code will cause the message to *not* be imported. */ + CtdlThreadPopName(); return total_retval; } @@ -1010,9 +1027,12 @@ void PerformDeleteHooks(char *room, long msgnum) { struct DeleteFunctionHook *fcn; + CtdlThreadPushName("PerformDeleteHooks"); + for (fcn = DeleteHookTable; fcn != NULL; fcn = fcn->next) { (*fcn->h_function_pointer) (room, msgnum); } + CtdlThreadPopName(); } @@ -1025,6 +1045,8 @@ int PerformXmsgHooks(char *sender, char *recp, char *msg) int total_sent = 0; int p; + CtdlThreadPushName("PerformXmsgHooks"); + for (p=0; pnext) { if (fcn->order == p) { @@ -1040,6 +1062,7 @@ int PerformXmsgHooks(char *sender, char *recp, char *msg) */ if (total_sent) break; } + CtdlThreadPopName(); return total_sent; } diff --git a/citadel/sysdep.c b/citadel/sysdep.c index faa6d2468..e22a967c4 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -1263,13 +1263,11 @@ char *CtdlThreadName(struct CtdlThreadNode *thread, char *name) return NULL; } begin_critical_section(S_THREAD_LIST); + old_name = this_thread->name; if (name) - { - old_name = this_thread->name; this_thread->name = strdup (name); - free(old_name); - } - old_name = strdup(this_thread->name); + else + old_name = strdup(old_name); end_critical_section (S_THREAD_LIST); return (old_name); } @@ -1441,6 +1439,7 @@ void ctdl_thread_internal_calc_loadavg(void) worker_avg += that_thread->load_avg; workers++; } +#ifdef WITH_THREADLOG CtdlLogPrintf(CTDL_DEBUG, "CtdlThread, \"%s\" (%ld) \"%s\" %f %f %f %f.\n", that_thread->name, that_thread->tid, @@ -1449,13 +1448,15 @@ void ctdl_thread_internal_calc_loadavg(void) that_thread->avg_running, that_thread->avg_blocked, that_thread->load_avg); - +#endif pthread_mutex_unlock(&that_thread->ThreadMutex); that_thread = that_thread->next; } CtdlThreadLoadAvg = load_avg/num_threads; CtdlThreadWorkerAvg = worker_avg/workers; +#ifdef WITH_THREADLOG CtdlLogPrintf(CTDL_INFO, "System load average %f, workers averag %f\n", CtdlThreadLoadAvg, CtdlThreadWorkerAvg); +#endif end_critical_section(S_THREAD_LIST); } @@ -1473,7 +1474,9 @@ void ctdl_internal_thread_gc (void) if(num_threads == 1) CtdlThreadList->state = CTDL_THREAD_EXITED; +#ifdef WITH_THREADLOG CtdlLogPrintf(CTDL_DEBUG, "Thread system running garbage collection.\n"); +#endif /* * Woke up to do garbage collection */ @@ -1767,9 +1770,12 @@ int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds void dead_session_purge(int force) { struct CitContext *ptr, *ptr2; /* general-purpose utility pointer */ struct CitContext *rem = NULL; /* list of sessions to be destroyed */ - + + CtdlThreadPushName("dead_session_purge"); + if (force == 0) { if ( (time(NULL) - last_purge) < 5 ) { + CtdlThreadPopName(); return; /* Too soon, go away */ } } @@ -1823,6 +1829,9 @@ void dead_session_purge(int force) { } end_critical_section(S_THREAD_LIST); // FIXME: reduce the number of worker threads too + + CtdlThreadPopName(); + } -- 2.30.2