Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Framework/Core/include/Framework/DataProcessingStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ struct DataProcessingStats {
std::atomic<size_t> statesSize = 0;

std::array<Command, MAX_CMDS> cmds = {};
/// Held by processCommandQueue, so that the queue is flushed by one thread at a time.
/// Held by processCommandQueue, so that the queue is flushed by one thread at a time,
/// and by flushChangedMetrics, which reads and resets what the flush updates.
std::mutex flushMutex;
std::array<int64_t, MAX_METRICS> metrics = {};
std::array<bool, MAX_METRICS> updated = {};
Expand Down
4 changes: 3 additions & 1 deletion Framework/Core/src/DataProcessingStats.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void DataProcessingStats::processCommandQueue(bool onlyIfFull)

// Process the commands in the order we have just computed.
for (int i = 0; i < range; ++i) {
auto& cmd = cmds[i];
auto& cmd = cmds[order[i]];
assert(cmd.id < updateInfos.size());
auto& update = updateInfos[cmd.id];
switch (cmd.op) {
Expand Down Expand Up @@ -214,6 +214,8 @@ void DataProcessingStats::processCommandQueue(bool onlyIfFull)

void DataProcessingStats::flushChangedMetrics(std::function<void(DataProcessingStats::MetricSpec const&, int64_t, int64_t)> const& callback)
{
// Pool threads flushing the command queue write the same metrics.
std::scoped_lock lock(flushMutex);
publishingInvokedTotal++;
bool publish = false;
auto currentTimestamp = getTimestamp(realTimeBase, initialTimeOffset);
Expand Down
9 changes: 8 additions & 1 deletion Framework/Core/test/test_DataProcessingStats.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEST_CASE("DataProcessingStatsOutOfOrder")
};
auto cpuTime = [](int64_t base, int64_t offset) -> int64_t {
static int count = 0;
int64_t value[] = {0, 1000, 999, 998};
int64_t value[] = {0, 1000, 999, 998, 1100, 1050};
return base + value[count++] - offset;
};
DataProcessingStats stats(realtimeTime, cpuTime, {});
Expand All @@ -210,6 +210,13 @@ TEST_CASE("DataProcessingStatsOutOfOrder")
stats.updateStats({DummyMetric, DataProcessingStats::Op::Set, 3});
stats.processCommandQueue();
REQUIRE(stats.metrics[DummyMetric] == 2);

// The Add comes first in the queue, but the Set happened before it, so the
// Set must not be dropped as older than the Add.
stats.updateStats({DummyMetric, DataProcessingStats::Op::Add, 1});
stats.updateStats({DummyMetric, DataProcessingStats::Op::Set, 7});
stats.processCommandQueue();
REQUIRE(stats.metrics[DummyMetric] == 8);
}

/// We verify that the running average is correctly computed.
Expand Down