From 259967e7b74263bacde073d601a300cef19078a2 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Wed, 26 Mar 2025 12:25:21 +0000 Subject: [PATCH] libcephfs: add API to get client perf counters Fixes: http://tracker.ceph.com/issues/71233 Signed-off-by: Venky Shankar --- src/client/Client.cc | 17 +++++++++++++++++ src/client/Client.h | 2 ++ src/include/cephfs/libcephfs.h | 17 +++++++++++++++++ src/libcephfs.cc | 11 +++++++++++ 4 files changed, 47 insertions(+) diff --git a/src/client/Client.cc b/src/client/Client.cc index 5c8185ab015..6a484bfc78f 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -17483,6 +17483,23 @@ void Client::set_cap_epoch_barrier(epoch_t e) cap_epoch_barrier = e; } +int Client::get_perf_counters(bufferlist *outbl) { + RWRef_t iref_reader(initialize_state, CLIENT_INITIALIZED); + if (!iref_reader.is_state_satisfied()) { + return -ENOTCONN; + } + + ceph::bufferlist inbl; + std::ostringstream err; + std::vector cmd{ + "{\"prefix\": \"perf dump\"}", + "{\"format\": \"json\"}" + }; + + ldout(cct, 10) << __func__ << ": perf cmd=" << cmd << dendl; + return cct->get_admin_socket()->execute_command(cmd, inbl, err, outbl); +} + std::vector Client::get_tracked_keys() const noexcept { static constexpr auto as_sv = std::to_array({ diff --git a/src/client/Client.h b/src/client/Client.h index 7ab691e2107..870cb970724 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -380,6 +380,8 @@ public: std::vector> *blocks); int file_blockdiff_finish(struct scan_state_t *state); + int get_perf_counters(bufferlist *outbl); + /* * Get the next snapshot delta entry. * diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 0a08e89566c..75a8c5e387a 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -2285,6 +2285,23 @@ int ceph_get_snap_info(struct ceph_mount_info *cmount, * @param snap_info snapshot info struct (fetched via call to ceph_get_snap_info()). */ void ceph_free_snap_info_buffer(struct snap_info *snap_info); + +/** + * perf counters via libcephfs API. + */ + +/** + * Get a json string of performance counters + * + * @param cmount the ceph mount handle to use. + * @param perf_dump buffer holding the perf dump + * + * Returns 0 success with the performance counters populated in the + * passed in perf_dump buffer. Caller is responsible for freeing the + * @perf_dump buffer using free(). + */ +int ceph_get_perf_counters(struct ceph_mount_info *cmount, char **perf_dump); + #ifdef __cplusplus } #endif diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 3c3cfe4d35a..be4d6d9beec 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -2540,3 +2540,14 @@ extern "C" void ceph_free_snap_info_buffer(struct snap_info *snap_info) { } free(snap_info->snap_metadata); } + +extern "C" int ceph_get_perf_counters(struct ceph_mount_info *cmount, char **perf_dump) { + bufferlist outbl; + int r = cmount->get_client()->get_perf_counters(&outbl); + if (r != 0) { + return r; + } + + do_out_buffer(outbl, perf_dump, NULL); + return outbl.length(); +} -- 2.39.5