add stats for max FRD and num avatars last frame

This commit is contained in:
Stephen Birarda 2015-04-30 10:09:23 -07:00
parent 4c4af81d3d
commit 17142a532f
4 changed files with 33 additions and 13 deletions

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <cfloat>
#include <random>
#include <QtCore/QCoreApplication>
@ -157,16 +158,14 @@ void AvatarMixer::broadcastAvatarData() {
AvatarData& avatar = nodeData->getAvatar();
glm::vec3 myPosition = avatar.getPosition();
// TODO use this along with the distance in the calculation of whether to send an update
// about a given otherNode to this node
// FIXME does this mean we should sort the othernodes by distance before iterating
// over them?
// float outputBandwidth =
node->getOutboundBandwidth();
// reset the internal state for correct random number distribution
distribution.reset();
// reset the max distance for this frame
float maxDistanceThisFrame = 0.0f;
// reset the number of sent avatars
nodeData->resetNumAvatarsSentLastFrame();
// this is an AGENT we have received head data from
// send back a packet with other active node data to this node
nodeList->eachMatchingNode(
@ -193,7 +192,10 @@ void AvatarMixer::broadcastAvatarData() {
// at twice the full rate distance, there will be a 50% chance of sending this avatar's update
glm::vec3 otherPosition = otherAvatar.getPosition();
float distanceToAvatar = glm::length(myPosition - otherPosition);
// potentially update the max full rate distance for this frame
maxDistanceThisFrame = std::max(maxDistanceThisFrame, distanceToAvatar);
if (distanceToAvatar != 0.0f
&& distribution(generator) > (nodeData->getFullRateDistance() / distanceToAvatar)) {
return;
@ -249,7 +251,15 @@ void AvatarMixer::broadcastAvatarData() {
}
});
nodeList->writeDatagram(mixedAvatarByteArray, node);
});
if (nodeData->getNumAvatarsSentLastFrame() == 0) {
// update the full rate distance to FLOAT_MAX since we didn't have any other avatars to send
nodeData->setMaxFullRateDistance(FLT_MAX);
} else {
nodeData->setMaxFullRateDistance(maxDistanceThisFrame);
}
}
);
_lastFrameTimestamp = QDateTime::currentMSecsSinceEpoch();
}

View file

@ -37,4 +37,6 @@ bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const {
jsonObject["display_name"] = _avatar.getDisplayName();
jsonObject["full_rate_distance"] = _fullRateDistance;
jsonObject["max_full_rate_distance"] = _maxFullRateDistance;
jsonObject["num_avatars_sent_last_frame"] = _numAvatarsSentLastFrame;
}

View file

@ -12,6 +12,7 @@
#ifndef hifi_AvatarMixerClientData_h
#define hifi_AvatarMixerClientData_h
#include <algorithm>
#include <cfloat>
#include <QtCore/QJsonObject>
@ -37,6 +38,11 @@ public:
void setIdentityChangeTimestamp(quint64 identityChangeTimestamp) { _identityChangeTimestamp = identityChangeTimestamp; }
float getFullRateDistance() const { return _fullRateDistance; }
void setMaxFullRateDistance(float distance) { _maxFullRateDistance = distance; }
void resetNumAvatarsSentLastFrame() { _numAvatarsSentLastFrame = 0; }
void increaseNumAvatarsSentLastFrame() { ++_numAvatarsSentLastFrame; }
int getNumAvatarsSentLastFrame() const { return _numAvatarsSentLastFrame; }
void loadJSONStats(QJsonObject& jsonObject) const;
private:
@ -45,6 +51,8 @@ private:
quint64 _billboardChangeTimestamp;
quint64 _identityChangeTimestamp;
float _fullRateDistance = FLT_MAX;
float _maxFullRateDistance = FLT_MAX;
int _numAvatarsSentLastFrame = 0;
};
#endif // hifi_AvatarMixerClientData_h

View file

@ -715,11 +715,11 @@ void Avatar::renderDisplayName() {
QString renderedDisplayName = _displayName;
if (DependencyManager::get<AvatarManager>()->shouldShowReceiveStats()) {
const float BYTES_PER_KILOBYTE = 1000.0f;
float kilobytesPerSecond = getAverageBytesReceivedPerSecond() / BYTES_PER_KILOBYTE;
const float KILOBITS_PER_BYTE = 125.0f;
float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / KILOBITS_PER_BYTE;
renderedDisplayName += QString(" - (%1 KBps, %2 Hz)")
.arg(QString::number(kilobytesPerSecond, 'f', 2))
renderedDisplayName += QString(" - (%1 Kbps, %2 Hz)")
.arg(QString::number(kilobitsPerSecond, 'f', 2))
.arg(getReceiveRate());
}