From ebde89d5602536b4bc651737e4280fdfb6634c32 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Tue, 13 Aug 2013 17:36:57 -0700 Subject: [PATCH] ObjectStore: add ObjectStore::get_cur_stats and impl in FileStore Signed-off-by: Samuel Just --- src/common/perf_counters.cc | 16 ++++++++++++++++ src/common/perf_counters.h | 20 ++++++++++++++++++++ src/os/FileStore.cc | 11 +++++++++++ src/os/FileStore.h | 19 +++++++++++++++++++ src/os/ObjectStore.h | 2 ++ src/osd/OSD.cc | 2 ++ 6 files changed, 70 insertions(+) diff --git a/src/common/perf_counters.cc b/src/common/perf_counters.cc index 1dd4cdabd9d85..339ff6a372bbf 100644 --- a/src/common/perf_counters.cc +++ b/src/common/perf_counters.cc @@ -203,6 +203,22 @@ utime_t PerfCounters::tget(int idx) const return utime_t(data.u64 / 1000000000ull, data.u64 % 1000000000ull); } +pair PerfCounters::get_tavg_ms(int idx) const +{ + if (!m_cct->_conf->perf) + return make_pair(0, 0); + + Mutex::Locker lck(m_lock); + assert(idx > m_lower_bound); + assert(idx < m_upper_bound); + const perf_counter_data_any_d& data(m_data[idx - m_lower_bound - 1]); + if (!(data.type & PERFCOUNTER_TIME)) + return make_pair(0, 0); + if (!(data.type & PERFCOUNTER_LONGRUNAVG)) + return make_pair(0, 0); + return make_pair(data.avgcount, data.u64/1000000); +} + void PerfCounters::dump_formatted(Formatter *f, bool schema) { Mutex::Locker lck(m_lock); diff --git a/src/common/perf_counters.h b/src/common/perf_counters.h index ec10f9a928286..f4651c69f1ca9 100644 --- a/src/common/perf_counters.h +++ b/src/common/perf_counters.h @@ -65,6 +65,24 @@ enum perfcounter_type_d class PerfCounters { public: + template + struct avg_tracker { + pair last; + pair cur; + avg_tracker() : last(0, 0), cur(0, 0) {} + T avg() const { + if (cur.first == last.first) + return cur.first ? + cur.second / cur.first : + 0; // no change, report avg over all time + return (cur.second - last.second) / (cur.first - last.first); + } + void consume_next(const pair &next) { + last = cur; + cur = next; + } + }; + ~PerfCounters(); void inc(int idx, uint64_t v = 1); @@ -78,6 +96,8 @@ public: void dump_formatted(ceph::Formatter *f, bool schema); + pair get_tavg_ms(int idx) const; + const std::string& get_name() const; void set_name(std::string s) { m_name = s; diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 108a857ab9fc9..e442dd4fe2bf0 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -126,6 +126,17 @@ static const __SWORD_TYPE XFS_SUPER_MAGIC(0x58465342); #define ALIGNED(x, by) (!((x) % (by))) #define ALIGN_UP(x, by) (ALIGNED((x), (by)) ? (x) : (ALIGN_DOWN((x), (by)) + (by))) +void FileStore::FSPerfTracker::update_from_perfcounters( + PerfCounters &logger) +{ + os_commit_latency.consume_next( + logger.get_tavg_ms( + l_os_commit_lat)); + os_apply_latency.consume_next( + logger.get_tavg_ms( + l_os_apply_lat)); +} + ostream& operator<<(ostream& out, const FileStore::OpSequencer& s) { diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 86d267dddf1cc..ba428093cdaf6 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -55,6 +55,25 @@ class FileStore : public JournalingObjectStore, public md_config_obs_t { public: + + struct FSPerfTracker { + PerfCounters::avg_tracker os_commit_latency; + PerfCounters::avg_tracker os_apply_latency; + + filestore_perf_stat_t get_cur_stats() const { + filestore_perf_stat_t ret; + ret.filestore_commit_latency = os_commit_latency.avg(); + ret.filestore_apply_latency = os_apply_latency.avg(); + return ret; + } + + void update_from_perfcounters(PerfCounters &logger); + } perf_tracker; + filestore_perf_stat_t get_cur_stats() { + perf_tracker.update_from_perfcounters(*logger); + return perf_tracker.get_cur_stats(); + } + static const uint32_t on_disk_version = 3; private: string internal_name; ///< internal name, used to name the perfcounter instance diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 6bfefa09a470a..eb5b40c5a690e 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -81,6 +81,8 @@ public: Logger *logger; + virtual filestore_perf_stat_t get_cur_stats() = 0; + /** * a sequencer orders transactions * diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 1a77dae730ab7..14bdc87487ce7 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3648,6 +3648,8 @@ void OSD::send_pg_stats(const utime_t &now) stat_lock.Lock(); osd_stat_t cur_stat = osd_stat; stat_lock.Unlock(); + + osd_stat.fs_perf_stat = store->get_cur_stats(); pg_stat_queue_lock.Lock(); -- 2.39.5