|
| 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