Reduce coupling to date.h by calling C++17 chrono functions

This commit is contained in:
Howard Hinnant
2021-02-18 14:09:49 -05:00
committed by manojsdoshi
parent 64e4a89470
commit 9932a19139
15 changed files with 34 additions and 48 deletions

View File

@@ -25,8 +25,6 @@
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <date/date.h>
namespace ripple {
namespace {

View File

@@ -76,6 +76,8 @@
#include <boost/asio/steady_timer.hpp>
#include <boost/system/error_code.hpp>
#include <date/date.h>
#include <condition_variable>
#include <cstring>
#include <iostream>
@@ -123,7 +125,7 @@ private:
operator()(Duration const& elapsed)
{
using namespace std::chrono;
auto const lastSample = date::ceil<milliseconds>(elapsed);
auto const lastSample = ceil<milliseconds>(elapsed);
lastSample_ = lastSample;

View File

@@ -2589,8 +2589,8 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters)
info[jss::server_state] = strOperatingMode(admin);
info[jss::time] = to_string(date::floor<std::chrono::microseconds>(
std::chrono::system_clock::now()));
info[jss::time] = to_string(
floor<std::chrono::microseconds>(std::chrono::system_clock::now()));
if (needNetworkLedger_)
info[jss::network_ledger] = "waiting";

View File

@@ -32,8 +32,6 @@
#include <ripple/protocol/messages.h>
#include <boost/regex.hpp>
#include <date/date.h>
#include <cmath>
#include <mutex>
#include <numeric>

View File

@@ -238,7 +238,7 @@ public:
auto last = getLastMsgTime();
if (last.time_since_epoch().count() != 0)
result["last_message_arrival_time"] =
to_string(date::floor<std::chrono::microseconds>(last));
to_string(floor<std::chrono::microseconds>(last));
return result;
}

View File

@@ -315,8 +315,8 @@ public:
result["is_writer"] = writing_.load();
auto last = getLastPublish();
if (last.time_since_epoch().count() != 0)
result["last_publish_time"] = to_string(
date::floor<std::chrono::microseconds>(getLastPublish()));
result["last_publish_time"] =
to_string(floor<std::chrono::microseconds>(getLastPublish()));
return result;
}

View File

