aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-07 22:23:40 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-07 22:23:40 +0100
commitaf6d8da8e78285e2c45510065a2b88c3fa0a46d1 (patch)
treeb0e3f12f865efb7a728b845d0e272a0076b4d1c2 /src/libutil
parent2f221e03ee2f293d2b26c7423e343b753a8d8e72 (diff)
downloadrspamd-af6d8da8e78285e2c45510065a2b88c3fa0a46d1.tar.gz
rspamd-af6d8da8e78285e2c45510065a2b88c3fa0a46d1.zip
Improve google perftools invocation.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c26
-rw-r--r--src/libutil/util.h1
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