diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index e86d28c8f2..9fc503c1dd 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1558,11 +1558,6 @@ - - True - - - True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index a1578063b6..51a4863769 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -2100,12 +2100,6 @@ ripple\beast\core - - ripple\beast\core - - - ripple\beast\core - ripple\beast\core diff --git a/src/ripple/app/misc/Validations.cpp b/src/ripple/app/misc/Validations.cpp index 7eb172a93b..2b477baac5 100644 --- a/src/ripple/app/misc/Validations.cpp +++ b/src/ripple/app/misc/Validations.cpp @@ -401,7 +401,8 @@ private: void doWrite () { - LoadEvent::autoptr event (app_.getJobQueue ().getLoadEventAP (jtDISK, "ValidationWrite")); + auto event = app_.getJobQueue ().getLoadEventAP (jtDISK, "ValidationWrite"); + std::string insVal ("INSERT INTO Validations " "(InitialSeq, LedgerSeq, LedgerHash,NodePubKey,SignTime,RawData) " "VALUES (:initialSeq, :ledgerSeq, :ledgerHash,:nodePubKey,:signTime,:rawData);"); diff --git a/src/ripple/app/paths/Pathfinder.h b/src/ripple/app/paths/Pathfinder.h index fb8b478580..2a9dc2f664 100644 --- a/src/ripple/app/paths/Pathfinder.h +++ b/src/ripple/app/paths/Pathfinder.h @@ -181,7 +181,7 @@ private: bool convert_all_; std::shared_ptr mLedger; - LoadEvent::pointer m_loadEvent; + std::shared_ptr m_loadEvent; std::shared_ptr mRLCache; STPathElement mSource; diff --git a/src/ripple/basics/impl/Sustain.cpp b/src/ripple/basics/impl/Sustain.cpp index 79df6a85fe..57f49805aa 100644 --- a/src/ripple/basics/impl/Sustain.cpp +++ b/src/ripple/basics/impl/Sustain.cpp @@ -130,8 +130,8 @@ std::string DoSustain () while (checkChild (pChild, 0)) sleep(sleepBetweenWaits); - auto pc = std::to_string (pChild); - rename ("core", ("core." + pc).c_str ()); + (void)rename ("core", + ("core." + std::to_string(pChild)).c_str()); } } } diff --git a/src/ripple/beast/core/RelativeTime.cpp b/src/ripple/beast/core/RelativeTime.cpp deleted file mode 100644 index 1400c73f33..0000000000 --- a/src/ripple/beast/core/RelativeTime.cpp +++ /dev/null @@ -1,291 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include - -namespace beast { - -RelativeTime::RelativeTime (const RelativeTime::value_type secs) noexcept - : numSeconds (secs) -{ -} - -RelativeTime::RelativeTime (const RelativeTime& other) noexcept - : numSeconds (other.numSeconds) -{ -} - -RelativeTime::~RelativeTime() noexcept {} - -//============================================================================== - -RelativeTime RelativeTime::milliseconds (const int milliseconds) noexcept -{ - return RelativeTime (milliseconds * 0.001); -} - -RelativeTime RelativeTime::milliseconds (const std::int64_t milliseconds) noexcept -{ - return RelativeTime (milliseconds * 0.001); -} - -RelativeTime RelativeTime::seconds (RelativeTime::value_type s) noexcept -{ - return RelativeTime (s); -} - -RelativeTime RelativeTime::minutes (const RelativeTime::value_type numberOfMinutes) noexcept -{ - return RelativeTime (numberOfMinutes * 60.0); -} - -RelativeTime RelativeTime::hours (const RelativeTime::value_type numberOfHours) noexcept -{ - return RelativeTime (numberOfHours * (60.0 * 60.0)); -} - -RelativeTime RelativeTime::days (const RelativeTime::value_type numberOfDays) noexcept -{ - return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0)); -} - -RelativeTime RelativeTime::weeks (const RelativeTime::value_type numberOfWeeks) noexcept -{ - return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0)); -} - -//============================================================================== - -std::int64_t RelativeTime::inMilliseconds() const noexcept -{ - return (std::int64_t) (numSeconds * 1000.0); -} - -RelativeTime::value_type RelativeTime::inMinutes() const noexcept -{ - return numSeconds / 60.0; -} - -RelativeTime::value_type RelativeTime::inHours() const noexcept -{ - return numSeconds / (60.0 * 60.0); -} - -RelativeTime::value_type RelativeTime::inDays() const noexcept -{ - return numSeconds / (60.0 * 60.0 * 24.0); -} - -RelativeTime::value_type RelativeTime::inWeeks() const noexcept -{ - return numSeconds / (60.0 * 60.0 * 24.0 * 7.0); -} - -//============================================================================== - -RelativeTime& RelativeTime::operator= (const RelativeTime& other) noexcept { numSeconds = other.numSeconds; return *this; } - -RelativeTime RelativeTime::operator+= (RelativeTime t) noexcept -{ - numSeconds += t.numSeconds; return *this; -} - -RelativeTime RelativeTime::operator-= (RelativeTime t) noexcept -{ - numSeconds -= t.numSeconds; return *this; -} - -RelativeTime RelativeTime::operator+= (const RelativeTime::value_type secs) noexcept -{ - numSeconds += secs; return *this; -} - -RelativeTime RelativeTime::operator-= (const RelativeTime::value_type secs) noexcept -{ - numSeconds -= secs; return *this; -} - -RelativeTime operator+ (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1 += t2; -} - -RelativeTime operator- (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1 -= t2; -} - -bool operator== (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() == t2.inSeconds(); -} - -bool operator!= (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() != t2.inSeconds(); -} - -bool operator> (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() > t2.inSeconds(); -} - -bool operator< (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() < t2.inSeconds(); -} - -bool operator>= (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() >= t2.inSeconds(); -} - -bool operator<= (RelativeTime t1, RelativeTime t2) noexcept -{ - return t1.inSeconds() <= t2.inSeconds(); -} - -} - -#if BEAST_WINDOWS - -#include - -namespace beast { -namespace detail { - -static double monotonicCurrentTimeInSeconds() -{ - return GetTickCount64() / 1000.0; -} - -} -} - -#elif BEAST_MAC || BEAST_IOS - -#include -#include - -namespace beast { -namespace detail { - -static double monotonicCurrentTimeInSeconds() -{ - struct StaticInitializer - { - StaticInitializer () - { - double numerator; - double denominator; - - mach_timebase_info_data_t timebase; - (void) mach_timebase_info (&timebase); - - if (timebase.numer % 1000000 == 0) - { - numerator = timebase.numer / 1000000.0; - denominator = timebase.denom * 1000.0; - } - else - { - numerator = timebase.numer; - // VFALCO NOTE I don't understand this code - //denominator = timebase.denom * (std::uint64_t) 1000000 * 1000.0; - denominator = timebase.denom * 1000000000.0; - } - - ratio = numerator / denominator; - } - - double ratio; - }; - - static StaticInitializer const data; - - return mach_absolute_time() * data.ratio; -} -} -} - -#else - -#include - -namespace beast { -namespace detail { - -static double monotonicCurrentTimeInSeconds() -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - return t.tv_sec + t.tv_nsec / 1000000000.0; -} - -} -} - -#endif - -namespace beast { -namespace detail { - -// Records and returns the time from process startup -static double getStartupTime() -{ - struct StaticInitializer - { - StaticInitializer () - { - when = beast::detail::monotonicCurrentTimeInSeconds(); - } - - double when; - }; - - static StaticInitializer const data; - - return data.when; -} - -// Used to call getStartupTime as early as possible -struct StartupTimeStaticInitializer -{ - StartupTimeStaticInitializer () - { - getStartupTime(); - } -}; - -static StartupTimeStaticInitializer startupTimeStaticInitializer; - -} - -RelativeTime RelativeTime::fromStartup () -{ - return RelativeTime ( - detail::monotonicCurrentTimeInSeconds() - detail::getStartupTime()); -} - -} - diff --git a/src/ripple/beast/core/RelativeTime.h b/src/ripple/beast/core/RelativeTime.h deleted file mode 100644 index ca7799bda7..0000000000 --- a/src/ripple/beast/core/RelativeTime.h +++ /dev/null @@ -1,190 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_CHRONO_RELATIVETIME_H_INCLUDED -#define BEAST_CHRONO_RELATIVETIME_H_INCLUDED - -#include - -#include -#include - -namespace beast { - -//============================================================================== -/** A relative measure of time. - - The time is stored as a number of seconds, at double-precision floating - point accuracy, and may be positive or negative. - - If you need an absolute time, (i.e. a date + time), see the Time class. -*/ -class RelativeTime -{ -public: - //============================================================================== - /** The underlying data type used by RelativeTime. - - If you need to get to the underlying time and manipulate it - you can use this to declare a type that is guaranteed to - work cleanly. - */ - using value_type = double; - - //============================================================================== - /** Creates a RelativeTime. - - @param seconds the number of seconds, which may be +ve or -ve. - @see milliseconds, minutes, hours, days, weeks - */ - explicit RelativeTime (value_type seconds = 0.0) noexcept; - - /** Copies another relative time. */ - RelativeTime (const RelativeTime& other) noexcept; - - /** Copies another relative time. */ - RelativeTime& operator= (const RelativeTime& other) noexcept; - - /** Destructor. */ - ~RelativeTime() noexcept; - - bool isZero() const - { return numSeconds == 0; } - - bool isNotZero() const - { return numSeconds != 0; } - - /** Returns the amount of time since the process was started. */ - static RelativeTime fromStartup (); - - //============================================================================== - /** Creates a new RelativeTime object representing a number of milliseconds. - @see seconds, minutes, hours, days, weeks - */ - static RelativeTime milliseconds (int milliseconds) noexcept; - - /** Creates a new RelativeTime object representing a number of milliseconds. - @see seconds, minutes, hours, days, weeks - */ - static RelativeTime milliseconds (std::int64_t milliseconds) noexcept; - - /** Creates a new RelativeTime object representing a number of seconds. - @see milliseconds, minutes, hours, days, weeks - */ - static RelativeTime seconds (value_type seconds) noexcept; - - /** Creates a new RelativeTime object representing a number of minutes. - @see milliseconds, hours, days, weeks - */ - static RelativeTime minutes (value_type numberOfMinutes) noexcept; - - /** Creates a new RelativeTime object representing a number of hours. - @see milliseconds, minutes, days, weeks - */ - static RelativeTime hours (value_type numberOfHours) noexcept; - - /** Creates a new RelativeTime object representing a number of days. - @see milliseconds, minutes, hours, weeks - */ - static RelativeTime days (value_type numberOfDays) noexcept; - - /** Creates a new RelativeTime object representing a number of weeks. - @see milliseconds, minutes, hours, days - */ - static RelativeTime weeks (value_type numberOfWeeks) noexcept; - - //============================================================================== - /** Returns the number of milliseconds this time represents. - @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks - */ - std::int64_t inMilliseconds() const noexcept; - - /** Returns the number of seconds this time represents. - @see inMilliseconds, inMinutes, inHours, inDays, inWeeks - */ - value_type inSeconds() const noexcept { return numSeconds; } - - /** Returns the number of minutes this time represents. - @see inMilliseconds, inSeconds, inHours, inDays, inWeeks - */ - value_type inMinutes() const noexcept; - - /** Returns the number of hours this time represents. - @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks - */ - value_type inHours() const noexcept; - - /** Returns the number of days this time represents. - @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks - */ - value_type inDays() const noexcept; - - /** Returns the number of weeks this time represents. - @see inMilliseconds, inSeconds, inMinutes, inHours, inDays - */ - value_type inWeeks() const noexcept; - - template - RelativeTime operator+ (Number seconds) const noexcept - { return RelativeTime (numSeconds + seconds); } - - template - RelativeTime operator- (Number seconds) const noexcept - { return RelativeTime (numSeconds - seconds); } - - /** Adds another RelativeTime to this one. */ - RelativeTime operator+= (RelativeTime timeToAdd) noexcept; - - /** Subtracts another RelativeTime from this one. */ - RelativeTime operator-= (RelativeTime timeToSubtract) noexcept; - - /** Adds a number of seconds to this time. */ - RelativeTime operator+= (value_type secondsToAdd) noexcept; - - /** Subtracts a number of seconds from this time. */ - RelativeTime operator-= (value_type secondsToSubtract) noexcept; - -private: - value_type numSeconds; -}; - -//------------------------------------------------------------------------------ - -bool operator== (RelativeTime t1, RelativeTime t2) noexcept; -bool operator!= (RelativeTime t1, RelativeTime t2) noexcept; -bool operator> (RelativeTime t1, RelativeTime t2) noexcept; -bool operator< (RelativeTime t1, RelativeTime t2) noexcept; -bool operator>= (RelativeTime t1, RelativeTime t2) noexcept; -bool operator<= (RelativeTime t1, RelativeTime t2) noexcept; - -//------------------------------------------------------------------------------ - -/** Adds two RelativeTimes together. */ -RelativeTime operator+ (RelativeTime t1, RelativeTime t2) noexcept; - -/** Subtracts two RelativeTimes. */ -RelativeTime operator- (RelativeTime t1, RelativeTime t2) noexcept; - -} - -#endif diff --git a/src/ripple/beast/core/core.unity.cpp b/src/ripple/beast/core/core.unity.cpp index 4c2d4be068..9a7c99e24b 100644 --- a/src/ripple/beast/core/core.unity.cpp +++ b/src/ripple/beast/core/core.unity.cpp @@ -192,7 +192,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/core/Job.h b/src/ripple/core/Job.h index 1eb5c7f16c..937ab2cbfb 100644 --- a/src/ripple/core/Job.h +++ b/src/ripple/core/Job.h @@ -142,7 +142,7 @@ private: JobType mType; std::uint64_t mJobIndex; std::function mJob; - LoadEvent::pointer m_loadEvent; + std::shared_ptr m_loadEvent; std::string mName; clock_type::time_point m_queue_time; }; diff --git a/src/ripple/core/JobQueue.h b/src/ripple/core/JobQueue.h index c7d590e744..e27a9a0bf2 100644 --- a/src/ripple/core/JobQueue.h +++ b/src/ripple/core/JobQueue.h @@ -150,11 +150,13 @@ public: // VFALCO TODO Rename these to newLoadEventMeasurement or something similar // since they create the object. - LoadEvent::pointer getLoadEvent (JobType t, std::string const& name); + std::shared_ptr + getLoadEvent (JobType t, std::string const& name); // VFALCO TODO Why do we need two versions, one which returns a shared // pointer and the other which returns an autoptr? - LoadEvent::autoptr getLoadEventAP (JobType t, std::string const& name); + std::unique_ptr + getLoadEventAP (JobType t, std::string const& name); /** Add multiple load events. */ diff --git a/src/ripple/core/LoadEvent.h b/src/ripple/core/LoadEvent.h index 4d0c2d3ace..a393c779cd 100644 --- a/src/ripple/core/LoadEvent.h +++ b/src/ripple/core/LoadEvent.h @@ -20,8 +20,9 @@ #ifndef RIPPLE_CORE_LOADEVENT_H_INCLUDED #define RIPPLE_CORE_LOADEVENT_H_INCLUDED -#include +#include #include +#include namespace ripple { @@ -34,52 +35,54 @@ class LoadMonitor; // class LoadEvent { -public: - // VFALCO NOTE Why are these shared pointers? Wouldn't there be a - // piece of lifetime-managed calling code that can simply own - // the object? - // - // Why both kinds of containers? - // - using pointer = std::shared_ptr ; - using autoptr = std::unique_ptr ; - public: // VFALCO TODO remove the dependency on LoadMonitor. Is that possible? LoadEvent (LoadMonitor& monitor, std::string const& name, bool shouldStart); + LoadEvent(LoadEvent const&) = delete; ~LoadEvent (); - std::string const& name () const; - double getSecondsWaiting() const; - double getSecondsRunning() const; - double getSecondsTotal() const; + std::string const& + name () const; + + // The time spent waiting. + std::chrono::steady_clock::duration + waitTime() const; + + // The time spent running. + std::chrono::steady_clock::duration + runTime() const; // VFALCO TODO rename this to setName () or setLabel () void reName (std::string const& name); - // Start the measurement. The constructor calls this automatically if - // shouldStart is true. If the operation is aborted, start() can be - // called again later. - // + // Start the measurement. If already started, then + // restart, assigning the elapsed time to the "waiting" + // state. void start (); - // Stops the measurement and reports the results. The time reported is - // measured from the last call to start. - // + // Stop the measurement and report the results. The + // time reported is measured from the last call to + // start. void stop (); private: - LoadMonitor& m_loadMonitor; - bool m_isRunning; - std::string m_name; - // VFALCO TODO Replace these with chrono - beast::RelativeTime m_timeStopped; - beast::RelativeTime m_timeStarted; - double m_secondsWaiting; - double m_secondsRunning; + LoadMonitor& monitor_; + + // Represents our current state + bool running_; + + // The name associated with this event, if any. + std::string name_; + + // Represents the time we last transitioned states + std::chrono::steady_clock::time_point mark_; + + // The time we spent waiting and running respectively + std::chrono::steady_clock::duration timeWaiting_; + std::chrono::steady_clock::duration timeRunning_; }; } // ripple diff --git a/src/ripple/core/LoadMonitor.h b/src/ripple/core/LoadMonitor.h index 35a3dfebec..db7058d86e 100644 --- a/src/ripple/core/LoadMonitor.h +++ b/src/ripple/core/LoadMonitor.h @@ -37,10 +37,6 @@ public: explicit LoadMonitor (beast::Journal j); - void addCount (); - - void addLatency (int latency); - void addLoadSample (LoadEvent const& sample); void addSamples (int count, std::chrono::milliseconds latency); @@ -65,13 +61,9 @@ public: bool isOver (); private: - static std::string printElapsed (double seconds); - void update (); - using LockType = std::mutex; - using ScopedLockType = std::lock_guard ; - LockType mLock; + std::mutex mutex_; std::uint64_t mCounts; int mLatencyEvents; diff --git a/src/ripple/core/impl/JobQueue.cpp b/src/ripple/core/impl/JobQueue.cpp index b135b4f7f2..3949889d8a 100644 --- a/src/ripple/core/impl/JobQueue.cpp +++ b/src/ripple/core/impl/JobQueue.cpp @@ -189,7 +189,7 @@ JobQueue::setThreadCount (int c, bool const standaloneMode) m_workers.setNumberOfThreads (c); } -LoadEvent::pointer +std::shared_ptr JobQueue::getLoadEvent (JobType t, std::string const& name) { JobDataMap::iterator iter (m_jobData.find (t)); @@ -202,7 +202,7 @@ JobQueue::getLoadEvent (JobType t, std::string const& name) std::ref (iter-> second.load ()), name, true); } -LoadEvent::autoptr +std::unique_ptr JobQueue::getLoadEventAP (JobType t, std::string const& name) { JobDataMap::iterator iter (m_jobData.find (t)); diff --git a/src/ripple/core/impl/LoadEvent.cpp b/src/ripple/core/impl/LoadEvent.cpp index 7144f7c3b2..543227f4ee 100644 --- a/src/ripple/core/impl/LoadEvent.cpp +++ b/src/ripple/core/impl/LoadEvent.cpp @@ -21,79 +21,74 @@ #include #include #include +#include namespace ripple { -LoadEvent::LoadEvent (LoadMonitor& monitor, std::string const& name, bool shouldStart) - : m_loadMonitor (monitor) - , m_isRunning (false) - , m_name (name) - , m_timeStopped (beast::RelativeTime::fromStartup()) - , m_secondsWaiting (0) - , m_secondsRunning (0) +LoadEvent::LoadEvent ( + LoadMonitor& monitor, + std::string const& name, + bool shouldStart) + : monitor_ (monitor) + , running_ (shouldStart) + , name_ (name) + , mark_ { std::chrono::steady_clock::now() } + , timeWaiting_ {} + , timeRunning_ {} { - if (shouldStart) - start (); } LoadEvent::~LoadEvent () { - if (m_isRunning) + if (running_) stop (); } std::string const& LoadEvent::name () const { - return m_name; + return name_; } -double LoadEvent::getSecondsWaiting() const +std::chrono::steady_clock::duration +LoadEvent::waitTime() const { - return m_secondsWaiting; + return timeWaiting_; } -double LoadEvent::getSecondsRunning() const +std::chrono::steady_clock::duration +LoadEvent::runTime() const { - return m_secondsRunning; -} - -double LoadEvent::getSecondsTotal() const -{ - return m_secondsWaiting + m_secondsRunning; + return timeRunning_; } void LoadEvent::reName (std::string const& name) { - m_name = name; + name_ = name; } void LoadEvent::start () { - beast::RelativeTime const currentTime (beast::RelativeTime::fromStartup()); + auto const now = std::chrono::steady_clock::now(); - // If we already called start, this call will replace the previous one. - if (m_isRunning) - { - m_secondsWaiting += (currentTime - m_timeStarted).inSeconds(); - } - else - { - m_secondsWaiting += (currentTime - m_timeStopped).inSeconds(); - m_isRunning = true; - } - - m_timeStarted = currentTime; + // If we had already called start, this call will + // replace the previous one. Any time accumulated will + // be counted as "waiting". + timeWaiting_ += now - mark_; + mark_ = now; + running_ = true; } void LoadEvent::stop () { - assert (m_isRunning); + assert (running_); - m_timeStopped = beast::RelativeTime::fromStartup(); - m_secondsRunning += (m_timeStopped - m_timeStarted).inSeconds(); + auto const now = std::chrono::steady_clock::now(); - m_isRunning = false; - m_loadMonitor.addLoadSample (*this); + timeRunning_ += now - mark_; + mark_ = now; + running_ = false; + + monitor_.addLoadSample (*this); } } // ripple diff --git a/src/ripple/core/impl/LoadMonitor.cpp b/src/ripple/core/impl/LoadMonitor.cpp index 376c57a84b..88aa3e7ef2 100644 --- a/src/ripple/core/impl/LoadMonitor.cpp +++ b/src/ripple/core/impl/LoadMonitor.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace ripple { @@ -66,9 +67,6 @@ LoadMonitor::LoadMonitor (beast::Journal j) void LoadMonitor::update () { int now = UptimeTimer::getInstance ().getElapsedSeconds (); - - // VFALCO TODO stop returning from the middle of functions. - if (now == mLastUpdate) // current return; @@ -104,73 +102,23 @@ void LoadMonitor::update () while (mLastUpdate < now); } -void LoadMonitor::addCount () +void LoadMonitor::addLoadSample (LoadEvent const& s) { - ScopedLockType sl (mLock); + using namespace std::chrono; - update (); - ++mCounts; -} + auto const total = s.runTime() + s.waitTime(); + // Don't include "jitter" as part of the latency + auto const latency = total < 2ms ? 0ms : round(total); -void LoadMonitor::addLatency (int latency) -{ - // VFALCO NOTE Why does 1 become 0? - if (latency == 1) - latency = 0; - - ScopedLockType sl (mLock); - - update (); - - ++mLatencyEvents; - mLatencyMSAvg += latency; - mLatencyMSPeak += latency; - - // Units are quarters of a millisecond - int const latencyPeak = mLatencyEvents * latency * 4; - - if (mLatencyMSPeak < latencyPeak) - mLatencyMSPeak = latencyPeak; -} - -std::string LoadMonitor::printElapsed (double seconds) -{ - std::stringstream ss; - ss << (std::size_t (seconds * 1000 + 0.5)) << " ms"; - return ss.str(); -} - -void LoadMonitor::addLoadSample (LoadEvent const& sample) -{ - std::string const& name (sample.name()); - beast::RelativeTime const latency (sample.getSecondsTotal()); - - if (latency.inSeconds() > 0.5) + if (latency > 500ms) { - auto mj = latency.inSeconds() > 1.0 ? j_.warn() : j_.info(); - JLOG (mj) - << "Job: " << name << " ExecutionTime: " << printElapsed (sample.getSecondsRunning()) << - " WaitingTime: " << printElapsed (sample.getSecondsWaiting()); + auto mj = (latency > 1s) ? j_.warn() : j_.info(); + JLOG (mj) << "Job: " << s.name() << + " run: " << round(s.runTime()).count() << "ms" << + " wait: " << round(s.waitTime()).count() << "ms"; } - // VFALCO NOTE Why does 1 become 0? - std::size_t latencyMilliseconds (latency.inMilliseconds()); - if (latencyMilliseconds == 1) - latencyMilliseconds = 0; - - ScopedLockType sl (mLock); - - update (); - ++mCounts; - ++mLatencyEvents; - mLatencyMSAvg += latencyMilliseconds; - mLatencyMSPeak += latencyMilliseconds; - - // VFALCO NOTE Why are we multiplying by 4? - int const latencyPeak = mLatencyEvents * latencyMilliseconds * 4; - - if (mLatencyMSPeak < latencyPeak) - mLatencyMSPeak = latencyPeak; + addSamples (1, latency); } /* Add multiple samples @@ -179,7 +127,7 @@ void LoadMonitor::addLoadSample (LoadEvent const& sample) */ void LoadMonitor::addSamples (int count, std::chrono::milliseconds latency) { - ScopedLockType sl (mLock); + std::lock_guard sl (mutex_); update (); mCounts += count; @@ -207,7 +155,7 @@ bool LoadMonitor::isOverTarget (std::uint64_t avg, std::uint64_t peak) bool LoadMonitor::isOver () { - ScopedLockType sl (mLock); + std::lock_guard sl (mutex_); update (); @@ -221,7 +169,7 @@ LoadMonitor::Stats LoadMonitor::getStats () { Stats stats; - ScopedLockType sl (mLock); + std::lock_guard sl (mutex_); update (); diff --git a/src/ripple/nodestore/impl/DatabaseImp.h b/src/ripple/nodestore/impl/DatabaseImp.h index 17f0063430..52dd9ff60e 100644 --- a/src/ripple/nodestore/impl/DatabaseImp.h +++ b/src/ripple/nodestore/impl/DatabaseImp.h @@ -79,6 +79,7 @@ public: cacheTargetSize, cacheTargetSeconds) , m_readShut (false) , m_readGen (0) + , fdlimit_ (0) , m_storeCount (0) , m_fetchTotalCount (0) , m_fetchHitCount (0) diff --git a/src/ripple/nodestore/impl/codec.h b/src/ripple/nodestore/impl/codec.h index 00a59a0f24..4fe4bebb32 100644 --- a/src/ripple/nodestore/impl/codec.h +++ b/src/ripple/nodestore/impl/codec.h @@ -494,16 +494,7 @@ nodeobject_compress (void const* in, std::pair result; switch(type) { - case 0: // uncompressed - { - result.second = vn + in_size; - std::uint8_t* p = reinterpret_cast< - std::uint8_t*>(bf(result.second)); - result.first = p; - std::memcpy(p, vi.data(), vn); - std::memcpy(p + vn, in, in_size); - break; - } + // case 0 was uncompressed data; we always compress now. case 1: // lz4 { std::uint8_t* p; diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 4080a1e209..c1d6d0b194 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -103,8 +103,6 @@ private: AppBundle (beast::unit_test::suite& suite, std::unique_ptr config); - AppBundle (beast::unit_test::suite& suite, - Application* app_); ~AppBundle(); }; diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 056114d229..f5f213710c 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -151,12 +151,6 @@ public: //------------------------------------------------------------------------------ -Env::AppBundle::AppBundle(beast::unit_test::suite&, - Application* app_) - : app(app_) -{ -} - Env::AppBundle::AppBundle(beast::unit_test::suite& suite, std::unique_ptr config) {