Show upload/download stats for all reliable messages, not just reliable delta

downloads.
This commit is contained in:
Andrzej Kapolka 2014-07-10 15:34:45 -07:00
parent e55a0fbc9c
commit 817b50c7b8
6 changed files with 54 additions and 17 deletions

View file

@ -422,18 +422,15 @@ void Stats::display(
int internal = 0, leaves = 0; int internal = 0, leaves = 0;
int received = 0, total = 0; int sendProgress = 0, sendTotal = 0;
int receiveProgress = 0, receiveTotal = 0;
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
if (node->getType() == NodeType::MetavoxelServer) { if (node->getType() == NodeType::MetavoxelServer) {
QMutexLocker locker(&node->getMutex()); QMutexLocker locker(&node->getMutex());
MetavoxelClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData()); MetavoxelClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
if (client) { if (client) {
client->getData().countNodes(internal, leaves, Application::getInstance()->getMetavoxels()->getLOD()); client->getData().countNodes(internal, leaves, Application::getInstance()->getMetavoxels()->getLOD());
int clientReceived = 0, clientTotal = 0; client->getSequencer().addReliableChannelStats(sendProgress, sendTotal, receiveProgress, receiveTotal);
if (client->getReliableDeltaProgress(clientReceived, clientTotal)) {
received += clientReceived;
total += clientTotal;
}
} }
} }
} }
@ -447,11 +444,16 @@ void Stats::display(
verticalOffset += STATS_PELS_PER_LINE; verticalOffset += STATS_PELS_PER_LINE;
drawText(horizontalOffset, verticalOffset, scale, rotation, font, nodeTypes.str().c_str(), color); drawText(horizontalOffset, verticalOffset, scale, rotation, font, nodeTypes.str().c_str(), color);
if (total > 0) { if (sendTotal > 0 || receiveTotal > 0) {
stringstream reliableDelta; stringstream reliableStats;
reliableDelta << "Reliable Delta: " << (received * 100 / total) << "%"; if (sendTotal > 0) {
reliableStats << "Upload: " << (sendProgress * 100 / sendTotal) << "% ";
}
if (receiveTotal > 0) {
reliableStats << "Download: " << (receiveProgress * 100 / receiveTotal) << "%";
}
verticalOffset += STATS_PELS_PER_LINE; verticalOffset += STATS_PELS_PER_LINE;
drawText(horizontalOffset, verticalOffset, scale, rotation, font, reliableDelta.str().c_str(), color); drawText(horizontalOffset, verticalOffset, scale, rotation, font, reliableStats.str().c_str(), color);
} }
} }

View file

