Skip to content

Commit 259967e

Browse files
committed
libcephfs: add API to get client perf counters
Fixes: http://tracker.ceph.com/issues/71233 Signed-off-by: Venky Shankar <[email protected]>
1 parent 00ff16c commit 259967e

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/client/Client.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17483,6 +17483,23 @@ void Client::set_cap_epoch_barrier(epoch_t e)
1748317483
cap_epoch_barrier = e;
1748417484
}
1748517485

17486+
int Client::get_perf_counters(bufferlist *outbl) {
17487+
RWRef_t iref_reader(initialize_state, CLIENT_INITIALIZED);
17488+
if (!iref_reader.is_state_satisfied()) {
17489+
return -ENOTCONN;
17490+
}
17491+
17492+
ceph::bufferlist inbl;
17493+
std::ostringstream err;
17494+
std::vector<std::string> cmd{
17495+
"{\"prefix\": \"perf dump\"}",
17496+
"{\"format\": \"json\"}"
17497+
};
17498+
17499+
ldout(cct, 10) << __func__ << ": perf cmd=" << cmd << dendl;
17500+
return cct->get_admin_socket()->execute_command(cmd, inbl, err, outbl);
17501+
}
17502+
1748617503
std::vector<std::string> Client::get_tracked_keys() const noexcept
1748717504
{
1748817505
static constexpr auto as_sv = std::to_array<std::string_view>({

src/client/Client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ class Client : public Dispatcher, public md_config_obs_t {
380380
std::vector<std::pair<uint64_t,uint64_t>> *blocks);
381381
int file_blockdiff_finish(struct scan_state_t *state);
382382

383+
int get_perf_counters(bufferlist *outbl);
384+
383385
/*
384386
* Get the next snapshot delta entry.
385387
*

src/include/cephfs/libcephfs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,23 @@ int ceph_get_snap_info(struct ceph_mount_info *cmount,
22852285
* @param snap_info snapshot info struct (fetched via call to ceph_get_snap_info()).
22862286
*/
22872287
void ceph_free_snap_info_buffer(struct snap_info *snap_info);
2288+
2289+
/**
2290+
* perf counters via libcephfs API.
2291+
*/
2292+
2293+
/**
2294+
* Get a json string of performance counters
2295+
*
2296+
* @param cmount the ceph mount handle to use.
2297+
* @param perf_dump buffer holding the perf dump
2298+
*
2299+
* Returns 0 success with the performance counters populated in the
2300+
* passed in perf_dump buffer. Caller is responsible for freeing the
2301+
* @perf_dump buffer using free().
2302+
*/
2303+
int ceph_get_perf_counters(struct ceph_mount_info *cmount, char **perf_dump);
2304+
22882305
#ifdef __cplusplus
22892306
}
22902307
#endif

src/libcephfs.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,3 +2540,14 @@ extern "C" void ceph_free_snap_info_buffer(struct snap_info *snap_info) {
25402540
}
25412541
free(snap_info->snap_metadata);
25422542
}
2543+
2544+
extern "C" int ceph_get_perf_counters(struct ceph_mount_info *cmount, char **perf_dump) {
2545+
bufferlist outbl;
2546+
int r = cmount->get_client()->get_perf_counters(&outbl);
2547+
if (r != 0) {
2548+
return r;
2549+
}
2550+
2551+
do_out_buffer(outbl, perf_dump, NULL);
2552+
return outbl.length();
2553+
}

0 commit comments

Comments
 (0)