refactoring, cause BandwidthDialog to only update numbers once per second

This commit is contained in:
Seth Alves 2015-02-02 05:28:28 -08:00
parent fc07ecf83d
commit b85456b1e9
6 changed files with 109 additions and 92 deletions

View file

@ -920,10 +920,10 @@ void ApplicationOverlay::renderStatsAndLogs() {
int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount();
// Onscreen text about position, servers, etc
Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(),
bandwidthRecorder->totalChannel->getAverageInputPacketsPerSecond(),
bandwidthRecorder->totalChannel->getAverageOutputPacketsPerSecond(),
bandwidthRecorder->totalChannel->getAverageInputKilobitsPerSecond(),
bandwidthRecorder->totalChannel->getAverageOutputKilobitsPerSecond(),
bandwidthRecorder->totalChannel.getAverageInputPacketsPerSecond(),
bandwidthRecorder->totalChannel.getAverageOutputPacketsPerSecond(),
bandwidthRecorder->totalChannel.getAverageInputKilobitsPerSecond(),
bandwidthRecorder->totalChannel.getAverageOutputKilobitsPerSecond(),
voxelPacketsToProcess);
}

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <iostream>
#include <cstdio>
#include "BandwidthRecorder.h"
@ -21,15 +22,10 @@
#include <QColor>
BandwidthDialog::ChannelDisplay::ChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form) {
BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form) {
this->ch = ch;
this->label = setupLabel(form);
}
QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) {
QLabel* label = new QLabel();
label = new QLabel();
label->setAlignment(Qt::AlignRight);
QPalette palette = label->palette();
@ -38,18 +34,20 @@ QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) {
palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb));
label->setPalette(palette);
form->addRow((std::string(" ") + ch->caption + " Bandwidth In/Out:").c_str(), label);
return label;
form->addRow(QString(" ") + ch->caption + " Bandwidth In/Out:", label);
}
void BandwidthDialog::ChannelDisplay::setLabelText() {
std::string strBuf =
std::to_string ((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" +
std::to_string ((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption;
label->setText(strBuf.c_str());
void BandwidthChannelDisplay::bandwidthAverageUpdated() {
strBuf =
QString("").setNum((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" +
QString("").setNum((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption;
}
void BandwidthChannelDisplay::Paint() {
label->setText(strBuf);
}
@ -64,43 +62,45 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) :
QFormLayout* form = new QFormLayout();
this->QDialog::setLayout(form);
audioChannelDisplay = new ChannelDisplay(_model->audioChannel, form);
avatarsChannelDisplay = new ChannelDisplay(_model->avatarsChannel, form);
octreeChannelDisplay = new ChannelDisplay(_model->octreeChannel, form);
metavoxelsChannelDisplay = new ChannelDisplay(_model->metavoxelsChannel, form);
otherChannelDisplay = new ChannelDisplay(_model->otherChannel, form);
totalChannelDisplay = new ChannelDisplay(_model->totalChannel, form);
_allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&_model->audioChannel, form);
_allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&_model->avatarsChannel, form);
_allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&_model->octreeChannel, form);
_allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&_model->metavoxelsChannel, form);
_allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&_model->otherChannel, form);
_allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&_model->totalChannel, form);
connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout()));
averageUpdateTimer->start(1000);
}
BandwidthDialog::~BandwidthDialog() {
delete audioChannelDisplay;
delete avatarsChannelDisplay;
delete octreeChannelDisplay;
delete metavoxelsChannelDisplay;
delete otherChannelDisplay;
delete totalChannelDisplay;
for (unsigned int i=0; i<_CHANNELCOUNT; i++)
delete _allChannelDisplays[i];
}
void BandwidthDialog::updateTimerTimeout() {
for (unsigned int i=0; i<_CHANNELCOUNT; i++)
_allChannelDisplays[i]->bandwidthAverageUpdated();
}
void BandwidthDialog::paintEvent(QPaintEvent* event) {
audioChannelDisplay->setLabelText();
avatarsChannelDisplay->setLabelText();
octreeChannelDisplay->setLabelText();
metavoxelsChannelDisplay->setLabelText();
otherChannelDisplay->setLabelText();
totalChannelDisplay->setLabelText();
for (unsigned int i=0; i<_CHANNELCOUNT; i++)
_allChannelDisplays[i]->Paint();
this->QDialog::paintEvent(event);
this->setFixedSize(this->width(), this->height());
}
void BandwidthDialog::reject() {
// Just regularly close upon ESC
this->QDialog::close();
}
void BandwidthDialog::closeEvent(QCloseEvent* event) {
this->QDialog::closeEvent(event);

View file

@ -19,6 +19,25 @@
#include "BandwidthRecorder.h"
class BandwidthChannelDisplay : public QObject {
Q_OBJECT
public:
BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form);
void Paint();
private:
BandwidthRecorder::Channel *ch;
QLabel* label;
// std::string strBuf;
QString strBuf;
public slots:
void bandwidthAverageUpdated();
};
class BandwidthDialog : public QDialog {
Q_OBJECT
public:
@ -26,26 +45,19 @@ public:
BandwidthDialog(QWidget* parent, BandwidthRecorder* model);
~BandwidthDialog();
class ChannelDisplay {
public:
ChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form);
QLabel* setupLabel(QFormLayout* form);
void setLabelText();
void paintEvent(QPaintEvent*);
private:
BandwidthRecorder::Channel *ch;
private:
BandwidthChannelDisplay* _audioChannelDisplay;
BandwidthChannelDisplay* _avatarsChannelDisplay;
BandwidthChannelDisplay* _octreeChannelDisplay;
BandwidthChannelDisplay* _metavoxelsChannelDisplay;
BandwidthChannelDisplay* _otherChannelDisplay;
BandwidthChannelDisplay* _totalChannelDisplay; // sums of all the other channels
QLabel* label;
};
static const unsigned int _CHANNELCOUNT = 6;
BandwidthChannelDisplay *_allChannelDisplays[_CHANNELCOUNT];
ChannelDisplay* audioChannelDisplay;
ChannelDisplay* avatarsChannelDisplay;
ChannelDisplay* octreeChannelDisplay;
ChannelDisplay* metavoxelsChannelDisplay;
ChannelDisplay* otherChannelDisplay;
// sums of all the other channels
ChannelDisplay* totalChannelDisplay;
signals:
@ -54,15 +66,18 @@ signals:
public slots:
void reject();
void updateTimerTimeout();
protected:
void paintEvent(QPaintEvent*);
// Emits a 'closed' signal when this dialog is closed.
void closeEvent(QCloseEvent*);
private:
BandwidthRecorder* _model;
QTimer *averageUpdateTimer = new QTimer(this);
};
#endif // hifi_BandwidthDialog_h

