]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Enable support of google perf tools
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 12:39:35 +0000 (16:39 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 12:39:35 +0000 (16:39 +0400)
CMakeLists.txt
config.h.in
rspamc.pl.in
src/cfg_file.h
src/cfg_file.l
src/cfg_file.y
src/worker.c

index 59537af1164ccf3f4219c5a68c34322192995a96..1403c0b234ad0da3354988fbbf2368beea5f7736 100644 (file)
@@ -23,6 +23,7 @@ OPTION(ENABLE_LUA          "Enable lua support [default: 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)
+OPTION(ENABLE_GPERF_TOOLS  "Enable google perftools [default: OFF]"             OFF)
 
 # Build optimized code for following CPU (default i386)
 #SET(CPU_TUNE               "i686")
@@ -143,6 +144,10 @@ IF(ENABLE_PROFILING MATCHES "ON")
        SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
 ENDIF(ENABLE_PROFILING MATCHES "ON")
 
+IF(ENABLE_GPERF_TOOLS MATCHES "ON")
+       SET(WITH_GPERF_TOOLS 1)
+ENDIF(ENABLE_GPERF_TOOLS MATCHES "ON")
+
 
 FIND_PATH(LIBEVENT_INCLUDE event.h PATHS       /opt/include
                                                                                /usr/include
@@ -407,6 +412,10 @@ IF(ENABLE_LUA MATCHES "ON")
        TARGET_LINK_LIBRARIES(rspamd "${LUA_LIBRARY}")
 ENDIF(ENABLE_LUA MATCHES "ON")
 
+IF(ENABLE_GPERF_TOOLS MATCHES "ON")
+       TARGET_LINK_LIBRARIES(rspamd profiler)
+ENDIF(ENABLE_GPERF_TOOLS MATCHES "ON")
+
 ADD_EXECUTABLE(test/rspamd-test ${TESTDEPENDS} ${CONTRIBSRC} ${TESTSRC})
 SET_TARGET_PROPERTIES(test/rspamd-test PROPERTIES LINKER_LANGUAGE C)
 TARGET_LINK_LIBRARIES(test/rspamd-test m)
index 14530362f63f936849097d671984cef6f077a803..61bbc6068fe573bf5e7a43a971e43f2d7f2c76d8 100644 (file)
 
 #cmakedefine WITH_PROFILER       1
 
+#cmakedefine WITH_GPERF_TOOLS    1
+
 #define RVERSION          "${RSPAMD_VERSION}"
 #define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}"
 
index c8d7f07d0ca4935b2ffb7a72baf088454ee7fd64..9976794d0055baee687cd9bd97f17654d971cb6a 100755 (executable)
@@ -78,6 +78,9 @@ sub connect_socket {
         my $proto = getprotobyname('tcp');
         my $sin;
         socket ($sock, PF_INET, SOCK_STREAM, $proto) or die "cannot create tcp socket";
+        if ($cfg{'host'} eq '*') {
+            $cfg{'host'} = '127.0.0.1';
+        }
         if (inet_aton ($cfg{'host'})) {
             $sin = sockaddr_in ($cfg{'port'}, inet_aton($cfg{'host'}));
         }
index 437317ed0231eadbf3b13bc757415c44b191d286..201b468230cb8b24ab73e51a13d7ab934e0c8ed6 100644 (file)
@@ -154,6 +154,9 @@ struct config_file {
        char *cfg_name;                                                                 /**< name of config file                                                                */
        char *pid_file;                                                                 /**< name of pid file                                                                   */
        char *temp_dir;                                                                 /**< dir for temp files                                                                 */
+#ifdef WITH_GPERF_TOOLS
+       char *profile_path;
+#endif
 
        char *bind_host;                                                                /**< bind line                                                                                  */
        struct in_addr bind_addr;                                               /**< bind address in case of TCP socket                                 */
index 29ca9aef79a398c0e81c6f5f0df73d782f2b04b3..f839c0b45c244f49c6f9a9bd0c1ed8c54dab794b 100644 (file)
@@ -84,6 +84,7 @@ WARNING                                                       return LOG_LEVEL_WARNING;
 ERROR                                                  return LOG_LEVEL_ERROR;
 log_facility                                   return LOG_FACILITY;
 log_file                                               return LOG_FILENAME;
+profile_file                                   return PROFILE_FILE;
 
 statfile_pool_size                             return STATFILE_POOL_SIZE;
 
index 9ddc5850f682bdb14f388f0bfdb4057ffbf85b43..e4e4d8dbea8ed240e1c92a1edecd336d3b5ce6a4 100644 (file)
@@ -48,7 +48,7 @@ struct statfile_section *cur_section = NULL;
 %token  LOGGING LOG_TYPE LOG_TYPE_CONSOLE LOG_TYPE_SYSLOG LOG_TYPE_FILE
 %token  LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME
 %token  STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER
-%token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE
+%token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE PROFILE_FILE
 
 %type  <string>        STRING
 %type  <string>        VARIABLE
@@ -94,6 +94,7 @@ command       :
        | delivery
        | luacode
        | raw_mode
+       | profile_file
        ;
 
 tempdir :
@@ -842,6 +843,16 @@ raw_mode:
        }
        ;
 
+profile_file:
+       PROFILE_FILE EQSIGN QUOTEDSTRING {
+#ifdef WITH_GPREF_TOOLS
+               cfg->profile_path = $3;
+#else
+               yywarn ("yyparse: profile_file directive is ignored as gperf support is not enabled");
+#endif
+       }
+       ;
+
 %%
 /* 
  * vi:ts=4 
index 270d71f61446aab19f6afba3375adcc58c5a0ea0..5242c008798c6f3300cb1876a298bb5ca2b7eb17 100644 (file)
 extern PerlInterpreter *perl_interpreter;
 #endif
 
+#ifdef WITH_GPERF_TOOLS
+#include <glib/gprintf.h>
+/* Declare prototypes */
+int ProfilerStart (u_char* fname);
+void ProfilerStop (void);
+void ProfilerRegisterThread (void);
+#endif
+
 static struct timeval io_tv;
 
 static void write_socket (void *arg);
@@ -53,6 +61,9 @@ void sig_handler (int signo)
        switch (signo) {
                case SIGINT:
                case SIGTERM:
+#ifdef WITH_GPERF_TOOLS
+                       ProfilerStop ();
+#endif
 #ifdef WITH_PROFILER
                        exit (0);
 #else
@@ -299,17 +310,34 @@ 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
+
+#ifdef WITH_GPERF_TOOLS
+       char prof_path[PATH_MAX];
+
+       if (getenv("CPUPROFILE")) {
+
+               /* disable inherited Profiler enabled in master process */
+               ProfilerStop ();
+       }
        /* 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);
+       if (worker->srv->cfg->profile_path == NULL) {
+               worker->srv->cfg->profile_path = g_strdup_printf ("%s/rspamd-profile", worker->srv->cfg->temp_dir);
+       }
+
+       snprintf (prof_path, sizeof (prof_path), "%s.%d", worker->srv->cfg->profile_path, (int)getpid ());
+       if (ProfilerStart (prof_path)) {
+               /* start ITIMER_PROF timer */
+               ProfilerRegisterThread();
+       }
+       else {
+               msg_warn ("start_worker: cannot start google perftools profiler");
        }
+
 #endif
 
        worker->srv->pid = getpid ();