From dd74c1985807c00dfe5ceaefa2109912ba8e3381 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 9 Nov 2013 12:08:23 -0800 Subject: [PATCH] Tidy up LoadMonitor stats API --- src/ripple_core/functional/JobQueue.cpp | 24 ++++++------- src/ripple_core/functional/LoadMonitor.cpp | 40 +++++++++++++++++----- src/ripple_core/functional/LoadMonitor.h | 12 ++++++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/ripple_core/functional/JobQueue.cpp b/src/ripple_core/functional/JobQueue.cpp index 1814985164..328f07e02d 100644 --- a/src/ripple_core/functional/JobQueue.cpp +++ b/src/ripple_core/functional/JobQueue.cpp @@ -278,14 +278,11 @@ public: if (type == jtGENERIC) continue; - uint64 count; - uint64 latencyAvg; - uint64 latencyPeak; + LoadMonitor::Stats stats; int jobCount; int threadCount; - bool isOver; - m_loads [i].getCountAndLatency (count, latencyAvg, latencyPeak, isOver); + m_loads [i].getStats (); MapType::const_iterator it = m_jobCounts.find (type); @@ -300,11 +297,12 @@ public: threadCount = it->second.running; } - if ((count != 0) || (jobCount != 0) || (latencyPeak != 0) || (threadCount != 0)) + if ((stats.count != 0) || (jobCount != 0) || + (stats.latencyPeak != 0) || (threadCount != 0)) { Json::Value pri (Json::objectValue); - if (isOver) + if (stats.isOverloaded) pri["over_target"] = true; pri["job_type"] = Job::toString (type); @@ -312,14 +310,14 @@ public: if (jobCount != 0) pri["waiting"] = jobCount; - if (count != 0) - pri["per_second"] = static_cast (count); + if (stats.count != 0) + pri["per_second"] = static_cast (stats.count); - if (latencyPeak != 0) - pri["peak_time"] = static_cast (latencyPeak); + if (stats.latencyPeak != 0) + pri["peak_time"] = static_cast (stats.latencyPeak); - if (latencyAvg != 0) - pri["avg_time"] = static_cast (latencyAvg); + if (stats.latencyAvg != 0) + pri["avg_time"] = static_cast (stats.latencyAvg); if (threadCount != 0) pri["in_progress"] = threadCount; diff --git a/src/ripple_core/functional/LoadMonitor.cpp b/src/ripple_core/functional/LoadMonitor.cpp index 2575d904ed..13088c59e7 100644 --- a/src/ripple_core/functional/LoadMonitor.cpp +++ b/src/ripple_core/functional/LoadMonitor.cpp @@ -17,6 +17,26 @@ */ //============================================================================== +/* + +TODO +---- + +- Use Journal for logging + +*/ + +//------------------------------------------------------------------------------ + +LoadMonitor::Stats::Stats() + : count (0) + , latencyAvg (0) + , latencyPeak (0) + , isOverloaded (false) +{ +} + +//------------------------------------------------------------------------------ SETUP_LOG (LoadMonitor) @@ -171,26 +191,28 @@ bool LoadMonitor::isOver () return isOverTarget (mLatencyMSAvg / (mLatencyEvents * 4), mLatencyMSPeak / (mLatencyEvents * 4)); } -void LoadMonitor::getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver) +LoadMonitor::Stats LoadMonitor::getStats () { + Stats stats; + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); - count = mCounts / 4; + stats.count = mCounts / 4; if (mLatencyEvents == 0) { - latencyAvg = 0; - latencyPeak = 0; + stats.latencyAvg = 0; + stats.latencyPeak = 0; } else { - latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4); - latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4); + stats.latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4); + stats.latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4); } - isOver = isOverTarget (latencyAvg, latencyPeak); -} + stats.isOverloaded = isOverTarget (stats.latencyAvg, stats.latencyPeak); -// vim:ts=4 + return stats; +} diff --git a/src/ripple_core/functional/LoadMonitor.h b/src/ripple_core/functional/LoadMonitor.h index 5589206f93..fdaf989383 100644 --- a/src/ripple_core/functional/LoadMonitor.h +++ b/src/ripple_core/functional/LoadMonitor.h @@ -41,7 +41,17 @@ public: bool isOverTarget (uint64 avg, uint64 peak); // VFALCO TODO make this return the values in a struct. - void getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver); + struct Stats + { + Stats(); + + uint64 count; + uint64 latencyAvg; + uint64 latencyPeak; + bool isOverloaded; + }; + + Stats getStats (); bool isOver ();