Skip to content

Commit

Permalink
smoothing of long-term statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 15, 2024
1 parent aad96aa commit 0dbbef9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 13 additions & 5 deletions source/EngineGpuKernels/StatisticsService.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void _StatisticsService::addDataPoint(StatisticsHistory& history, TimelineStatis
historyData.clear();
}

if (!_lastRawStatistics || historyData.empty() || toDouble(timestep) - historyData.back().time > _longtermTimestepDelta) {

if (!_lastRawStatistics || historyData.empty() || toDouble(timestep) - historyData.back().time > _longtermTimestepDelta / 100 * (_numDataPoints + 1)) {
auto newDataPoint = [&] {
if (!_lastRawStatistics && !historyData.empty()) {

Expand All @@ -32,15 +31,24 @@ void _StatisticsService::addDataPoint(StatisticsHistory& history, TimelineStatis
}
}();

_lastRawStatistics = newRawStatistics;
_lastTimestep = timestep;
_accumulatedDataPoint = _accumulatedDataPoint.has_value() ? *_accumulatedDataPoint + newDataPoint : newDataPoint;
++_numDataPoints;
}

if (_accumulatedDataPoint.has_value() && (historyData.empty() || toDouble(timestep) - historyData.back().time > _longtermTimestepDelta)) {
auto newDataPoint = *_accumulatedDataPoint / _numDataPoints;
_numDataPoints = 0;
_accumulatedDataPoint.reset();

//remove last entry if timestep has not changed
if (!historyData.empty() && abs(historyData.back().time - toDouble(timestep)) < NEAR_ZERO) {
historyData.pop_back();
}
historyData.emplace_back(newDataPoint);

_lastRawStatistics = newRawStatistics;
_lastTimestep = timestep;

//compress history after MaxSamples
if (historyData.size() > MaxSamples) {
std::vector<DataPointCollection> newData;
newData.reserve(historyData.size() / 2);
Expand Down
3 changes: 3 additions & 0 deletions source/EngineGpuKernels/StatisticsService.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ private:

double _longtermTimestepDelta = DefaultTimeStepDelta;

int _numDataPoints = 0;
std::optional<DataPointCollection> _accumulatedDataPoint;

std::optional<TimelineStatistics> _lastRawStatistics;
std::optional<uint64_t> _lastTimestep;
};

0 comments on commit 0dbbef9

Please sign in to comment.