Skip to content

Commit 9d55fa0

Browse files
committed
Merge PR ceph#62632 into main
* refs/pull/62632/head: libcephfs: increment library minor version test: add test to fetch perf counters via libcephfs API libcephfs: add API to get client perf counters client: fix total write operations perf counter name Reviewed-by: Patrick Donnelly <[email protected]>
2 parents 84fb640 + 48446ab commit 9d55fa0

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

qa/workunits/libcephfs/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ ceph_test_libcephfs_newops
88
ceph_test_libcephfs_suidsgid
99
ceph_test_libcephfs_snapdiff
1010
ceph_test_libcephfs_vxattr
11+
ceph_test_libcephfs_perfcounters
1112

1213
exit 0

src/client/Client.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void Client::_finish_init()
670670
plb.add_u64(l_c_rd_ops, "rdops", "Total read IO operations");
671671
plb.add_time(l_c_wr_avg, "writeavg", "Average latency for processing write requests");
672672
plb.add_u64(l_c_wr_sqsum, "writesqsum", "Sum of squares ((to calculate variability/stdev) for write requests");
673-
plb.add_u64(l_c_wr_ops, "rdops", "Total write IO operations");
673+
plb.add_u64(l_c_wr_ops, "wrops", "Total write IO operations");
674674
logger.reset(plb.create_perf_counters());
675675
cct->get_perfcounters_collection()->add(logger.get());
676676
}
@@ -17487,6 +17487,23 @@ void Client::set_cap_epoch_barrier(epoch_t e)
1748717487
cap_epoch_barrier = e;
1748817488
}
1748917489

17490+
int Client::get_perf_counters(bufferlist *outbl) {
17491+
RWRef_t iref_reader(initialize_state, CLIENT_INITIALIZED);
17492+
if (!iref_reader.is_state_satisfied()) {
17493+
return -ENOTCONN;
17494+
}
17495+
17496+
ceph::bufferlist inbl;
17497+
std::ostringstream err;
17498+
std::vector<std::string> cmd{
17499+
"{\"prefix\": \"perf dump\"}",
17500+
"{\"format\": \"json\"}"
17501+
};
17502+
17503+
ldout(cct, 10) << __func__ << ": perf cmd=" << cmd << dendl;
17504+
return cct->get_admin_socket()->execute_command(cmd, inbl, err, outbl);
17505+
}
17506+
1749017507
std::vector<std::string> Client::get_tracked_keys() const noexcept
1749117508
{
1749217509
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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern "C" {
4040
#endif
4141

4242
#define LIBCEPHFS_VER_MAJOR 10
43-
#define LIBCEPHFS_VER_MINOR 0
43+
#define LIBCEPHFS_VER_MINOR 1
4444
#define LIBCEPHFS_VER_EXTRA 3
4545

4646
#define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
@@ -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+
}

src/test/libcephfs/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,19 @@ target_link_libraries(ceph_test_libcephfs_lazyio
122122
)
123123
install(TARGETS ceph_test_libcephfs_access
124124
DESTINATION ${CMAKE_INSTALL_BINDIR})
125+
126+
add_executable(ceph_test_libcephfs_perfcounters
127+
perfcounters.cc
128+
main.cc
129+
)
130+
target_link_libraries(ceph_test_libcephfs_perfcounters
131+
ceph-common
132+
cephfs
133+
librados
134+
${UNITTEST_LIBS}
135+
${EXTRALIBS}
136+
${CMAKE_DL_LIBS}
137+
)
138+
install(TARGETS ceph_test_libcephfs_perfcounters
139+
DESTINATION ${CMAKE_INSTALL_BINDIR})
125140
endif(WITH_LIBCEPHFS)

src/test/libcephfs/perfcounters.cc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2+
// vim: ts=8 sw=2 smarttab
3+
/*
4+
* Ceph - scalable distributed file system
5+
*
6+
*
7+
* This is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License version 2.1, as published by the Free Software
10+
* Foundation. See file COPYING.
11+
*
12+
*/
13+
14+
#include "include/compat.h"
15+
#include "gtest/gtest.h"
16+
#include "include/cephfs/libcephfs.h"
17+
#include "common/ceph_json.h"
18+
#include "include/utime.h"
19+
20+
#include <string>
21+
22+
using namespace std;
23+
24+
TEST(LibCephFS, ValidatePerfCounters) {
25+
struct ceph_mount_info *cmount;
26+
ASSERT_EQ(0, ceph_create(&cmount, NULL));
27+
ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
28+
ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
29+
ASSERT_EQ(0, ceph_mount(cmount, "/"));
30+
31+
char *perf_dump;
32+
int len = ceph_get_perf_counters(cmount, &perf_dump);
33+
ASSERT_GT(len, 0);
34+
35+
JSONParser jp;
36+
ASSERT_TRUE(jp.parse(perf_dump, len));
37+
38+
JSONObj *jo = jp.find_obj("client");
39+
40+
// basic verification to chek if we have (some) fields in
41+
// the json object.
42+
utime_t val;
43+
JSONDecoder::decode_json("mdavg", val, jo);
44+
JSONDecoder::decode_json("readavg", val, jo);
45+
JSONDecoder::decode_json("writeavg", val, jo);
46+
47+
int count;
48+
JSONDecoder::decode_json("mdops", count, jo);
49+
JSONDecoder::decode_json("rdops", count, jo);
50+
JSONDecoder::decode_json("wrops", count, jo);
51+
52+
free(perf_dump);
53+
ceph_shutdown(cmount);
54+
}

0 commit comments

Comments
 (0)