diff --git a/groups/bal/balm/balm_metricsmanager.cpp b/groups/bal/balm/balm_metricsmanager.cpp index 435e8d5d82..2dc2ca924b 100644 --- a/groups/bal/balm/balm_metricsmanager.cpp +++ b/groups/bal/balm/balm_metricsmanager.cpp @@ -618,8 +618,8 @@ void MetricsManager_PublicationHelper::publish( SampleCache sampleCache; // publisher -> sample (samples point to // records in the 'recordBuffer') - bdlt::DatetimeTz timeStamp(bdlt::CurrentTime::utc(), 0); bsls::TimeInterval now = bdlt::CurrentTime::now(); + bdlt::DatetimeTz timeStamp(bdlt::EpochUtil::epoch() + now, 0); // Lock the publication lock *then* lock the other object properties. @@ -1096,8 +1096,9 @@ void MetricsManager::collectSampleImp(MetricSample *sample, int numCategories, bool resetFlag) { - bdlt::DatetimeTz timeStamp(bdlt::CurrentTime::utc(), 0); + bsls::TimeInterval now = bdlt::CurrentTime::now(); + bdlt::DatetimeTz timeStamp(bdlt::EpochUtil::epoch() + now, 0); sample->setTimeStamp(timeStamp); diff --git a/groups/bal/balm/balm_metricsmanager.t.cpp b/groups/bal/balm/balm_metricsmanager.t.cpp index 3b2f393b08..b1b40bbb33 100644 --- a/groups/bal/balm/balm_metricsmanager.t.cpp +++ b/groups/bal/balm/balm_metricsmanager.t.cpp @@ -246,9 +246,9 @@ bool recordLess(const balm::MetricRecord& lhs, const balm::MetricRecord& rhs) /// Return `true` if the specified `localTime` is within the specified /// `windowMs` (milliseconds) of the specified `utcExpectedTime`. -bool withinWindow(const bdlt::DatetimeTz& localTime, - const bdlt::Datetime& utcExpectedTime, - int windowMs) +bool withinWindow(const bdlt::DatetimeTz& localTime, + const bdlt::Datetime& utcExpectedTime, + bsls::Types::Int64 windowMs) { bdlt::Datetime gmtTime = localTime.utcDatetime(); bdlt::Datetime begin = utcExpectedTime; @@ -256,7 +256,7 @@ bool withinWindow(const bdlt::DatetimeTz& localTime, begin.addMilliseconds(-windowMs); end.addMilliseconds(windowMs); - bool withinWindow = begin < gmtTime && end > gmtTime; + bool withinWindow = begin <= gmtTime && end >= gmtTime; if (!withinWindow) { P_(localTime); P_(gmtTime); P(utcExpectedTime); } @@ -283,11 +283,11 @@ const balm::Category *firstCategory(const balm::MetricSampleGroup& group) /// `windowMs` (milliseconds) of the specified `expectedValue`. bool withinWindow(const bsls::TimeInterval& value, const bsls::TimeInterval& expectedValue, - int windowMs) + bsls::Types::Int64 windowMs) { bsls::TimeInterval window(0, windowMs * NANOSECS_PER_MILLISEC); - bool withinWindow = (expectedValue - window) < value - && (expectedValue + window) > value; + bool withinWindow = (expectedValue - window) <= value + && (expectedValue + window) >= value; if (!withinWindow) { P_(windowMs); P_(expectedValue); P(value); @@ -983,6 +983,7 @@ void ConcurrencyTest::execute() Obj *mX = d_manager_p; const Obj *MX = mX; Registry& registry = mX->metricRegistry(); for (int i = 0; i < 10; ++i) { + bdlt::Datetime iterationStartTime = bdlt::CurrentTime::utc(); // Create 2 strings unique for this iteration. @@ -1085,15 +1086,19 @@ void ConcurrencyTest::execute() allCategories.data(), static_cast(allCategories.size())); - bdlt::Datetime now = bdlt::CurrentTime::utc(); - ASSERT(!s1Cb.resetFlag()); ASSERT(!s2Cb.resetFlag()); ASSERT(1 <= aCb.invocations()); ASSERT(1 <= bCb.invocations()); ASSERT(1 == s1Cb.invocations()); ASSERT(1 == s2Cb.invocations()); - ASSERT(withinWindow(sample.timeStamp(), now, 100)); + + bdlt::Datetime now = bdlt::CurrentTime::utc(); + bsls::Types::Int64 milliseconds = + 1 + (now - iterationStartTime).totalMilliseconds(); + + ASSERTV(sample.timeStamp(), now, iterationStartTime, milliseconds, + withinWindow(sample.timeStamp(), now, milliseconds)); // Test `publish`. mX->publish(allCategories.data(), diff --git a/groups/bal/balm/balm_publicationscheduler.t.cpp b/groups/bal/balm/balm_publicationscheduler.t.cpp index 095c2bc082..4a121bcd8c 100644 --- a/groups/bal/balm/balm_publicationscheduler.t.cpp +++ b/groups/bal/balm/balm_publicationscheduler.t.cpp @@ -329,11 +329,11 @@ void microSleep(int microSeconds, int seconds) /// `windowMs` (milliseconds) of the specified `expectedValue`. bool withinWindow(const bsls::TimeInterval& value, const bsls::TimeInterval& expectedValue, - int windowMs) + bsls::Types::Int64 windowMs) { bsls::TimeInterval window(0, windowMs * NANOSECS_PER_MILLISEC); - bool withinWindow = (expectedValue - window) < value - && (expectedValue + window) > value; + bool withinWindow = (expectedValue - window) <= value + && (expectedValue + window) >= value; if (!withinWindow) { P_(windowMs); P_(expectedValue); P(value);