]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
profiler: move perftools glue into perfglue/
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 28 Feb 2011 15:42:28 +0000 (07:42 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Mar 2011 14:45:09 +0000 (06:45 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/Makefile.am
src/common/LogEntry.h
src/include/ceph_fs.cc
src/mds/MDS.cc
src/perfglue/cpu_profiler.cc [new file with mode: 0644]
src/perfglue/cpu_profiler.h [new file with mode: 0644]
src/perfglue/disabled_stubs.cc [new file with mode: 0644]

index 152a098771bd379ab226db32a9231b1d6812e783..b42bdfb7601b4be1797815e5e31b4c5d5e96e992 100644 (file)
@@ -554,6 +554,12 @@ libcommon_files = \
        common/version.cc \
        common/hex.cc
 
+if WITH_PROFILER
+libcommon_files += perfglue/cpu_profiler.cc
+else
+libcommon_files += perfglue/disabled_stubs.cc
+endif
+
 libcrush_a_SOURCES = \
        crush/builder.c \
        crush/mapper.c \
@@ -965,6 +971,7 @@ noinst_HEADERS = \
         osdc/Journaler.h\
         osdc/ObjectCacher.h\
         osdc/Objecter.h\
+        perfglue/cpu_profiler.h\
        rgw/rgw_access.h\
        rgw/rgw_acl.h\
        rgw/rgw_fs.h\
index 04c80b607a43cbcebcd2a5ae639f237f8f99488e..ced05abaf6b07db94bce64ae43f0cee3d9cd179d 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "include/types.h"
 #include "include/encoding.h"
+#include "msg/msg_types.h" // for entity_inst_t
 
 typedef enum {
   CLOG_DEBUG = 0,
index c8e96598198a5e6415d5b4785d784fef8611e495..4457190b909939f8a801bc26d9d48da54c0eef77 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * ceph_fs.cc - Some Ceph functions that are shared between kernel space and
  * user space.
+ *
  */
 
 /*
index c9916831826ce5cfb65ca014b277118a59ce0016..6eba78e90e897c22d5e4415b7bd5f64533414aee 100644 (file)
@@ -70,9 +70,7 @@
 
 #include "common/config.h"
 
-#ifdef HAVE_PROFILER
-# include <google/profiler.h>
-#endif
+#include "perfglue/cpu_profiler.h"
 
 
 #define DOUT_SUBSYS mds
@@ -779,50 +777,9 @@ void MDS::handle_command(MMonCommand *m)
       } else dout(0) << "bad migrate_dir target syntax" << dendl;
     } else dout(0) << "bad migrate_dir syntax" << dendl;
   } 
-
-  else if (m->cmd[0] == "cpu_profiler_start" && m->cmd.size() == 2) {
-#ifdef HAVE_PROFILER
-    int r = ProfilerStart(m->cmd[1].c_str());
-    clog.info() << "cpu_profiler start, logging to " << m->cmd[1] << ", r=" << r << "\n";
-#else
-    clog.info() << "cpu_profiler support not linked in\n";
-#endif
-  }
-  else if (m->cmd[0] == "cpu_profiler_status") {
-#ifdef HAVE_PROFILER
-    if (ProfilingIsEnabledForAllThreads())
-      clog.info() << "cpu_profiler is enabled\n";
-    else
-      clog.info() << "cpu_profiler is not enabled\n";
-    ProfilerState st;
-    ProfilerGetCurrentState(&st);
-    clog.info() << "cpu_profiler " << (st.enabled ? "enabled":"not enabled")
-               << " start_time " << st.start_time
-               << " profile_name " << st.profile_name
-               << " samples " << st.samples_gathered
-               << "\n";
-#else
-    clog.info() << "cpu_profiler support not linked in\n";
-#endif
-  }
-  else if (m->cmd[0] == "cpu_profiler_flush") {
-#ifdef HAVE_PROFILER
-    clog.info() << "cpu_profiler flush\n";
-    ProfilerFlush();
-#else
-    clog.info() << "cpu_profiler support not linked in\n";
-#endif
-  }
-  else if (m->cmd[0] == "cpu_profiler_stop") {
-#ifdef HAVE_PROFILER
-    clog.info() << "cpu_profiler flush and stop\n";
-    ProfilerFlush();
-    ProfilerStop();
-#else
-    clog.info() << "cpu_profiler support not linked in\n";
-#endif
+  else if (m->cmd[0] == "cpu_profiler") {
+    cpu_profiler_handle_command(m->cmd, clog);
   }
-
  else if (m->cmd.size() == 1 && m->cmd[0] == "heap_profiler_options") {
     char val[sizeof(int)*8+1];
     snprintf(val, sizeof(val), "%i", g_conf.profiler_allocation_interval);
diff --git a/src/perfglue/cpu_profiler.cc b/src/perfglue/cpu_profiler.cc
new file mode 100644 (file)
index 0000000..856b96b
--- /dev/null
@@ -0,0 +1,60 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/LogClient.h"
+#include "perfglue/cpu_profiler.h"
+
+#include <google/profiler.h>
+
+void cpu_profiler_handle_command(const std::vector<std::string> &cmd,
+                                LogClient &clog)
+{
+  if (cmd[1] == "start") {
+    if (cmd.size() < 3) {
+      clog.info() << "cpu_profiler: you must give an argument to start: a "
+                 << "file name to log to.\n";
+      return;
+    }
+    const char *file = cmd[2].c_str();
+    int r = ProfilerStart(file);
+    clog.info() << "cpu_profiler: starting logging to " << file
+               << ", r=" << r << "\n";
+  }
+  else if (cmd[1] == "status") {
+    if (ProfilingIsEnabledForAllThreads())
+      clog.info() << "cpu_profiler is enabled\n";
+    else
+      clog.info() << "cpu_profiler is not enabled\n";
+    ProfilerState st;
+    ProfilerGetCurrentState(&st);
+    clog.info() << "cpu_profiler " << (st.enabled ? "enabled":"not enabled")
+               << " start_time " << st.start_time
+               << " profile_name " << st.profile_name
+               << " samples " << st.samples_gathered
+               << "\n";
+  }
+  else if (cmd[1] == "flush") {
+    clog.info() << "cpu_profiler: flushing\n";
+    ProfilerFlush();
+  }
+  else if (cmd[1] == "stop") {
+    clog.info() << "cpu_profiler: flushing and stopping\n";
+    ProfilerFlush();
+    ProfilerStop();
+  }
+  else {
+    clog.info() << "can't understand cpu_profiler command. Expected one of: "
+               << "start,status,flush,stop.\n";
+  }
+}
diff --git a/src/perfglue/cpu_profiler.h b/src/perfglue/cpu_profiler.h
new file mode 100644 (file)
index 0000000..a5b6a97
--- /dev/null
@@ -0,0 +1,27 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+#ifndef CEPH_PERFGLUE_CPU_PROFILER
+
+/*
+ * Ceph glue for the Google Perftools CPU profiler
+ */
+#include <string>
+#include <vector>
+
+class LogClient;
+
+void cpu_profiler_handle_command(const std::vector<std::string> &cmd,
+                                LogClient &clog);
+
+#endif
diff --git a/src/perfglue/disabled_stubs.cc b/src/perfglue/disabled_stubs.cc
new file mode 100644 (file)
index 0000000..ad5b23b
--- /dev/null
@@ -0,0 +1,25 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/LogClient.h"
+#include "perfglue/cpu_profiler.h"
+
+#include <vector>
+#include <string>
+
+void cpu_profiler_handle_command(const std::vector<std::string> &cmd,
+                                LogClient &clog)
+{
+  clog.info() << "cpu_profiler support not linked in\n";
+}