@@ -288,7 +288,7 @@ PerfLogImp::report()
lastLog_ = present;
Json::Value report(Json::objectValue);
report[jss::time] = to_string(date::floor<microseconds>(present));
report[jss::time] = to_string(floor<microseconds>(present));
{
std::lock_guard lock{counters_.jobsMutex_};
report[jss::workers] =

View File

@@ -22,8 +22,6 @@
#include <ripple/beast/insight/EventImpl.h>
#include <date/date.h>
#include <chrono>
#include <memory>
@@ -67,7 +65,7 @@ public:
{
using namespace std::chrono;
if (m_impl)
m_impl->notify(date::ceil<value_type>(value));
m_impl->notify(ceil<value_type>(value));
}
std::shared_ptr<EventImpl> const&

View File

@@ -417,14 +417,14 @@ JobQueue::processTask(int instance)
// The amount of time that the job was in the queue
auto const q_time =
date::ceil<microseconds>(start_time - job.queue_time());
ceil<microseconds>(start_time - job.queue_time());
perfLog_.jobStart(type, q_time, start_time, instance);
job.doJob();
// The amount of time it took to execute the job
auto const x_time =
date::ceil<microseconds>(Job::clock_type::now() - start_time);
ceil<microseconds>(Job::clock_type::now() - start_time);
if (x_time >= 10ms || q_time >= 10ms)
{

View File

@@ -21,8 +21,6 @@
#include <ripple/basics/UptimeClock.h>
#include <ripple/core/LoadMonitor.h>
#include <date/date.h>
namespace ripple {
/*
@@ -106,15 +104,14 @@ LoadMonitor::addLoadSample(LoadEvent const& s)
auto const total = s.runTime() + s.waitTime();
// Don't include "jitter" as part of the latency
auto const latency = total < 2ms ? 0ms : date::round<milliseconds>(total);
auto const latency = total < 2ms ? 0ms : round<milliseconds>(total);
if (latency > 500ms)
{
auto mj = (latency > 1s) ? j_.warn() : j_.info();
JLOG(mj) << "Job: " << s.name()
<< " run: " << date::round<milliseconds>(s.runTime()).count()
<< "ms"
<< " wait: " << date::round<milliseconds>(s.waitTime()).count()
<< " run: " << round<milliseconds>(s.runTime()).count() << "ms"
<< " wait: " << round<milliseconds>(s.waitTime()).count()
<< "ms";
}

View File

@@ -277,7 +277,7 @@ verifyHandshake(
auto const offset = calculateOffset(netTime, ourTime);
if (date::abs(offset) > tolerance)
if (abs(offset) > tolerance)
throw std::runtime_error("Peer clock is too far off");
}

View File

@@ -32,6 +32,7 @@
#include <boost/asio.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <chrono>
#include <date/date.h>
#include <test/jtx.h>
#include <test/jtx/TrustedPublisherServer.h>
#include <test/unit_test/FileDirGuard.h>

View File

@@ -40,7 +40,7 @@ class ByzantineFailureSim_test : public beast::unit_test::suite
ConsensusParms const parms{};
SimDuration const delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
PeerGroup a = sim.createGroup(1);
PeerGroup b = sim.createGroup(1);
PeerGroup c = sim.createGroup(1);

View File

@@ -151,7 +151,7 @@ public:
// Connected trust and network graphs with single fixed delay
peers.trustAndConnect(
peers, date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
peers, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
// everyone submits their own ID as a TX
for (Peer* p : peers)
@@ -199,11 +199,10 @@ public:
// Fast and slow network connections
fast.connect(
fast, date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
fast, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
slow.connect(
network,
date::round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
network, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
// All peers submit their own ID as a transaction
for (Peer* peer : network)
@@ -256,12 +255,11 @@ public:
// Fast and slow network connections
fast.connect(
fast,
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
fast, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
slow.connect(
network,
date::round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
for (Peer* peer : slow)
peer->runAsValidator = isParticipant;
@@ -384,7 +382,7 @@ public:
network.trust(network);
network.connect(
network, date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
network, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
// Run consensus without skew until we have a short close time
// resolution
@@ -454,7 +452,7 @@ public:
PeerGroup network = minority + majority;
SimDuration delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
minority.trustAndConnect(minority + majorityA, delay);
majority.trustAndConnect(majority, delay);
@@ -559,8 +557,7 @@ public:
PeerGroup network = loner + clique;
network.connect(
network,
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
network, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
// initial round to set prior state
sim.run(1);
@@ -609,10 +606,9 @@ public:
network.trust(network);
// Fast and slow network connections
fast.connect(
fast, date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
fast.connect(fast, round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
slow.connect(
network, date::round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
network, round<milliseconds>(1.1 * parms.ledgerGRANULARITY));
// Run to the ledger *prior* to decreasing the resolution
sim.run(increaseLedgerTimeResolutionEvery - 2);
@@ -712,7 +708,7 @@ public:
PeerGroup network = a + b;
SimDuration delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
a.trustAndConnect(a, delay);
b.trustAndConnect(b, delay);
@@ -758,8 +754,7 @@ public:
validators.trust(validators);
center.trust(validators);
SimDuration delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
SimDuration delay = round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
validators.connect(center, delay);
center[0]->runAsValidator = false;
@@ -879,10 +874,8 @@ public:
PeerGroup groupNotFastC = groupABD + groupCsplit;
PeerGroup network = groupABD + groupCsplit + groupCfast;
SimDuration delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
SimDuration fDelay =
date::round<milliseconds>(0.1 * parms.ledgerGRANULARITY);
SimDuration delay = round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
SimDuration fDelay = round<milliseconds>(0.1 * parms.ledgerGRANULARITY);
network.trust(network);
// C must have a shorter delay to see all the validations before the
@@ -992,8 +985,7 @@ public:
ConsensusParms const parms{};
Sim sim;
SimDuration delay =
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
SimDuration delay = round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
PeerGroup behind = sim.createGroup(3);
PeerGroup ahead = sim.createGroup(2);

View File

@@ -59,7 +59,7 @@ class ScaleFreeSim_test : public beast::unit_test::suite
// nodes with a trust line in either direction are network-connected
network.connectFromTrust(
date::round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
// Initialize collectors to track statistics to report
TxCollector txCollector;