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 received = 0, total = 0;
int sendProgress = 0, sendTotal = 0;
int receiveProgress = 0, receiveTotal = 0;
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
if (node->getType() == NodeType::MetavoxelServer) {
QMutexLocker locker(&node->getMutex());
MetavoxelClient* client = static_cast<MetavoxelSystemClient*>(node->getLinkedData());
if (client) {
client->getData().countNodes(internal, leaves, Application::getInstance()->getMetavoxels()->getLOD());
int clientReceived = 0, clientTotal = 0;
if (client->getReliableDeltaProgress(clientReceived, clientTotal)) {
received += clientReceived;
total += clientTotal;
}
client->getSequencer().addReliableChannelStats(sendProgress, sendTotal, receiveProgress, receiveTotal);
}
}
}
@ -447,11 +444,16 @@ void Stats::display(
verticalOffset += STATS_PELS_PER_LINE;
drawText(horizontalOffset, verticalOffset, scale, rotation, font, nodeTypes.str().c_str(), color);
if (total > 0) {
stringstream reliableDelta;
reliableDelta << "Reliable Delta: " << (received * 100 / total) << "%";
if (sendTotal > 0 || receiveTotal > 0) {
stringstream reliableStats;
if (sendTotal > 0) {
reliableStats << "Upload: " << (sendProgress * 100 / sendTotal) << "% ";
}
if (receiveTotal > 0) {
reliableStats << "Download: " << (receiveProgress * 100 / receiveTotal) << "%";
}
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;
}
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) {
// figure out how much data we have enqueued and increase the number of packets desired
int totalAvailable = 0;
@ -684,6 +702,8 @@ void ReliableChannel::endMessage() {
quint32 length = _buffer.pos() - _messageLengthPlaceholder;
_buffer.writeBytes(_messageLengthPlaceholder, sizeof(quint32), (const char*)&length);
_messageReceivedOffset = getBytesWritten();
_messageSize = length;
}
void ReliableChannel::sendMessage(const QVariant& message) {
@ -692,6 +712,15 @@ void ReliableChannel::sendMessage(const QVariant& message) {
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 {
if (!_messagesEnabled || _buffer.bytesAvailable() < (int)sizeof(quint32)) {
return false;
@ -728,7 +757,8 @@ ReliableChannel::ReliableChannel(DatagramSequencer* sequencer, int index, bool o
_offset(0),
_writePosition(0),
_writePositionResetPacketNumber(0),
_messagesEnabled(true) {
_messagesEnabled(true),
_messageReceivedOffset(0) {
_buffer.open(output ? QIODevice::WriteOnly : QIODevice::ReadOnly);
_dataStream.setByteOrder(QDataStream::LittleEndian);

View file

@ -108,6 +108,9 @@ public:
/// Returns the intput channel at the specified index, creating it if necessary.
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.
/// \param desiredPackets the number of packets we'd like 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).
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.
/// \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;
@ -420,6 +427,8 @@ private:
SpanList _acknowledged;
bool _messagesEnabled;
int _messageLengthPlaceholder;
int _messageReceivedOffset;
int _messageSize;
};
#endif // hifi_DatagramSequencer_h

View file

@ -32,6 +32,8 @@ public:
PacketRecord* baselineReceiveRecord = NULL);
virtual ~Endpoint();
const DatagramSequencer& getSequencer() const { return _sequencer; }
virtual void update();
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&)));
}
bool MetavoxelClient::getReliableDeltaProgress(int& received, int& total) const {
return _reliableDeltaChannel && _reliableDeltaChannel->getMessageReceiveProgress(received, total);
}
void MetavoxelClient::guide(MetavoxelVisitor& visitor) {
visitor.setLOD(_manager->getLOD());
_data.guide(visitor);

View file

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