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")
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
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)
#cmakedefine WITH_PROFILER 1
+#cmakedefine WITH_GPERF_TOOLS 1
+
#define RVERSION "${RSPAMD_VERSION}"
#define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}"
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'}));
}
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 */
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;
%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
| delivery
| luacode
| raw_mode
+ | profile_file
;
tempdir :
}
;
+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
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);
switch (signo) {
case SIGINT:
case SIGTERM:
+#ifdef WITH_GPERF_TOOLS
+ ProfilerStop ();
+#endif
#ifdef WITH_PROFILER
exit (0);
#else
{
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 ();