mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:49:27 +02:00
Merge pull request #14163 from Atlante45/fix/bw-recorder
Fix crash with BandwidthRecorder
This commit is contained in:
commit
3c79a79487
5 changed files with 42 additions and 58 deletions
|
@ -52,7 +52,6 @@
|
||||||
#include <RunningMarker.h>
|
#include <RunningMarker.h>
|
||||||
|
|
||||||
#include "avatar/MyAvatar.h"
|
#include "avatar/MyAvatar.h"
|
||||||
#include "BandwidthRecorder.h"
|
|
||||||
#include "FancyCamera.h"
|
#include "FancyCamera.h"
|
||||||
#include "ConnectionMonitor.h"
|
#include "ConnectionMonitor.h"
|
||||||
#include "CursorManager.h"
|
#include "CursorManager.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
BandwidthRecorder::Channel::Channel() {
|
BandwidthRecorder::Channel::Channel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
|
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() const {
|
||||||
float averageTimeBetweenPackets = _input.getEventDeltaAverage();
|
float averageTimeBetweenPackets = _input.getEventDeltaAverage();
|
||||||
if (averageTimeBetweenPackets > 0.0f) {
|
if (averageTimeBetweenPackets > 0.0f) {
|
||||||
return (1.0f / averageTimeBetweenPackets);
|
return (1.0f / averageTimeBetweenPackets);
|
||||||
|
@ -26,7 +26,7 @@ float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
|
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() const {
|
||||||
float averageTimeBetweenPackets = _output.getEventDeltaAverage();
|
float averageTimeBetweenPackets = _output.getEventDeltaAverage();
|
||||||
if (averageTimeBetweenPackets > 0.0f) {
|
if (averageTimeBetweenPackets > 0.0f) {
|
||||||
return (1.0f / averageTimeBetweenPackets);
|
return (1.0f / averageTimeBetweenPackets);
|
||||||
|
@ -34,11 +34,11 @@ float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() {
|
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() const {
|
||||||
return (_input.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
return (_input.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() {
|
float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() const {
|
||||||
return (_output.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
return (_output.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,35 +77,35 @@ void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int s
|
||||||
_channels[channelType]->updateOutputAverage(sample);
|
_channels[channelType]->updateOutputAverage(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) {
|
float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) const {
|
||||||
if (! _channels[channelType]) {
|
if (! _channels[channelType]) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
return _channels[channelType]->getAverageInputPacketsPerSecond();
|
return _channels[channelType]->getAverageInputPacketsPerSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) {
|
float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) const {
|
||||||
if (! _channels[channelType]) {
|
if (! _channels[channelType]) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
return _channels[channelType]->getAverageOutputPacketsPerSecond();
|
return _channels[channelType]->getAverageOutputPacketsPerSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) {
|
float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) const {
|
||||||
if (! _channels[channelType]) {
|
if (! _channels[channelType]) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
return _channels[channelType]->getAverageInputKilobitsPerSecond();
|
return _channels[channelType]->getAverageInputKilobitsPerSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) {
|
float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) const {
|
||||||
if (! _channels[channelType]) {
|
if (! _channels[channelType]) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
return _channels[channelType]->getAverageOutputKilobitsPerSecond();
|
return _channels[channelType]->getAverageOutputKilobitsPerSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() {
|
float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() const {
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||||
if (_channels[i]) {
|
if (_channels[i]) {
|
||||||
|
@ -115,7 +115,7 @@ float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() {
|
float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() const {
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||||
if (_channels[i]) {
|
if (_channels[i]) {
|
||||||
|
@ -125,7 +125,7 @@ float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){
|
float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond() const {
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||||
if (_channels[i]) {
|
if (_channels[i]) {
|
||||||
|
@ -135,7 +135,7 @@ float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){
|
float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond() const {
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||||
if (_channels[i]) {
|
if (_channels[i]) {
|
||||||
|
@ -145,7 +145,7 @@ float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
|
float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() const {
|
||||||
static qint64 lastCalculated = 0;
|
static qint64 lastCalculated = 0;
|
||||||
static float cachedValue = 0.0f;
|
static float cachedValue = 0.0f;
|
||||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
@ -156,7 +156,7 @@ float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
|
float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() const {
|
||||||
static qint64 lastCalculated = 0;
|
static qint64 lastCalculated = 0;
|
||||||
static float cachedValue = 0.0f;
|
static float cachedValue = 0.0f;
|
||||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
@ -167,7 +167,7 @@ float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
|
float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() const {
|
||||||
static qint64 lastCalculated = 0;
|
static qint64 lastCalculated = 0;
|
||||||
static float cachedValue = 0.0f;
|
static float cachedValue = 0.0f;
|
||||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
@ -178,7 +178,7 @@ float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() {
|
float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() const {
|
||||||
static qint64 lastCalculated = 0;
|
static qint64 lastCalculated = 0;
|
||||||
static float cachedValue = 0.0f;
|
static float cachedValue = 0.0f;
|
||||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
|
|
@ -32,33 +32,33 @@ public:
|
||||||
class Channel {
|
class Channel {
|
||||||
public:
|
public:
|
||||||
Channel();
|
Channel();
|
||||||
float getAverageInputPacketsPerSecond();
|
float getAverageInputPacketsPerSecond() const;
|
||||||
float getAverageOutputPacketsPerSecond();
|
float getAverageOutputPacketsPerSecond() const;
|
||||||
float getAverageInputKilobitsPerSecond();
|
float getAverageInputKilobitsPerSecond() const;
|
||||||
float getAverageOutputKilobitsPerSecond();
|
float getAverageOutputKilobitsPerSecond() const;
|
||||||
|
|
||||||
void updateInputAverage(const float sample);
|
void updateInputAverage(const float sample);
|
||||||
void updateOutputAverage(const float sample);
|
void updateOutputAverage(const float sample);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SimpleMovingAverage _input = SimpleMovingAverage();
|
SimpleMovingAverage _input;
|
||||||
SimpleMovingAverage _output = SimpleMovingAverage();
|
SimpleMovingAverage _output;
|
||||||
};
|
};
|
||||||
|
|
||||||
float getAverageInputPacketsPerSecond(const quint8 channelType);
|
float getAverageInputPacketsPerSecond(const quint8 channelType) const;
|
||||||
float getAverageOutputPacketsPerSecond(const quint8 channelType);
|
float getAverageOutputPacketsPerSecond(const quint8 channelType) const;
|
||||||
float getAverageInputKilobitsPerSecond(const quint8 channelType);
|
float getAverageInputKilobitsPerSecond(const quint8 channelType) const;
|
||||||
float getAverageOutputKilobitsPerSecond(const quint8 channelType);
|
float getAverageOutputKilobitsPerSecond(const quint8 channelType) const;
|
||||||
|
|
||||||
float getTotalAverageInputPacketsPerSecond();
|
float getTotalAverageInputPacketsPerSecond() const;
|
||||||
float getTotalAverageOutputPacketsPerSecond();
|
float getTotalAverageOutputPacketsPerSecond() const;
|
||||||
float getTotalAverageInputKilobitsPerSecond();
|
float getTotalAverageInputKilobitsPerSecond() const;
|
||||||
float getTotalAverageOutputKilobitsPerSecond();
|
float getTotalAverageOutputKilobitsPerSecond() const;
|
||||||
|
|
||||||
float getCachedTotalAverageInputPacketsPerSecond();
|
float getCachedTotalAverageInputPacketsPerSecond() const;
|
||||||
float getCachedTotalAverageOutputPacketsPerSecond();
|
float getCachedTotalAverageOutputPacketsPerSecond() const;
|
||||||
float getCachedTotalAverageInputKilobitsPerSecond();
|
float getCachedTotalAverageInputKilobitsPerSecond() const;
|
||||||
float getCachedTotalAverageOutputKilobitsPerSecond();
|
float getCachedTotalAverageOutputKilobitsPerSecond() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
|
||||||
#include "BandwidthRecorder.h"
|
|
||||||
#include "NetworkLogging.h"
|
#include "NetworkLogging.h"
|
||||||
#include <Trace.h>
|
#include <Trace.h>
|
||||||
#include "NodeType.h"
|
#include "NodeType.h"
|
||||||
|
@ -230,35 +229,18 @@ QDebug operator<<(QDebug debug, const NetworkPeer &peer) {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME this is a temporary implementation to determine if this is the right approach.
|
|
||||||
// If so, migrate the BandwidthRecorder into the NetworkPeer class
|
|
||||||
using BandwidthRecorderPtr = QSharedPointer<BandwidthRecorder>;
|
|
||||||
static QHash<QUuid, BandwidthRecorderPtr> PEER_BANDWIDTH;
|
|
||||||
|
|
||||||
BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) {
|
|
||||||
if (!PEER_BANDWIDTH.count(uuid)) {
|
|
||||||
PEER_BANDWIDTH.insert(uuid, QSharedPointer<BandwidthRecorder>::create());
|
|
||||||
}
|
|
||||||
return *PEER_BANDWIDTH[uuid].data();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkPeer::recordBytesSent(int count) const {
|
void NetworkPeer::recordBytesSent(int count) const {
|
||||||
auto& bw = getBandwidthRecorder(_uuid);
|
_bandwidthRecorder.updateOutboundData(0, count);
|
||||||
bw.updateOutboundData(0, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPeer::recordBytesReceived(int count) const {
|
void NetworkPeer::recordBytesReceived(int count) const {
|
||||||
auto& bw = getBandwidthRecorder(_uuid);
|
_bandwidthRecorder.updateInboundData(0, count);
|
||||||
bw.updateInboundData(0, count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float NetworkPeer::getOutboundBandwidth() const {
|
float NetworkPeer::getOutboundBandwidth() const {
|
||||||
auto& bw = getBandwidthRecorder(_uuid);
|
return _bandwidthRecorder.getAverageOutputKilobitsPerSecond(0);
|
||||||
return bw.getAverageOutputKilobitsPerSecond(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float NetworkPeer::getInboundBandwidth() const {
|
float NetworkPeer::getInboundBandwidth() const {
|
||||||
auto& bw = getBandwidthRecorder(_uuid);
|
return _bandwidthRecorder.getAverageInputKilobitsPerSecond(0);
|
||||||
return bw.getAverageInputKilobitsPerSecond(0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QUuid>
|
#include <QtCore/QUuid>
|
||||||
|
|
||||||
#include "UUID.h"
|
#include "BandwidthRecorder.h"
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
|
#include "UUID.h"
|
||||||
|
|
||||||
const QString ICE_SERVER_HOSTNAME = "localhost";
|
const QString ICE_SERVER_HOSTNAME = "localhost";
|
||||||
const quint16 ICE_SERVER_DEFAULT_PORT = 7337;
|
const quint16 ICE_SERVER_DEFAULT_PORT = 7337;
|
||||||
|
@ -113,6 +114,8 @@ protected:
|
||||||
HifiSockAddr _symmetricSocket;
|
HifiSockAddr _symmetricSocket;
|
||||||
HifiSockAddr* _activeSocket;
|
HifiSockAddr* _activeSocket;
|
||||||
|
|
||||||
|
mutable BandwidthRecorder _bandwidthRecorder;
|
||||||
|
|
||||||
quint64 _wakeTimestamp;
|
quint64 _wakeTimestamp;
|
||||||
std::atomic_ullong _lastHeardMicrostamp;
|
std::atomic_ullong _lastHeardMicrostamp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue