@@ -86,12 +86,23 @@ const ID_PRIME = "PRIME";
86
86
const TID_PRIME = "TPRIME" ;
87
87
88
88
// Bitrate calculations.
89
- // First packet has been sent.
90
- var bool bTransfersStarted ;
91
89
var float StartTimeSeconds ;
92
90
var float StopTimeSeconds ;
93
91
var int BytesOut ; // TODO: does this overflow?
94
92
var int BytesIn ; // TODO: does this overflow?
93
+ var int LastBytesOut ;
94
+ var int LastBytesIn ;
95
+ var array <float > BytesOutSamples ;
96
+ var array <float > BytesInSamples ;
97
+ var float ByteRateOut ;
98
+ var float ByteRateIn ;
99
+ var int BytesOutSamplesIndex ;
100
+ var int BytesInSamplesIndex ;
101
+ const NUM_SAMPLES = 5 ;
102
+ var float MaxByteRateOut ;
103
+ var float MaxByteRateIn ;
104
+ var float AvgByteRateOut ;
105
+ var float AvgByteRateIn ;
95
106
96
107
var delegate <OnRandPrimeReceived > RandPrimeDelegate ;
97
108
delegate OnRandPrimeReceived (const out array <byte> P );
@@ -100,22 +111,87 @@ simulated event PreBeginPlay()
100
111
{
101
112
super .PreBeginPlay ();
102
113
114
+ SampleTransferRates ();
103
115
SetTimer (2.0 , True , NameOf (LogTransferRates ));
104
116
}
105
117
106
- simulated final function LogTransferRates ()
118
+ simulated final function SampleTransferRates ()
119
+ {
120
+ StartTimeSeconds = WorldInfo .RealTimeSeconds ;
121
+ SetTimer (0.2 , False , NameOf (StopTransferRateSample ));
122
+ }
123
+
124
+ simulated final function StopTransferRateSample ()
107
125
{
108
126
local float TimeSpent ;
109
- local float ByteRateOut ;
110
- local float ByteRateIn ;
127
+ local float CurrentByteRateOut ;
128
+ local float CurrentByteRateIn ;
129
+ local float CurrentBytesOut ;
130
+ local float CurrentBytesIn ;
131
+ local int i ;
111
132
112
133
StopTimeSeconds = WorldInfo .RealTimeSeconds ;
113
134
TimeSpent = StopTimeSeconds - StartTimeSeconds ;
114
- ByteRateOut = BytesOut / TimeSpent ;
115
- ByteRateIn = BytesIn / TimeSpent ;
116
135
117
- `fclog ("BytesOut :" @ ByteRateOut @ "B/s" @ ByteRateOut * BpsToMbps @ "Mb/s" );
118
- `fclog ("BytesIn :" @ ByteRateIn @ "B/s" @ ByteRateIn * BpsToMbps @ "Mb/s" );
136
+ CurrentBytesOut = BytesOut - LastBytesOut ;
137
+ CurrentBytesIn = BytesIn - LastBytesIn ;
138
+
139
+ CurrentByteRateOut = CurrentBytesOut / TimeSpent ;
140
+ CurrentByteRateIn = CurrentBytesIn / TimeSpent ;
141
+
142
+ // `fclog("CurrentByteRateOut=" $ CurrentByteRateOut);
143
+ // `fclog("CurrentByteRateIn=" $ CurrentByteRateIn);
144
+
145
+ BytesOutSamplesIndex = (BytesOutSamplesIndex + 1 ) % NUM_SAMPLES ;
146
+ BytesInSamplesIndex = (BytesInSamplesIndex + 1 ) % NUM_SAMPLES ;
147
+
148
+ BytesOutSamples [BytesOutSamplesIndex ] = CurrentByteRateOut ;
149
+ BytesInSamples [BytesInSamplesIndex ] = CurrentByteRateIn ;
150
+
151
+ LastBytesOut = BytesOut ;
152
+ LastBytesIn = BytesIn ;
153
+
154
+ for (i = 0 ; i < NUM_SAMPLES ; ++i )
155
+ {
156
+ ByteRateOut += BytesOutSamples [i ];
157
+ ByteRateIn += BytesInSamples [i ];
158
+ }
159
+
160
+ ByteRateOut /= NUM_SAMPLES ;
161
+ ByteRateIn /= NUM_SAMPLES ;
162
+
163
+ MaxByteRateOut = Max (MaxByteRateOut , ByteRateOut );
164
+ MaxByteRateIn = Max (MaxByteRateIn , ByteRateIn );
165
+
166
+ if (ByteRateOut > 0 )
167
+ {
168
+ AvgByteRateOut += ByteRateOut ;
169
+ AvgByteRateOut /= 2 ;
170
+ }
171
+
172
+ if (ByteRateIn > 0 )
173
+ {
174
+ AvgByteRateIn += ByteRateIn ;
175
+ AvgByteRateIn /= 2 ;
176
+ }
177
+
178
+ SampleTransferRates ();
179
+ }
180
+
181
+ simulated final function LogTransferRates ()
182
+ {
183
+ `fclog (
184
+ "BytesOut :" @ ByteRateOut @ "B/s"
185
+ @ ByteRateOut * BpsToMbps @ "Mb/s"
186
+ @ AvgByteRateOut * BpsToMbps @ "(avg )"
187
+ @ MaxByteRateOut * BpsToMbps @ " (max )"
188
+ );
189
+ `fclog(
190
+ " BytesIn :" @ ByteRateIn @ " B /s "
191
+ @ ByteRateIn * BpsToMbps @ " Mb /s "
192
+ @ AvgByteRateIn * BpsToMbps @ " (avg )"
193
+ @ MaxByteRateIn * BpsToMbps @ " (max )"
194
+ );
119
195
}
120
196
121
197
simulated event Tick(float DeltaTime)
@@ -317,12 +393,6 @@ final simulated function RandPrime(int Size)
317
393
318
394
final function SendTextEx(coerce string Str)
319
395
{
320
- if (!bTransfersStarted)
321
- {
322
- bTransfersStarted = True;
323
- StartTimeSeconds = WorldInfo.RealTimeSeconds;
324
- }
325
-
326
396
// TODO: is this right? UScript strings are UTF-16 (UCS-2).
327
397
BytesOut += Len(Str) * 2;
328
398
@@ -386,6 +456,4 @@ DefaultProperties
386
456
OutLineMode=LMODE_UNIX
387
457
388
458
TickGroup=TG_DuringAsyncWork
389
-
390
- bTransfersStarted=False
391
459
}
0 commit comments