From 6cb3a859197585047802ec6216b19a33c08db116 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 29 Apr 2009 16:37:03 +0400 Subject: * Enable gprof support --- CMakeLists.txt | 8 ++++++++ config.h.in | 2 ++ src/main.c | 3 +-- src/worker.c | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b89b265b..59537af11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ OPTION(ENABLE_PERL "Enable perl support [default: OFF]" OPTION(ENABLE_LUA "Enable lua support [default: OFF]" OFF) OPTION(SKIP_RELINK_RPATH "Skip relinking and full RPATH for the install tree" OFF) OPTION(ENABLE_REDIRECTOR "Enable redirector install [default: OFF]" OFF) +OPTION(ENABLE_PROFILING "Enable profiling [default: OFF]" OFF) # Build optimized code for following CPU (default i386) #SET(CPU_TUNE "i686") @@ -136,6 +137,13 @@ IF(NOT LIBEVENT_LIBRARY) MESSAGE(FATAL_ERROR "libevent is required for building rspamd") ENDIF(NOT LIBEVENT_LIBRARY) +IF(ENABLE_PROFILING MATCHES "ON") + SET(WITH_PROFILER 1) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") +ENDIF(ENABLE_PROFILING MATCHES "ON") + + FIND_PATH(LIBEVENT_INCLUDE event.h PATHS /opt/include /usr/include /usr/local/include diff --git a/config.h.in b/config.h.in index 1fd8a5361..14530362f 100644 --- a/config.h.in +++ b/config.h.in @@ -99,6 +99,8 @@ #cmakedefine WITH_LUA 1 +#cmakedefine WITH_PROFILER 1 + #define RVERSION "${RSPAMD_VERSION}" #define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}" diff --git a/src/main.c b/src/main.c index 2bc79cf14..bb8028441 100644 --- a/src/main.c +++ b/src/main.c @@ -687,8 +687,7 @@ main (int argc, char **argv, char **env) } msg_info ("main: terminating..."); - - + if (rspamd->cfg->bind_family == AF_UNIX) { unlink (rspamd->cfg->bind_host); } diff --git a/src/worker.c b/src/worker.c index 20e04ed5e..ee00bb63b 100644 --- a/src/worker.c +++ b/src/worker.c @@ -53,7 +53,11 @@ void sig_handler (int signo) switch (signo) { case SIGINT: case SIGTERM: +#ifdef WITH_PROFILER + exit (0); +#else _exit (1); +#endif break; } } @@ -293,6 +297,18 @@ start_worker (struct rspamd_worker *worker, int listen_sock) { struct sigaction signals; int i; +#ifdef WITH_PROFILER + extern void _start (void), etext (void); + monstartup ((u_long) &_start, (u_long) &etext); +#endif +#if 0 + /* Try to create temp directory for gmon.out and chdir to it */ + char prof_dir[PATH_MAX]; + snprintf (prof_dir, sizeof (prof_dir), "%s/rspamd-prof-%d", worker->srv->cfg->temp_dir, (int)getpid ()); + if (mkdir (prof_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IXOTH | S_IROTH | S_IXGRP | S_IRGRP) != -1) { + chdir (prof_dir); + } +#endif worker->srv->pid = getpid (); worker->srv->type = TYPE_WORKER; -- cgit v1.2.3