summaryrefslogtreecommitdiffstats
path: root/src/worker.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-05-04 16:39:35 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-05-04 16:39:35 +0400
commite30ea48c912be20ddc9c327205d146e46d60535e (patch)
treebd01b7906d88ad8a009afb3c082aad14b15aef88 /src/worker.c
parent1670afcda506b1641e8b0dc34b894f7ab2817607 (diff)
downloadrspamd-e30ea48c912be20ddc9c327205d146e46d60535e.tar.gz
rspamd-e30ea48c912be20ddc9c327205d146e46d60535e.zip
* Enable support of google perf tools
Diffstat (limited to 'src/worker.c')
-rw-r--r--src/worker.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/worker.c b/src/worker.c
index 270d71f61..5242c0087 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -43,6 +43,14 @@
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 ();