From cb8cd32734a354007d10d75959ba990ac8baaa19 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 18 Mar 2011 14:13:16 -0400 Subject: [PATCH] Removed the DEBUG_MEMORY_LEAKS framework because we do this with Valgrind now. --- citadel/citserver.c | 4 -- citadel/server.h | 1 - citadel/sysdep.c | 121 ----------------------------------------- citadel/sysdep_decls.h | 22 -------- citadel/threads.c | 89 ------------------------------ 5 files changed, 237 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index 13791feee..75b23badb 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -244,10 +244,6 @@ void master_cleanup(int exitcode) { syslog(LOG_INFO, "Closing databases\n"); close_databases(); -#ifdef DEBUG_MEMORY_LEAKS - dump_heap(); -#endif - /* If the operator requested a halt but not an exit, halt here. */ if (shutdown_and_halt) { syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n"); diff --git a/citadel/server.h b/citadel/server.h index d3b89f215..f07b6ffa4 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -129,7 +129,6 @@ enum { S_NETCONFIGS, S_PUBLIC_CLIENTS, S_FLOORCACHE, - S_DEBUGMEMLEAKS, S_ATBF, S_JOURNAL_QUEUE, S_RPLIST, diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 4c19d2933..e16c8a50b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -89,18 +89,6 @@ #include "control.h" -#ifdef DEBUG_MEMORY_LEAKS -struct igheap { - struct igheap *next; - char file[32]; - int line; - void *block; -}; - -struct igheap *igheap = NULL; -#endif - - /* * Signal handler to shut down the server. */ @@ -1487,112 +1475,3 @@ int SyslogFacility(char *name) } return LOG_DAEMON; } - - -/********** MEM CHEQQER ***********/ - -#ifdef DEBUG_MEMORY_LEAKS - -#undef malloc -#undef realloc -#undef strdup -#undef free - -void *tracked_malloc(size_t size, char *file, int line) { - struct igheap *thisheap; - void *block; - - block = malloc(size); - if (block == NULL) return(block); - - thisheap = malloc(sizeof(struct igheap)); - if (thisheap == NULL) { - free(block); - return(NULL); - } - - thisheap->block = block; - strcpy(thisheap->file, file); - thisheap->line = line; - - begin_critical_section(S_DEBUGMEMLEAKS); - thisheap->next = igheap; - igheap = thisheap; - end_critical_section(S_DEBUGMEMLEAKS); - - return(block); -} - - -void *tracked_realloc(void *ptr, size_t size, char *file, int line) { - struct igheap *thisheap; - void *block; - - block = realloc(ptr, size); - if (block == NULL) return(block); - - thisheap = malloc(sizeof(struct igheap)); - if (thisheap == NULL) { - free(block); - return(NULL); - } - - thisheap->block = block; - strcpy(thisheap->file, file); - thisheap->line = line; - - begin_critical_section(S_DEBUGMEMLEAKS); - thisheap->next = igheap; - igheap = thisheap; - end_critical_section(S_DEBUGMEMLEAKS); - - return(block); -} - - - -void tracked_free(void *ptr) { - struct igheap *thisheap; - struct igheap *trash; - - free(ptr); - - if (igheap == NULL) return; - begin_critical_section(S_DEBUGMEMLEAKS); - for (thisheap = igheap; thisheap != NULL; thisheap = thisheap->next) { - if (thisheap->next != NULL) { - if (thisheap->next->block == ptr) { - trash = thisheap->next; - thisheap->next = thisheap->next->next; - free(trash); - } - } - } - if (igheap->block == ptr) { - trash = igheap; - igheap = igheap->next; - free(trash); - } - end_critical_section(S_DEBUGMEMLEAKS); -} - -char *tracked_strdup(const char *s, char *file, int line) { - char *ptr; - - if (s == NULL) return(NULL); - ptr = tracked_malloc(strlen(s) + 1, file, line); - if (ptr == NULL) return(NULL); - strncpy(ptr, s, strlen(s)); - return(ptr); -} - -void dump_heap(void) { - struct igheap *thisheap; - - for (thisheap = igheap; thisheap != NULL; thisheap = thisheap->next) { - syslog(LOG_CRIT, "UNFREED: %30s : %d\n", - thisheap->file, thisheap->line); - } -} - -#endif /* DEBUG_MEMORY_LEAKS */ diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index a333714fd..c2f957804 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -2,14 +2,6 @@ #ifndef SYSDEP_DECLS_H #define SYSDEP_DECLS_H -/* - * Uncomment this #define if you are a Citadel developer tracking - * down memory leaks in the server. Do NOT do this on a production - * system because it definitely incurs a lot of additional overhead. -#define DEBUG_MEMORY_LEAKS - */ - - #include #include "sysdep.h" @@ -125,18 +117,4 @@ typedef pthread_attr_t citthread_attr_t; #endif /* HAVE_PTHREAD_H */ - -#ifdef DEBUG_MEMORY_LEAKS -#define malloc(x) tracked_malloc(x, __FILE__, __LINE__) -#define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__) -#undef strdup -#define strdup(x) tracked_strdup(x, __FILE__, __LINE__) -#define free(x) tracked_free(x) -void *tracked_malloc(size_t size, char *file, int line); -void *tracked_realloc(void *ptr, size_t size, char *file, int line); -void tracked_free(void *ptr); -char *tracked_strdup(const char *s, char *file, int line); -void dump_heap(void); -#endif - #endif /* SYSDEP_DECLS_H */ diff --git a/citadel/threads.c b/citadel/threads.c index e87ac935d..1f066a0cd 100644 --- a/citadel/threads.c +++ b/citadel/threads.c @@ -61,13 +61,8 @@ #include "context.h" #include "event_client.h" -/* - * define this to use the new worker_thread method of handling connections - */ -//#define NEW_WORKER /* - * New thread interface. * To create a thread you must call one of the create thread functions. * You must pass it the address of (a pointer to a CtdlThreadNode initialised to NULL) like this * struct CtdlThreadNode *node = NULL; @@ -119,9 +114,6 @@ int try_critical_section(int which_one) * transaction; this could lead to deadlock. */ if ( (which_one != S_FLOORCACHE) -#ifdef DEBUG_MEMORY_LEAKS - && (which_one != S_DEBUGMEMLEAKS) -#endif && (which_one != S_RPLIST) ) { cdb_check_handles(); @@ -142,9 +134,6 @@ void begin_critical_section(int which_one) * transaction; this could lead to deadlock. */ if ( (which_one != S_FLOORCACHE) -#ifdef DEBUG_MEMORY_LEAKS - && (which_one != S_DEBUGMEMLEAKS) -#endif && (which_one != S_RPLIST) ) { cdb_check_handles(); @@ -300,30 +289,6 @@ void ctdl_thread_internal_init(void) } -/* - * A function to update a threads load averages - */ - void ctdl_thread_internal_update_avgs(CtdlThreadNode *this_thread) - { - struct timeval now, result; - double last_duration; - - gettimeofday(&now, NULL); - timersub(&now, &(this_thread->last_state_change), &result); - /* I don't think these mutex's are needed here */ - citthread_mutex_lock(&this_thread->ThreadMutex); - // result now has a timeval for the time we spent in the last state since we last updated - last_duration = (double)result.tv_sec + ((double)result.tv_usec / (double) 1000000); - if (this_thread->state == CTDL_THREAD_SLEEPING) - this_thread->avg_sleeping += last_duration; - if (this_thread->state == CTDL_THREAD_RUNNING) - this_thread->avg_running += last_duration; - if (this_thread->state == CTDL_THREAD_BLOCKED) - this_thread->avg_blocked += last_duration; - memcpy (&this_thread->last_state_change, &now, sizeof (struct timeval)); - citthread_mutex_unlock(&this_thread->ThreadMutex); -} - /* * A function to chenge the state of a thread */ @@ -332,7 +297,6 @@ void ctdl_thread_internal_change_state (CtdlThreadNode *this_thread, enum CtdlTh /* * Wether we change state or not we need update the load values */ - ctdl_thread_internal_update_avgs(this_thread); /* This mutex not needed here? */ citthread_mutex_lock(&this_thread->ThreadMutex); /* To prevent race condition of a sleeping thread */ if ((new_state == CTDL_THREAD_STOP_REQ) && (this_thread->state > CTDL_THREAD_STOP_REQ)) @@ -638,54 +602,6 @@ static void ctdl_internal_thread_cleanup(void *arg) citthread_mutex_unlock(&CT->ThreadMutex); } -/* - * A quick function to show the load averages - */ -void ctdl_thread_internal_calc_loadavg(void) -{ - CtdlThreadNode *that_thread; - double load_avg, worker_avg; - int workers = 0; - - that_thread = CtdlThreadList; - load_avg = 0; - worker_avg = 0; - while(that_thread) - { - /* Update load averages */ - ctdl_thread_internal_update_avgs(that_thread); - citthread_mutex_lock(&that_thread->ThreadMutex); - that_thread->load_avg = (that_thread->avg_sleeping + that_thread->avg_running) / (that_thread->avg_sleeping + that_thread->avg_running + that_thread->avg_blocked) * 100; - that_thread->avg_sleeping /= 2; - that_thread->avg_running /= 2; - that_thread->avg_blocked /= 2; - load_avg += that_thread->load_avg; - if (that_thread->flags & CTDLTHREAD_WORKER) - { - worker_avg += that_thread->load_avg; - workers++; - } -#ifdef WITH_THREADLOG - syslog(LOG_DEBUG, "CtdlThread, \"%s\" (%lu) \"%s\" %.2f %.2f %.2f %.2f\n", - that_thread->name, - that_thread->tid, - CtdlThreadStates[that_thread->state], - that_thread->avg_sleeping, - that_thread->avg_running, - that_thread->avg_blocked, - that_thread->load_avg); -#endif - citthread_mutex_unlock(&that_thread->ThreadMutex); - that_thread = that_thread->next; - } - CtdlThreadLoadAvg = load_avg/num_threads; - CtdlThreadWorkerAvg = worker_avg/workers; -#ifdef WITH_THREADLOG - syslog(LOG_INFO, "System load average %.2f, workers averag %.2f, threads %d, workers %d, sessions %d\n", CtdlThreadGetLoadAvg(), CtdlThreadWorkerAvg, num_threads, num_workers, num_sessions); -#endif -} - - /* * Garbage collection routine. * Gets called by main() in a loop to clean up the thread list periodically. @@ -1032,7 +948,6 @@ CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thre CtdlThreadList = this_thread; if (this_thread->next) this_thread->next->prev = this_thread; - ctdl_thread_internal_calc_loadavg(); end_critical_section(S_THREAD_LIST); @@ -1088,7 +1003,6 @@ CtdlThreadNode *ctdl_thread_internal_start_scheduled (CtdlThreadNode *this_threa if (this_thread->next) this_thread->next->prev = this_thread; - ctdl_thread_internal_calc_loadavg(); end_critical_section(S_THREAD_LIST); @@ -1213,8 +1127,6 @@ void go_threading(void) { int i; CtdlThreadNode *last_worker; - struct timeval start, now, result; - double last_duration; /* * Initialise the thread system @@ -1249,7 +1161,6 @@ void go_threading(void) if (CT->state > CTDL_THREAD_STOP_REQ) { begin_critical_section(S_THREAD_LIST); - ctdl_thread_internal_calc_loadavg(); end_critical_section(S_THREAD_LIST); ctdl_thread_internal_check_scheduled(); /* start scheduled threads */ -- 2.30.2