View file

@ -444,10 +444,10 @@ void Stats::display(
sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps",
// roundf(avatarMixer->getAverageKilobitsPerSecond()),
// roundf(avatarMixer->getAveragePacketsPerSecond())
roundf(bandwidthRecorder->audioChannel->getAverageInputKilobitsPerSecond() +
bandwidthRecorder->audioChannel->getAverageOutputKilobitsPerSecond()),
roundf(bandwidthRecorder->audioChannel->getAverageInputPacketsPerSecond() +
bandwidthRecorder->audioChannel->getAverageOutputPacketsPerSecond()));
roundf(bandwidthRecorder->audioChannel.getAverageInputKilobitsPerSecond() +
bandwidthRecorder->audioChannel.getAverageOutputKilobitsPerSecond()),
roundf(bandwidthRecorder->audioChannel.getAverageInputPacketsPerSecond() +
bandwidthRecorder->audioChannel.getAverageOutputPacketsPerSecond()));
} else {
sprintf(avatarMixerStats, "No Avatar Mixer");
}

View file

@ -11,7 +11,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// #include <GeometryCache.h>
#include "BandwidthRecorder.h"
@ -27,11 +26,17 @@ BandwidthRecorder::Channel::Channel(char const* const caption,
}
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
return (1 / _input.getEventDeltaAverage());
float delt = _input.getEventDeltaAverage();
if (delt > 0.)
return (1.0 / delt);
return 0.;
}
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
return (1 / _output.getEventDeltaAverage());
float delt = _input.getEventDeltaAverage();
if (delt > 0.)
return (1.0 / _output.getEventDeltaAverage());
return 0.;
}
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() {
@ -58,66 +63,62 @@ BandwidthRecorder::BandwidthRecorder() {
BandwidthRecorder::~BandwidthRecorder() {
delete audioChannel;
delete avatarsChannel;
delete octreeChannel;
delete metavoxelsChannel;
delete totalChannel;
}
void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) {
totalChannel->updateInputAverage(sample);
totalChannel.updateInputAverage(sample);
// see Node.h NodeType
switch (channelType) {
case NodeType::DomainServer:
case NodeType::EntityServer:
octreeChannel->updateInputAverage(sample);
octreeChannel.updateInputAverage(sample);
break;
case NodeType::MetavoxelServer:
case NodeType::EnvironmentServer:
metavoxelsChannel->updateInputAverage(sample);
metavoxelsChannel.updateInputAverage(sample);
break;
case NodeType::AudioMixer:
audioChannel->updateInputAverage(sample);
audioChannel.updateInputAverage(sample);
break;
case NodeType::Agent:
case NodeType::AvatarMixer:
avatarsChannel->updateInputAverage(sample);
avatarsChannel.updateInputAverage(sample);
break;
case NodeType::Unassigned:
default:
otherChannel->updateInputAverage(sample);
otherChannel.updateInputAverage(sample);
break;
}
}
void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) {
totalChannel->updateOutputAverage(sample);
totalChannel.updateOutputAverage(sample);
// see Node.h NodeType
switch (channelType) {
case NodeType::DomainServer:
case NodeType::EntityServer:
octreeChannel->updateOutputAverage(sample);
octreeChannel.updateOutputAverage(sample);
break;
case NodeType::MetavoxelServer:
case NodeType::EnvironmentServer:
metavoxelsChannel->updateOutputAverage(sample);
metavoxelsChannel.updateOutputAverage(sample);
break;
case NodeType::AudioMixer:
audioChannel->updateOutputAverage(sample);
audioChannel.updateOutputAverage(sample);
break;
case NodeType::Agent:
case NodeType::AvatarMixer:
avatarsChannel->updateOutputAverage(sample);
avatarsChannel.updateOutputAverage(sample);
break;
case NodeType::Unassigned:
default:
otherChannel->updateOutputAverage(sample);
otherChannel.updateOutputAverage(sample);
break;
}
}

