feat(Core/UpdateTime): Improve diff time measurement. (#18387)
* feat(Core/UpdateTime): Improve diff time measurement. * Codestyle fixes
This commit is contained in:
committed by
GitHub
parent
1768e4a633
commit
34598bfccf
@@ -19,6 +19,8 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
// create instance
|
// create instance
|
||||||
WorldUpdateTime sWorldUpdateTime;
|
WorldUpdateTime sWorldUpdateTime;
|
||||||
@@ -71,8 +73,34 @@ uint32 UpdateTime::GetLastUpdateTime() const
|
|||||||
return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1];
|
return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 UpdateTime::GetDatasetSize() const
|
||||||
|
{
|
||||||
|
return _updateTimeDataTable[_updateTimeDataTable.size() - 1] == 0 ? _updateTimeTableIndex : _orderedUpdateTimeDataTable.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 UpdateTime::GetPercentile(uint8 p)
|
||||||
|
{
|
||||||
|
if (_needsReorder)
|
||||||
|
SortUpdateTimeDataTable();
|
||||||
|
|
||||||
|
// Calculate the index of the element corresponding to the percentile
|
||||||
|
double index = (double(p) / 100.0) * (GetDatasetSize() - 1);
|
||||||
|
|
||||||
|
// If the index is an integer, return the value at that index
|
||||||
|
if (index == floor(index))
|
||||||
|
return _orderedUpdateTimeDataTable[index];
|
||||||
|
|
||||||
|
// Otherwise, perform linear interpolation
|
||||||
|
int lowerIndex = floor(index);
|
||||||
|
int upperIndex = ceil(index);
|
||||||
|
double fraction = index - lowerIndex;
|
||||||
|
|
||||||
|
return _orderedUpdateTimeDataTable[lowerIndex] * (1 - fraction) + _orderedUpdateTimeDataTable[upperIndex] * fraction;
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateTime::UpdateWithDiff(uint32 diff)
|
void UpdateTime::UpdateWithDiff(uint32 diff)
|
||||||
{
|
{
|
||||||
|
_needsReorder = true;
|
||||||
_totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff;
|
_totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff;
|
||||||
_updateTimeDataTable[_updateTimeTableIndex] = diff;
|
_updateTimeDataTable[_updateTimeTableIndex] = diff;
|
||||||
|
|
||||||
@@ -100,6 +128,26 @@ void UpdateTime::RecordUpdateTimeReset()
|
|||||||
_recordedTime = GetTimeMS();
|
_recordedTime = GetTimeMS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateTime::SortUpdateTimeDataTable()
|
||||||
|
{
|
||||||
|
if (!_needsReorder)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto endUpdateTable = _updateTimeDataTable.end();
|
||||||
|
if (!_updateTimeDataTable[_updateTimeDataTable.size() - 1])
|
||||||
|
endUpdateTable = std::next(_updateTimeDataTable.begin(), _updateTimeTableIndex);
|
||||||
|
|
||||||
|
std::copy(_updateTimeDataTable.begin(), endUpdateTable, _orderedUpdateTimeDataTable.begin());
|
||||||
|
|
||||||
|
auto endOrderedUpdateTable = _orderedUpdateTimeDataTable.end();
|
||||||
|
if (!_updateTimeDataTable[_updateTimeDataTable.size() - 1])
|
||||||
|
endOrderedUpdateTable = std::next(_orderedUpdateTimeDataTable.begin(), _updateTimeTableIndex);
|
||||||
|
|
||||||
|
std::sort(_orderedUpdateTimeDataTable.begin(), endOrderedUpdateTable);
|
||||||
|
|
||||||
|
_needsReorder = false;
|
||||||
|
}
|
||||||
|
|
||||||
void WorldUpdateTime::LoadFromConfig()
|
void WorldUpdateTime::LoadFromConfig()
|
||||||
{
|
{
|
||||||
_recordUpdateTimeInverval = Milliseconds(sConfigMgr->GetOption<uint32>("RecordUpdateTimeDiffInterval", 60000));
|
_recordUpdateTimeInverval = Milliseconds(sConfigMgr->GetOption<uint32>("RecordUpdateTimeDiffInterval", 60000));
|
||||||
@@ -117,7 +165,10 @@ void WorldUpdateTime::RecordUpdateTime(Milliseconds gameTimeMs, uint32 diff, uin
|
|||||||
{
|
{
|
||||||
if (GetMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
|
if (GetMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
|
||||||
{
|
{
|
||||||
LOG_INFO("time.update", "Update time diff: {}. Players online: {}.", GetAverageUpdateTime(), sessionCount);
|
LOG_INFO("time.update", "Last {} diffs summary with {} players online:", GetDatasetSize(), sessionCount);
|
||||||
|
LOG_INFO("time.update", " - Mean: {};", GetAverageUpdateTime());
|
||||||
|
LOG_INFO("time.update", " - Median: {};", GetPercentile(50));
|
||||||
|
LOG_INFO("time.update", " - Percentiles (95, 99, max): {}, {}, {}.", GetPercentile(95), GetPercentile(99), GetPercentile(100));
|
||||||
_lastRecordTime = gameTimeMs;
|
_lastRecordTime = gameTimeMs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public:
|
|||||||
uint32 GetMaxUpdateTime() const;
|
uint32 GetMaxUpdateTime() const;
|
||||||
uint32 GetMaxUpdateTimeOfCurrentTable() const;
|
uint32 GetMaxUpdateTimeOfCurrentTable() const;
|
||||||
uint32 GetLastUpdateTime() const;
|
uint32 GetLastUpdateTime() const;
|
||||||
|
uint32 GetDatasetSize() const;
|
||||||
|
uint32 GetPercentile(uint8 p);
|
||||||
|
|
||||||
void UpdateWithDiff(uint32 diff);
|
void UpdateWithDiff(uint32 diff);
|
||||||
|
|
||||||
@@ -43,6 +45,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
UpdateTime();
|
UpdateTime();
|
||||||
|
|
||||||
|
void SortUpdateTimeDataTable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiffTableArray _updateTimeDataTable;
|
DiffTableArray _updateTimeDataTable;
|
||||||
uint32 _averageUpdateTime;
|
uint32 _averageUpdateTime;
|
||||||
@@ -52,6 +56,9 @@ private:
|
|||||||
uint32 _maxUpdateTimeOfLastTable;
|
uint32 _maxUpdateTimeOfLastTable;
|
||||||
uint32 _maxUpdateTimeOfCurrentTable;
|
uint32 _maxUpdateTimeOfCurrentTable;
|
||||||
|
|
||||||
|
DiffTableArray _orderedUpdateTimeDataTable;
|
||||||
|
bool _needsReorder;
|
||||||
|
|
||||||
Milliseconds _recordedTime;
|
Milliseconds _recordedTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -271,7 +271,13 @@ public:
|
|||||||
|
|
||||||
handler->PSendSysMessage("Connection peak: %u.", connPeak);
|
handler->PSendSysMessage("Connection peak: %u.", connPeak);
|
||||||
handler->PSendSysMessage(LANG_UPTIME, secsToTimeString(GameTime::GetUptime().count()).c_str());
|
handler->PSendSysMessage(LANG_UPTIME, secsToTimeString(GameTime::GetUptime().count()).c_str());
|
||||||
handler->PSendSysMessage("Update time diff: %ums, average: %ums.", sWorldUpdateTime.GetLastUpdateTime(), sWorldUpdateTime.GetAverageUpdateTime());
|
handler->PSendSysMessage("Update time diff: %ums. Last %d diffs summary:", sWorldUpdateTime.GetLastUpdateTime(), sWorldUpdateTime.GetDatasetSize());
|
||||||
|
handler->PSendSysMessage("- Mean: %ums", sWorldUpdateTime.GetAverageUpdateTime());
|
||||||
|
handler->PSendSysMessage("- Median: %ums", sWorldUpdateTime.GetPercentile(50));
|
||||||
|
handler->PSendSysMessage("- Percentiles (95, 99, max): %ums, %ums, %ums",
|
||||||
|
sWorldUpdateTime.GetPercentile(95),
|
||||||
|
sWorldUpdateTime.GetPercentile(99),
|
||||||
|
sWorldUpdateTime.GetPercentile(100));
|
||||||
|
|
||||||
//! Can't use sWorld->ShutdownMsg here in case of console command
|
//! Can't use sWorld->ShutdownMsg here in case of console command
|
||||||
if (sWorld->IsShuttingDown())
|
if (sWorld->IsShuttingDown())
|
||||||
|
|||||||
Reference in New Issue
Block a user