From: Vsevolod Stakhov Date: Wed, 7 Oct 2015 21:23:40 +0000 (+0100) Subject: Improve google perftools invocation. X-Git-Tag: 1.0.5~61 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af6d8da8e78285e2c45510065a2b88c3fa0a46d1;p=thirdparty%2Frspamd.git Improve google perftools invocation. --- diff --git a/src/libutil/util.c b/src/libutil/util.c index 5706a2f498..daf427ef32 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 8284557d95..a78c4dfdac 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