]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add admin socket control and CMake flag for cputrace
authorJaya Prakash <jayaprakash@ibm.com>
Thu, 3 Jul 2025 11:25:39 +0000 (11:25 +0000)
committerJaya Prakash <jayaprakash@ibm.com>
Tue, 7 Oct 2025 14:13:47 +0000 (14:13 +0000)
- Introduced a separate CMake flag to enable cputrace:
    cmake -DWITH_CPUTRACE=1 ...

- Added admin socket interface for runtime control:
    - `ceph tell osd.X cputrace start`   → Start profiling
    - `ceph tell osd.X cputrace stop`    → Stop profiling
    - `ceph tell osd.X cputrace dump`    → Dump collected metrics
    - `ceph tell osd.X cputrace reset`   → Reset profiling state

This enables developers to dynamically control profiling during runtime
without rebuilding or restarting the OSD, and ensures `cputrace` remains
disabled in production unless explicitly enabled at build time.

Signed-off-by: Jaya Prakash <jayaprakash@ibm.com>
CMakeLists.txt
src/CMakeLists.txt
src/common/CMakeLists.txt
src/common/ceph_context.cc

index bc255b4df40ed81393d7855c411799b246e67762..a9a01b1db7d8fbfef0c2763261dc6eb2eda81a76 100644 (file)
@@ -431,6 +431,8 @@ endif(WITH_LZ4)
 CMAKE_DEPENDENT_OPTION(WITH_CEPH_DEBUG_MUTEX "Use debug ceph::mutex with lockdep" ON
   "CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
 
+option(WITH_CPUTRACE "Enable Cputrace support via the admin socket" OFF)
+
 #if allocator is set on command line make sure it matches below strings
 set(ALLOCATOR "" CACHE STRING
   "specify memory allocator to use. currently tcmalloc, tcmalloc_minimal, \
index 19dc380d62c766943dd26c2a35a4ec2758134b27..f82166752ce36537c2f5f7f5587e3d761b020e1d 100644 (file)
@@ -199,6 +199,10 @@ if(WITH_CEPH_DEBUG_MUTEX)
   add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-DCEPH_DEBUG_MUTEX>)
 endif()
 
+if(WITH_CPUTRACE)
+  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-DWITH_CPUTRACE>)
+endif()
+
 include(CheckCCompilerFlag)
 if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
     CHECK_C_COMPILER_FLAG(-fstack-protector-strong HAS_STACK_PROTECT)
index 1f21ad4c0c5838397468bd762458281dc8598516..276c62aa3f8cd56df68fd866e8da2da38d270bf0 100644 (file)
@@ -112,7 +112,13 @@ set(common_srcs
   mclock_common.cc
   tcp_info.cc)
 
+if(WITH_CPUTRACE)
+  list(APPEND common_srcs
+    cputrace.cc)
+endif()
+
 include_directories(${CMAKE_SOURCE_DIR}/src/dmclock/support/src)
+
 if(WITH_SYSTEMD)
   list(APPEND common_srcs
     Journald.cc)
index db4cae2db0eb4fe180d323c2476ea5420c4ea065..e7179e20142d3975f2a8d492b4353283c4c8a4f0 100644 (file)
 // for CINIT_FLAGS
 #include "common/common_init.h"
 
+#ifdef WITH_CPUTRACE
+#include "common/cputrace.h"
+#endif
+
 #include <iostream>
 #include <pthread.h>
 
@@ -685,6 +689,24 @@ int CephContext::_do_command(
     else if (command == "log reopen") {
       _log->reopen_log_file();
     }
+#ifdef WITH_CPUTRACE
+    else if (command == "cputrace start") {
+      cputrace_start(f);
+    }
+    else if (command == "cputrace stop") {
+      cputrace_stop(f);
+    }
+    else if (command == "cputrace dump") {
+      std::string logger;
+      std::string counter;
+      cmd_getval(cmdmap, "logger", logger);
+      cmd_getval(cmdmap, "counter", counter);
+      cputrace_dump(f, logger, counter);
+    }
+    else if (command == "cputrace reset") {
+      cputrace_reset(f);
+    }
+#endif
     else {
       ceph_abort_msg("registered under wrong command?");    
     }
@@ -781,6 +803,12 @@ CephContext::CephContext(uint32_t module_type_,
   _admin_socket->register_command("log dump", _admin_hook, "dump recent log entries to log file");
   _admin_socket->register_command("log reopen", _admin_hook, "reopen log file");
 
+#ifdef WITH_CPUTRACE
+  _admin_socket->register_command("cputrace start", _admin_hook, "start cpu profiling");
+  _admin_socket->register_command("cputrace stop", _admin_hook, "stop cpu profiling");
+  _admin_socket->register_command("cputrace reset", _admin_hook, "reset cpu profiling");
+  _admin_socket->register_command("cputrace dump name=logger,type=CephString,req=false name=counter,type=CephString,req=false", _admin_hook, "dump cpu profiling results");
+#endif
   _crypto_none = CryptoHandler::create(CEPH_CRYPTO_NONE);
   _crypto_aes = CryptoHandler::create(CEPH_CRYPTO_AES);
   _crypto_random.reset(new CryptoRandom());