]> source.dussan.org Git - rspamd.git/commitdiff
Improve google perftools invocation.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 7 Oct 2015 21:23:40 +0000 (22:23 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 7 Oct 2015 21:23:40 +0000 (22:23 +0100)
src/libutil/util.c
src/libutil/util.h

index 5706a2f4988df455f7c2d5a11d8ebccbeb249d65..daf427ef32e2b06ca6ad3849debffce6ff72346c 100644 (file)
@@ -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
 }
 
index 8284557d95fedea2c7ca459d088de6be93fd62de..a78c4dfdac22b30e1eb3edf96d8c6e4b00298530 100644 (file)
@@ -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