Skip to content

Commit c51c9a8

Browse files
committed
test: add test to fetch perf counters via libcephfs API
Signed-off-by: Venky Shankar <[email protected]>
1 parent 259967e commit c51c9a8

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
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/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)