From: Jaya Prakash Date: Thu, 3 Jul 2025 11:25:39 +0000 (+0000) Subject: common: add admin socket control and CMake flag for cputrace X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=905d2a0714ed48e5e6757a5a3839fe09e79b7c5c;p=ceph.git common: add admin socket control and CMake flag for cputrace - 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bc255b4df40e..a9a01b1db7d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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, \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 19dc380d62c7..f82166752ce3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -199,6 +199,10 @@ if(WITH_CEPH_DEBUG_MUTEX) add_compile_options($<$:-DCEPH_DEBUG_MUTEX>) endif() +if(WITH_CPUTRACE) + add_compile_options($<$:-DWITH_CPUTRACE>) +endif() + include(CheckCCompilerFlag) if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) CHECK_C_COMPILER_FLAG(-fstack-protector-strong HAS_STACK_PROTECT) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 1f21ad4c0c58..276c62aa3f8c 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index db4cae2db0eb..e7179e20142d 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -67,6 +67,10 @@ // for CINIT_FLAGS #include "common/common_init.h" +#ifdef WITH_CPUTRACE +#include "common/cputrace.h" +#endif + #include #include @@ -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());