From b69f0356ec7f957d1f99a3c3a7436b4988d4e10a Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Fri, 22 Jan 2016 13:16:38 -0500 Subject: [PATCH] Convert PathRequest to use std::chrono (RIPD-1069) --- src/ripple/app/paths/PathRequest.cpp | 52 ++++++++++++---------------- src/ripple/app/paths/PathRequest.h | 6 ++-- src/ripple/app/paths/PathRequests.h | 8 ++--- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index bc983b0d3..d1fbc2353 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -53,10 +53,10 @@ PathRequest::PathRequest ( , iLastLevel (0) , bLastSuccess (false) , iIdentifier (id) + , created_ (std::chrono::steady_clock::now()) { if (m_journal.debug) m_journal.debug << iIdentifier << " created"; - ptCreated = boost::posix_time::microsec_clock::universal_time (); } PathRequest::PathRequest ( @@ -75,45 +75,36 @@ PathRequest::PathRequest ( , iLastLevel (0) , bLastSuccess (false) , iIdentifier (id) + , created_ (std::chrono::steady_clock::now()) { if (m_journal.debug) m_journal.debug << iIdentifier << " created"; - ptCreated = boost::posix_time::microsec_clock::universal_time (); -} - -static std::string const get_milli_diff ( - boost::posix_time::ptime const& after, - boost::posix_time::ptime - const& before) -{ - return beast::lexicalCastThrow ( - static_cast ((after - before).total_milliseconds())); -} - -static std::string const get_milli_diff (boost::posix_time::ptime const& before) -{ - return get_milli_diff( - boost::posix_time::microsec_clock::universal_time(), before); } PathRequest::~PathRequest() { + using namespace std::chrono; + if (! m_journal.info) + return; + std::string fast, full; - if (!ptQuickReply.is_not_a_date_time()) + if (quick_reply_ != steady_clock::time_point{}) { fast = " fast:"; - fast += get_milli_diff (ptQuickReply, ptCreated); + fast += std::to_string( + duration_cast(quick_reply_ - created_).count()); fast += "ms"; } - if (!ptFullReply.is_not_a_date_time()) + if (full_reply_ != steady_clock::time_point{}) { full = " full:"; - full += get_milli_diff (ptFullReply, ptCreated); + full += std::to_string( + duration_cast(full_reply_ - created_).count()); full += "ms"; } - if (m_journal.info) - m_journal.info << iIdentifier << " complete:" << fast << full << - " total:" << get_milli_diff(ptCreated) << "ms"; + m_journal.info << iIdentifier << " complete:" << fast << full << + " total:" << duration_cast(steady_clock::now() - + created_).count() << "ms"; } bool PathRequest::isNew () @@ -599,6 +590,7 @@ PathRequest::findPaths (RippleLineCache::ref cache, int const level, Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) { + using namespace std::chrono; m_journal.debug << iIdentifier << " update " << (fast ? "fast" : "normal"); { @@ -670,15 +662,15 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) bLastSuccess = jvArray.size(); iLastLevel = iLevel; - if (fast && ptQuickReply.is_not_a_date_time()) + if (fast && quick_reply_ == steady_clock::time_point{}) { - ptQuickReply = boost::posix_time::microsec_clock::universal_time(); - mOwner.reportFast ((ptQuickReply-ptCreated).total_milliseconds()); + quick_reply_ = steady_clock::now(); + mOwner.reportFast(duration_cast(quick_reply_ - created_)); } - else if (! fast && ptFullReply.is_not_a_date_time()) + else if (! fast && full_reply_ == steady_clock::time_point{}) { - ptFullReply = boost::posix_time::microsec_clock::universal_time(); - mOwner.reportFull ((ptFullReply-ptCreated).total_milliseconds()); + full_reply_ = steady_clock::now(); + mOwner.reportFull(duration_cast(full_reply_ - created_)); } { diff --git a/src/ripple/app/paths/PathRequest.h b/src/ripple/app/paths/PathRequest.h index f41ca167d..3b4203ba7 100644 --- a/src/ripple/app/paths/PathRequest.h +++ b/src/ripple/app/paths/PathRequest.h @@ -144,9 +144,9 @@ private: int iIdentifier; - boost::posix_time::ptime ptCreated; - boost::posix_time::ptime ptQuickReply; - boost::posix_time::ptime ptFullReply; + std::chrono::steady_clock::time_point const created_; + std::chrono::steady_clock::time_point quick_reply_; + std::chrono::steady_clock::time_point full_reply_; static unsigned int const max_paths_ = 4; }; diff --git a/src/ripple/app/paths/PathRequests.h b/src/ripple/app/paths/PathRequests.h index 8ed210a2d..57c91bdd2 100644 --- a/src/ripple/app/paths/PathRequests.h +++ b/src/ripple/app/paths/PathRequests.h @@ -60,14 +60,14 @@ public: std::shared_ptr const& inLedger, Json::Value const& request); - void reportFast (int milliseconds) + void reportFast (std::chrono::milliseconds ms) { - mFast.notify (static_cast < beast::insight::Event::value_type> (milliseconds)); + mFast.notify (ms); } - void reportFull (int milliseconds) + void reportFull (std::chrono::milliseconds ms) { - mFull.notify (static_cast < beast::insight::Event::value_type> (milliseconds)); + mFull.notify (ms); } private: