Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Try and fit all stream stats column within window
Browse files Browse the repository at this point in the history
 * Resize columns to content (instead of using default width)
 * Use Kpps/Mpps for Pkt Rate with 3 decimal
 * Use 3 decimal places for bit-rates (is more logical because units change
   every 1000 anyway)
 * Use 2 decimal places for time interval

This just improves the chances of all columns fitting - but is not guaranteed
  • Loading branch information
pstavirs committed Jun 26, 2023
1 parent bfda96a commit 28b308c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions client/streamstatsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ QVariant StreamStatsModel::data(const QModelIndex &index, int role) const
return QString("%L1").arg(aggrGuidStats_.value(guid).txDuration);
case kAvgTxFrameRate:
return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") :
QString("%L1").arg(
XLocale().toPktRateString(
aggrGuidStats_.value(guid).txPkts
/ aggrGuidStats_.value(guid).txDuration);
case kAvgRxFrameRate:
return aggrGuidStats_.value(guid).txDuration <= 0 ? QString("-") :
QString("%L1").arg(
XLocale().toPktRateString(
aggrGuidStats_.value(guid).rxPkts
/ aggrGuidStats_.value(guid).txDuration);
case kAvgTxBitRate:
Expand Down
6 changes: 6 additions & 0 deletions client/streamstatswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ StreamStatsWindow::StreamStatsWindow(QAbstractItemModel *model, QWidget *parent)
streamStats->verticalHeader()->setHighlightSections(false);
streamStats->verticalHeader()->setDefaultSectionSize(
streamStats->verticalHeader()->minimumSectionSize());

// Fit all columns in window whenever data changes
connect(model, &QAbstractItemModel::modelReset,
[=]() { streamStats->resizeColumnsToContents(); });
}

StreamStatsWindow::~StreamStatsWindow()
Expand All @@ -62,4 +66,6 @@ void StreamStatsWindow::on_actionShowDetails_triggered(bool checked)
filterModel_->setFilterRegExp(QRegExp(".*"));
else
filterModel_->setFilterRegExp(QRegExp(kDefaultFilter_));

streamStats->resizeColumnsToContents();
}
27 changes: 20 additions & 7 deletions client/xqlocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,47 @@ class XLocale: public QLocale
return toDouble(text, ok) * multiplier;
}

QString toPktRateString(double pps) const
{
QString text;

if (pps >= 1e6)
return QObject::tr("%L1 Mpps").arg(pps/1e6, 0, 'f', 3);

if (pps >= 1e3)
return QObject::tr("%L1 Kpps").arg(pps/1e3, 0, 'f', 3);

return QObject::tr("%L1").arg(pps, 0, 'f', 3);
}

QString toBitRateString(double bps) const
{
QString text;

if (bps >= 1e9)
return QObject::tr("%L1 Gbps").arg(bps/1e9, 0, 'f', 4);
return QObject::tr("%L1 Gbps").arg(bps/1e9, 0, 'f', 3);

if (bps >= 1e6)
return QObject::tr("%L1 Mbps").arg(bps/1e6, 0, 'f', 4);
return QObject::tr("%L1 Mbps").arg(bps/1e6, 0, 'f', 3);

if (bps >= 1e3)
return QObject::tr("%L1 Kbps").arg(bps/1e3, 0, 'f', 4);
return QObject::tr("%L1 Kbps").arg(bps/1e3, 0, 'f', 3);

return QObject::tr("%L1 bps").arg(bps, 0, 'f', 4);
return QObject::tr("%L1 bps").arg(bps, 0, 'f', 3);
}

QString toTimeIntervalString(qint64 nanosecs) const
{
QString text;

if (nanosecs >= 1e9)
return QObject::tr("%L1 s").arg(nanosecs/1e9, 0, 'f', 3);
return QObject::tr("%L1 s").arg(nanosecs/1e9, 0, 'f', 2);

if (nanosecs >= 1e6)
return QObject::tr("%L1 ms").arg(nanosecs/1e6, 0, 'f', 3);
return QObject::tr("%L1 ms").arg(nanosecs/1e6, 0, 'f', 2);

if (nanosecs >= 1e3)
return QObject::tr("%L1 us").arg(nanosecs/1e3, 0, 'f', 3);
return QObject::tr("%L1 us").arg(nanosecs/1e3, 0, 'f', 2);

return QObject::tr("%L1 ns").arg(nanosecs);
}
Expand Down

0 comments on commit 28b308c

Please sign in to comment.