@ -79,6 +79,24 @@ ReliableChannel* DatagramSequencer::getReliableInputChannel(int index) {
return channel; return channel;
} }
void DatagramSequencer::addReliableChannelStats(int& sendProgress, int& sendTotal,
int& receiveProgress, int& receiveTotal) const {
foreach (ReliableChannel* channel, _reliableOutputChannels) {
int sent, total;
if (channel->getMessageSendProgress(sent, total)) {
sendProgress += sent;
sendTotal += total;
}
}
foreach (ReliableChannel* channel, _reliableInputChannels) {
int received, total;
if (channel->getMessageReceiveProgress(received, total)) {
receiveProgress += received;
receiveTotal += total;
}
}
}
int DatagramSequencer::notePacketGroup(int desiredPackets) { int DatagramSequencer::notePacketGroup(int desiredPackets) {
// figure out how much data we have enqueued and increase the number of packets desired // figure out how much data we have enqueued and increase the number of packets desired
int totalAvailable = 0; int totalAvailable = 0;
@ -684,6 +702,8 @@ void ReliableChannel::endMessage() {
quint32 length = _buffer.pos() - _messageLengthPlaceholder; quint32 length = _buffer.pos() - _messageLengthPlaceholder;
_buffer.writeBytes(_messageLengthPlaceholder, sizeof(quint32), (const char*)&length); _buffer.writeBytes(_messageLengthPlaceholder, sizeof(quint32), (const char*)&length);
_messageReceivedOffset = getBytesWritten();
_messageSize = length;
} }
void ReliableChannel::sendMessage(const QVariant& message) { void ReliableChannel::sendMessage(const QVariant& message) {
@ -692,6 +712,15 @@ void ReliableChannel::sendMessage(const QVariant& message) {
endMessage(); endMessage();
} }
bool ReliableChannel::getMessageSendProgress(int& sent, int& total) const {
if (!_messagesEnabled || _offset >= _messageReceivedOffset) {
return false;
}
sent = qMax(0, _messageSize - (_messageReceivedOffset - _offset));
total = _messageSize;
return true;
}
bool ReliableChannel::getMessageReceiveProgress(int& received, int& total) const { bool ReliableChannel::getMessageReceiveProgress(int& received, int& total) const {
if (!_messagesEnabled || _buffer.bytesAvailable() < (int)sizeof(quint32)) { if (!_messagesEnabled || _buffer.bytesAvailable() < (int)sizeof(quint32)) {
return false; return false;
@ -728,7 +757,8 @@ ReliableChannel::ReliableChannel(DatagramSequencer* sequencer, int index, bool o
_offset(0), _offset(0),
_writePosition(0), _writePosition(0),
_writePositionResetPacketNumber(0), _writePositionResetPacketNumber(0),
_messagesEnabled(true) { _messagesEnabled(true),
_messageReceivedOffset(0) {
_buffer.open(output ? QIODevice::WriteOnly : QIODevice::ReadOnly); _buffer.open(output ? QIODevice::WriteOnly : QIODevice::ReadOnly);
_dataStream.setByteOrder(QDataStream::LittleEndian); _dataStream.setByteOrder(QDataStream::LittleEndian);

View file

@ -108,6 +108,9 @@ public:
/// Returns the intput channel at the specified index, creating it if necessary. /// Returns the intput channel at the specified index, creating it if necessary.
ReliableChannel* getReliableInputChannel(int index = 0); ReliableChannel* getReliableInputChannel(int index = 0);
/// Adds stats for all reliable channels to the referenced variables.
void addReliableChannelStats(int& sendProgress, int& sendTotal, int& receiveProgress, int& receiveTotal) const;
/// Notes that we're sending a group of packets. /// Notes that we're sending a group of packets.
/// \param desiredPackets the number of packets we'd like to write in the group /// \param desiredPackets the number of packets we'd like to write in the group
/// \return the number of packets to write in the group /// \return the number of packets to write in the group
@ -376,6 +379,10 @@ public:
/// writes the message to the bitstream, then calls endMessage). /// writes the message to the bitstream, then calls endMessage).
void sendMessage(const QVariant& message); void sendMessage(const QVariant& message);
/// Determines the number of bytes uploaded towards the currently pending message.
/// \return true if there is a message pending, in which case the sent and total arguments will be set
bool getMessageSendProgress(int& sent, int& total) const;
/// Determines the number of bytes downloaded towards the currently pending message. /// Determines the number of bytes downloaded towards the currently pending message.
/// \return true if there is a message pending, in which case the received and total arguments will be set /// \return true if there is a message pending, in which case the received and total arguments will be set
bool getMessageReceiveProgress(int& received, int& total) const; bool getMessageReceiveProgress(int& received, int& total) const;
@ -420,6 +427,8 @@ private:
SpanList _acknowledged; SpanList _acknowledged;
bool _messagesEnabled; bool _messagesEnabled;
int _messageLengthPlaceholder; int _messageLengthPlaceholder;
int _messageReceivedOffset;
int _messageSize;
}; };
#endif // hifi_DatagramSequencer_h #endif // hifi_DatagramSequencer_h

View file

@ -32,6 +32,8 @@ public:
PacketRecord* baselineReceiveRecord = NULL); PacketRecord* baselineReceiveRecord = NULL);
virtual ~Endpoint(); virtual ~Endpoint();
const DatagramSequencer& getSequencer() const { return _sequencer; }
virtual void update(); virtual void update();
virtual int parseData(const QByteArray& packet); virtual int parseData(const QByteArray& packet);

View file

@ -94,10 +94,6 @@ MetavoxelClient::MetavoxelClient(const SharedNodePointer& node, MetavoxelClientM
SIGNAL(receivedMessage(const QVariant&, Bitstream&)), SLOT(handleMessage(const QVariant&, Bitstream&))); SIGNAL(receivedMessage(const QVariant&, Bitstream&)), SLOT(handleMessage(const QVariant&, Bitstream&)));
} }
bool MetavoxelClient::getReliableDeltaProgress(int& received, int& total) const {
return _reliableDeltaChannel && _reliableDeltaChannel->getMessageReceiveProgress(received, total);
}
void MetavoxelClient::guide(MetavoxelVisitor& visitor) { void MetavoxelClient::guide(MetavoxelVisitor& visitor) {
visitor.setLOD(_manager->getLOD()); visitor.setLOD(_manager->getLOD());
_data.guide(visitor); _data.guide(visitor);

View file

@ -53,8 +53,6 @@ public:
MetavoxelData& getData() { return _data; } MetavoxelData& getData() { return _data; }
bool getReliableDeltaProgress(int& received, int& total) const;
void guide(MetavoxelVisitor& visitor); void guide(MetavoxelVisitor& visitor);
void applyEdit(const MetavoxelEditMessage& edit, bool reliable = false); void applyEdit(const MetavoxelEditMessage& edit, bool reliable = false);