Skip to content

Commit

Permalink
Adjust windows (#5046)
Browse files Browse the repository at this point in the history
* Adjust windows

* Apply code review comments, fix test failure
  • Loading branch information
mversche authored and GitHub Enterprise committed Oct 24, 2024
1 parent f5157ca commit 0cb390f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions groups/bal/balm/balm_metricsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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);

Expand Down
25 changes: 15 additions & 10 deletions groups/bal/balm/balm_metricsmanager.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,17 @@ 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;
bdlt::Datetime end = utcExpectedTime;
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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -1085,15 +1086,19 @@ void ConcurrencyTest::execute()
allCategories.data(),
static_cast<int>(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(),
Expand Down
6 changes: 3 additions & 3 deletions groups/bal/balm/balm_publicationscheduler.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0cb390f

Please sign in to comment.