]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
config: build infrastructure for handling tcmalloc's profiling.
authorGreg Farnum <gregf@hq.newdream.net>
Sat, 18 Sep 2010 00:16:57 +0000 (17:16 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 21 Sep 2010 21:40:10 +0000 (14:40 -0700)
src/common/common_init.cc
src/config.cc
src/config.h

index 582ae6bea0651ad186728a752095e0db7154d67b..4a8fee28eb2b859f16d220d364f973d02e9a9e8a 100644 (file)
@@ -29,6 +29,21 @@ void common_init(std::vector<const char*>& args, const char *module_type, bool i
   parse_startup_config_options(args, module_type);
   parse_config_options(args);
 
+#ifdef HAVE_LIBTCMALLOC
+  if (g_conf.tcmalloc_profiler_run && g_conf.tcmalloc_have) {
+    char *profile_name = new char[PATH_MAX];
+    sprintf(profile_name, "%s/%s", g_conf.log_dir, g_conf.name);
+    char *val = new char[sizeof(int)*8+1];
+    sprintf(val, "%i", g_conf.profiler_allocation_interval);
+    setenv("HEAP_PROFILE_ALLOCATION_INTERVAL", val, g_conf.profiler_allocation_interval);
+    sprintf(val, "%i", g_conf.profiler_highwater_interval);
+    setenv("HEAP_PROFILE_INUSE_INTERVAL", "", g_conf.profiler_highwater_interval);
+    generic_dout(0) << "turning on heap profiler with prefix " << profile_name << dendl;
+    g_conf.profiler_start(profile_name);
+    delete profile_name;
+  }
+#endif //HAVE_LIBTCMALLOC
+
   if (g_conf.log_file && g_conf.log_file[0])
     g_conf.log_to_stdout = false;
 
index 2b69af13b02eed87b43f492f83da1a3a5ff82a96..1f7cc2bafa0a1a708314ed8852be477c019faeac 100644 (file)
@@ -263,6 +263,9 @@ static struct config_option config_optionsp[] = {
        OPTION(monmap, 'M', OPT_STR, 0),
        OPTION(mon_host, 'm', OPT_STR, 0),
        OPTION(daemonize, 'd', OPT_BOOL, false),
+        OPTION(tcmalloc_profiler_run, 0, OPT_BOOL, false),
+        OPTION(profiler_allocation_interval, 0, OPT_INT, 1073741824),
+        OPTION(profiler_highwater_interval, 0, OPT_INT, 104857600),
        OPTION(logger, 0, OPT_BOOL, false),
        OPTION(logger_interval, 0, OPT_INT, 1),
        OPTION(logger_calc_variance, 0, OPT_BOOL, true),
@@ -1075,7 +1078,6 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
       }
     }
   }
-
   // open new conf
   string fn = g_conf.conf;
   list<string> ls;
index fb0324b45bd9dff03c1e3751916f5331acf91503..92fd2c18fab481f9b66b5b1be7b6c9773a3f35d6 100644 (file)
@@ -31,6 +31,10 @@ extern struct ceph_file_layout g_default_file_layout;
 
 #include "msg/msg_types.h"
 
+#ifdef HAVE_LIBTCMALLOC
+#include <google/heap-profiler.h>
+#endif //HAVE_LIBTCMALLOC
+
 extern bool g_daemon;
 extern const char *g_default_id;
 
@@ -56,6 +60,16 @@ struct md_config_t {
   const char *mon_host;
   bool daemonize;
 
+  //profiling
+  bool tcmalloc_have;
+  bool tcmalloc_profiler_run;
+  void (*profiler_start)(const char*);
+  bool (*profiler_running)();
+  void (*profiler_stop)();
+  void (*profiler_dump)(const char*);
+  int profiler_allocation_interval;
+  int profiler_highwater_interval;
+
   // logger (profiling)
   bool logger;
   int logger_interval;