]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add test to fetch perf counters via libcephfs API
authorVenky Shankar <vshankar@redhat.com>
Wed, 2 Apr 2025 13:02:04 +0000 (13:02 +0000)
committerVenky Shankar <vshankar@redhat.com>
Mon, 12 May 2025 08:42:17 +0000 (08:42 +0000)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
qa/workunits/libcephfs/test.sh
src/test/libcephfs/CMakeLists.txt
src/test/libcephfs/perfcounters.cc [new file with mode: 0644]

index dc8ef1fc72f4f382d3457bd18a330f4f482ab716..dbddf9cdb8f8ebccbd713055c9fc26559e896b25 100755 (executable)
@@ -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
index 8ad73529fea12e0e58fbccedf5478a96b7d41f41..6a75dd2578b1e7a653cff80b7749bbc96a756d16 100644 (file)
@@ -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 (file)
index 0000000..179d8e8
--- /dev/null
@@ -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 <string>
+
+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);
+}