From c51c9a89598774c888d60a6122a878b2d6a96277 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Wed, 2 Apr 2025 13:02:04 +0000 Subject: [PATCH] test: add test to fetch perf counters via libcephfs API Signed-off-by: Venky Shankar --- qa/workunits/libcephfs/test.sh | 1 + src/test/libcephfs/CMakeLists.txt | 15 +++++++++ src/test/libcephfs/perfcounters.cc | 54 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/test/libcephfs/perfcounters.cc diff --git a/qa/workunits/libcephfs/test.sh b/qa/workunits/libcephfs/test.sh index dc8ef1fc72f4f..dbddf9cdb8f8e 100755 --- a/qa/workunits/libcephfs/test.sh +++ b/qa/workunits/libcephfs/test.sh @@ -8,5 +8,6 @@ ceph_test_libcephfs_newops ceph_test_libcephfs_suidsgid ceph_test_libcephfs_snapdiff ceph_test_libcephfs_vxattr +ceph_test_libcephfs_perfcounters exit 0 diff --git a/src/test/libcephfs/CMakeLists.txt b/src/test/libcephfs/CMakeLists.txt index 8ad73529fea12..6a75dd2578b1e 100644 --- a/src/test/libcephfs/CMakeLists.txt +++ b/src/test/libcephfs/CMakeLists.txt @@ -122,4 +122,19 @@ target_link_libraries(ceph_test_libcephfs_lazyio ) install(TARGETS ceph_test_libcephfs_access DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_executable(ceph_test_libcephfs_perfcounters + perfcounters.cc + main.cc + ) + target_link_libraries(ceph_test_libcephfs_perfcounters + ceph-common + cephfs + librados + ${UNITTEST_LIBS} + ${EXTRALIBS} + ${CMAKE_DL_LIBS} + ) + install(TARGETS ceph_test_libcephfs_perfcounters + DESTINATION ${CMAKE_INSTALL_BINDIR}) endif(WITH_LIBCEPHFS) diff --git a/src/test/libcephfs/perfcounters.cc b/src/test/libcephfs/perfcounters.cc new file mode 100644 index 0000000000000..179d8e8f46249 --- /dev/null +++ b/src/test/libcephfs/perfcounters.cc @@ -0,0 +1,54 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "include/compat.h" +#include "gtest/gtest.h" +#include "include/cephfs/libcephfs.h" +#include "common/ceph_json.h" +#include "include/utime.h" + +#include + +using namespace std; + +TEST(LibCephFS, ValidatePerfCounters) { + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + char *perf_dump; + int len = ceph_get_perf_counters(cmount, &perf_dump); + ASSERT_GT(len, 0); + + JSONParser jp; + ASSERT_TRUE(jp.parse(perf_dump, len)); + + JSONObj *jo = jp.find_obj("client"); + + // basic verification to chek if we have (some) fields in + // the json object. + utime_t val; + JSONDecoder::decode_json("mdavg", val, jo); + JSONDecoder::decode_json("readavg", val, jo); + JSONDecoder::decode_json("writeavg", val, jo); + + int count; + JSONDecoder::decode_json("mdops", count, jo); + JSONDecoder::decode_json("rdops", count, jo); + JSONDecoder::decode_json("wrops", count, jo); + + free(perf_dump); + ceph_shutdown(cmount); +} -- 2.39.5