-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbandwidth_metric.cpp
More file actions
79 lines (68 loc) · 1.48 KB
/
bandwidth_metric.cpp
File metadata and controls
79 lines (68 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "bandwidth_metric.h"
#include "logger.h"
namespace NetLib
{
namespace Metrics
{
BandwidthMetric::BandwidthMetric()
: _updateRate( 1.0f )
, _timeUntilNextUpdate( 1.0f )
, _inProgressValue( 0 )
, _currentValue( 0 )
, _maxValue( 0 )
{
}
uint32 BandwidthMetric::GetValue( const std::string& value_type ) const
{
uint32 result = 0;
if ( value_type == "MAX" )
{
result = _maxValue;
}
else if ( value_type == "CURRENT" )
{
result = _currentValue;
}
else
{
LOG_WARNING( "Unknown value type '%s' for BandwidthMetric", value_type.c_str() );
}
return result;
}
void BandwidthMetric::SetUpdateRate( float32 update_rate )
{
_updateRate = update_rate;
_timeUntilNextUpdate = _updateRate;
}
void BandwidthMetric::Update( float32 elapsed_time )
{
if ( _timeUntilNextUpdate <= elapsed_time )
{
// Update current
_currentValue = _inProgressValue;
_inProgressValue = 0;
// Update max
if ( _currentValue > _maxValue )
{
_maxValue = _currentValue;
}
_timeUntilNextUpdate = _updateRate;
}
else
{
_timeUntilNextUpdate -= elapsed_time;
}
}
void BandwidthMetric::AddValueSample( uint32 value, const std::string& sample_type )
{
_inProgressValue += value;
}
void BandwidthMetric::Reset()
{
_inProgressValue = 0;
_currentValue = 0;
_maxValue = 0;
_timeUntilNextUpdate = _updateRate;
}
} // namespace Metrics
} // namespace NetLib