View file

@ -16,6 +16,7 @@
#include <QObject>
#include <QElapsedTimer>
#include <QTimer>
#include "Node.h"
#include "SimpleMovingAverage.h"
@ -29,7 +30,7 @@ const unsigned int COLOR2 = 0xd0d0d0a0;
class BandwidthRecorder : public QObject {
Q_OBJECT
public:
public:
BandwidthRecorder();
~BandwidthRecorder();
@ -52,21 +53,21 @@ class BandwidthRecorder : public QObject {
unsigned colorRGBA;
private:
SimpleMovingAverage _input = SimpleMovingAverage(1000);
SimpleMovingAverage _output = SimpleMovingAverage(1000);
SimpleMovingAverage _input = SimpleMovingAverage();
SimpleMovingAverage _output = SimpleMovingAverage();
};
// create the channels we keep track of
Channel* audioChannel = new Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0);
Channel* avatarsChannel = new Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1);
Channel* octreeChannel = new Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel* otherChannel = new Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel* totalChannel = new Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel audioChannel = Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0);
Channel avatarsChannel = Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1);
Channel octreeChannel = Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel metavoxelsChannel = Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel otherChannel = Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
Channel totalChannel = Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2);
public slots:
void updateInboundData(const quint8 channelType, const int bytes);
void updateOutboundData(const quint8 channelType, const int bytes);
public slots:
void updateInboundData(const quint8 channelType, const int bytes);
void updateOutboundData(const quint8 channelType, const int bytes);
};
#endif