AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
UpdateTime Class Reference

#include "UpdateTime.h"

Inheritance diagram for UpdateTime:
WorldUpdateTime

Public Member Functions

uint32 GetAverageUpdateTime () const
 
uint32 GetTimeWeightedAverageUpdateTime () const
 
uint32 GetMaxUpdateTime () const
 
uint32 GetMaxUpdateTimeOfCurrentTable () const
 
uint32 GetLastUpdateTime () const
 
uint32 GetDatasetSize () const
 
uint32 GetPercentile (uint8 p)
 
void UpdateWithDiff (uint32 diff)
 
void RecordUpdateTimeReset ()
 

Protected Member Functions

 UpdateTime ()
 
void SortUpdateTimeDataTable ()
 

Private Types

using DiffTableArray = std::array< uint32, AVG_DIFF_COUNT >
 

Private Attributes

DiffTableArray _updateTimeDataTable
 
uint32 _averageUpdateTime
 
uint32 _totalUpdateTime
 
uint32 _updateTimeTableIndex
 
uint32 _maxUpdateTime
 
uint32 _maxUpdateTimeOfLastTable
 
uint32 _maxUpdateTimeOfCurrentTable
 
DiffTableArray _orderedUpdateTimeDataTable
 
bool _needsReorder
 
Milliseconds _recordedTime
 

Detailed Description

Member Typedef Documentation

◆ DiffTableArray

using UpdateTime::DiffTableArray = std::array<uint32, AVG_DIFF_COUNT>
private

Constructor & Destructor Documentation

◆ UpdateTime()

UpdateTime::UpdateTime ( )
protected
30{
37
39}
uint32 _totalUpdateTime
Definition: UpdateTime.h:53
uint32 _averageUpdateTime
Definition: UpdateTime.h:52
uint32 _maxUpdateTime
Definition: UpdateTime.h:55
DiffTableArray _updateTimeDataTable
Definition: UpdateTime.h:51
uint32 _updateTimeTableIndex
Definition: UpdateTime.h:54
uint32 _maxUpdateTimeOfCurrentTable
Definition: UpdateTime.h:57
uint32 _maxUpdateTimeOfLastTable
Definition: UpdateTime.h:56

References _averageUpdateTime, _maxUpdateTime, _maxUpdateTimeOfCurrentTable, _maxUpdateTimeOfLastTable, _totalUpdateTime, _updateTimeDataTable, and _updateTimeTableIndex.

Member Function Documentation

◆ GetAverageUpdateTime()

uint32 UpdateTime::GetAverageUpdateTime ( ) const

◆ GetDatasetSize()

uint32 UpdateTime::GetDatasetSize ( ) const

◆ GetLastUpdateTime()

◆ GetMaxUpdateTime()

uint32 UpdateTime::GetMaxUpdateTime ( ) const
63{
64 return _maxUpdateTime;
65}

References _maxUpdateTime.

◆ GetMaxUpdateTimeOfCurrentTable()

uint32 UpdateTime::GetMaxUpdateTimeOfCurrentTable ( ) const

◆ GetPercentile()

uint32 UpdateTime::GetPercentile ( uint8  p)
83{
84 if (_needsReorder)
86
87 // Calculate the index of the element corresponding to the percentile
88 double index = (double(p) / 100.0) * (GetDatasetSize() - 1);
89
90 // If the index is an integer, return the value at that index
91 if (index == std::floor(index))
92 return _orderedUpdateTimeDataTable[index];
93
94 // Otherwise, perform linear interpolation
95 int lowerIndex = std::floor(index);
96 int upperIndex = std::ceil(index);
97 double fraction = index - lowerIndex;
98
99 return _orderedUpdateTimeDataTable[lowerIndex] * (1 - fraction) + _orderedUpdateTimeDataTable[upperIndex] * fraction;
100}
uint32 GetDatasetSize() const
Definition: UpdateTime.cpp:77
void SortUpdateTimeDataTable()
Definition: UpdateTime.cpp:132
bool _needsReorder
Definition: UpdateTime.h:60

References _needsReorder, _orderedUpdateTimeDataTable, GetDatasetSize(), and SortUpdateTimeDataTable().

Referenced by server_commandscript::HandleServerInfoCommand(), and WorldUpdateTime::RecordUpdateTime().

◆ GetTimeWeightedAverageUpdateTime()

uint32 UpdateTime::GetTimeWeightedAverageUpdateTime ( ) const
47{
48 uint32 sum = 0, weightsum = 0;
49
50 for (uint32 diff : _updateTimeDataTable)
51 {
52 sum += diff * diff;
53 weightsum += diff;
54 }
55
56 if (weightsum == 0)
57 return 0;
58
59 return sum / weightsum;
60}
std::uint32_t uint32
Definition: Define.h:107

References _updateTimeDataTable.

◆ RecordUpdateTimeReset()

void UpdateTime::RecordUpdateTimeReset ( )
128{
130}
Milliseconds GetTimeMS()
Definition: Timer.h:84
Milliseconds _recordedTime
Definition: UpdateTime.h:62

References _recordedTime, and GetTimeMS().

◆ SortUpdateTimeDataTable()

void UpdateTime::SortUpdateTimeDataTable ( )
protected
133{
134 if (!_needsReorder)
135 return;
136
137 auto endUpdateTable = _updateTimeDataTable.end();
139 endUpdateTable = std::next(_updateTimeDataTable.begin(), _updateTimeTableIndex);
140
141 std::copy(_updateTimeDataTable.begin(), endUpdateTable, _orderedUpdateTimeDataTable.begin());
142
143 auto endOrderedUpdateTable = _orderedUpdateTimeDataTable.end();
145 endOrderedUpdateTable = std::next(_orderedUpdateTimeDataTable.begin(), _updateTimeTableIndex);
146
147 std::sort(_orderedUpdateTimeDataTable.begin(), endOrderedUpdateTable);
148
149 _needsReorder = false;
150}

References _needsReorder, _orderedUpdateTimeDataTable, _updateTimeDataTable, and _updateTimeTableIndex.

Referenced by GetPercentile().

◆ UpdateWithDiff()

Member Data Documentation

◆ _averageUpdateTime

uint32 UpdateTime::_averageUpdateTime
private

◆ _maxUpdateTime

uint32 UpdateTime::_maxUpdateTime
private

◆ _maxUpdateTimeOfCurrentTable

uint32 UpdateTime::_maxUpdateTimeOfCurrentTable
private

◆ _maxUpdateTimeOfLastTable

uint32 UpdateTime::_maxUpdateTimeOfLastTable
private

◆ _needsReorder

bool UpdateTime::_needsReorder
private

◆ _orderedUpdateTimeDataTable

DiffTableArray UpdateTime::_orderedUpdateTimeDataTable
private

◆ _recordedTime

Milliseconds UpdateTime::_recordedTime
private

Referenced by RecordUpdateTimeReset().

◆ _totalUpdateTime

uint32 UpdateTime::_totalUpdateTime
private

Referenced by UpdateTime(), and UpdateWithDiff().

◆ _updateTimeDataTable

◆ _updateTimeTableIndex

uint32 UpdateTime::_updateTimeTableIndex
private