From af6d8da8e78285e2c45510065a2b88c3fa0a46d1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 7 Oct 2015 22:23:40 +0100 Subject: [PATCH] Improve google perftools invocation. --- src/libutil/util.c | 26 +++++++++++++++++++++----- src/libutil/util.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libutil/util.c b/src/libutil/util.c index 5706a2f49..daf427ef3 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1137,22 +1137,31 @@ gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr) { #if defined(WITH_GPERF_TOOLS) gchar prof_path[PATH_MAX]; + const gchar *prefix; if (getenv ("CPUPROFILE")) { /* disable inherited Profiler enabled in master process */ ProfilerStop (); } - /* Try to create temp directory for gmon.out and chdir to it */ - if (cfg->profile_path == NULL) { - cfg->profile_path = - g_strdup_printf ("%s/rspamd-profile", cfg->temp_dir); + + if (cfg != NULL) { + /* Try to create temp directory for gmon.out and chdir to it */ + if (cfg->profile_path == NULL) { + cfg->profile_path = + g_strdup_printf ("%s/rspamd-profile", cfg->temp_dir); + } + + prefix = cfg->profile_path; + } + else { + prefix = "/tmp/rspamd-profile"; } snprintf (prof_path, sizeof (prof_path), "%s-%s.%d", - cfg->profile_path, + prefix, descr, (gint)getpid ()); if (ProfilerStart (prof_path)) { @@ -1162,7 +1171,14 @@ gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr) else { msg_warn ("cannot start google perftools profiler"); } +#endif +} +void +gperf_profiler_stop (void) +{ +#if defined(WITH_GPERF_TOOLS) + ProfilerStop (); #endif } diff --git a/src/libutil/util.h b/src/libutil/util.h index 8284557d9..a78c4dfda 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -165,6 +165,7 @@ gboolean rspamd_file_unlock (gint fd, gboolean async); * Google perf-tools initialization function */ void gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr); +void gperf_profiler_stop (void); /* * Workarounds for older versions of glib -- 2.39.5