From a035712f0db2e0835c07a53556a9e197bd8faa4f Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Fri, 15 Sep 2017 22:23:05 +0300 Subject: Fix visualization of memory consumption values (use 2^10 instead of 10^3 as divisor for bytes -> kilobytes -> megabytes -> etc. calculation). --- src/analyze/gui/callercalleemodel.cpp | 24 ++++++++++++------------ src/analyze/gui/chartmodel.cpp | 2 +- src/analyze/gui/chartwidget.cpp | 2 +- src/analyze/gui/flamegraph.cpp | 16 ++++++++-------- src/analyze/gui/histogramwidget.cpp | 2 +- src/analyze/gui/mainwindow.cpp | 12 ++++++------ src/analyze/gui/treemodel.cpp | 12 ++++++------ src/analyze/print/heaptrack_print.cpp | 6 +++--- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/analyze/gui/callercalleemodel.cpp b/src/analyze/gui/callercalleemodel.cpp index b6888c7..5ce63d9 100644 --- a/src/analyze/gui/callercalleemodel.cpp +++ b/src/analyze/gui/callercalleemodel.cpp @@ -183,7 +183,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(row.selfCost.allocated); } else { - return m_format.formatByteSize(row.selfCost.allocated, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.selfCost.allocated, 1, KFormat::JEDECBinaryDialect); } case SelfAllocationsColumn: return static_cast(row.selfCost.allocations); @@ -193,7 +193,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(row.selfCost.peak); } else { - return m_format.formatByteSize(row.selfCost.peak, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.selfCost.peak, 1, KFormat::JEDECBinaryDialect); } case SelfPeakInstancesColumn: return static_cast(row.selfCost.peak_instances); @@ -201,13 +201,13 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(row.selfCost.leaked); } else { - return m_format.formatByteSize(row.selfCost.leaked, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.selfCost.leaked, 1, KFormat::JEDECBinaryDialect); } case InclusiveAllocatedColumn: if (role == SortRole || role == MaxCostRole) { return static_cast(row.inclusiveCost.allocated); } else { - return m_format.formatByteSize(row.inclusiveCost.allocated, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.inclusiveCost.allocated, 1, KFormat::JEDECBinaryDialect); } case InclusiveAllocationsColumn: return static_cast(row.inclusiveCost.allocations); @@ -217,7 +217,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(row.inclusiveCost.peak); } else { - return m_format.formatByteSize(row.inclusiveCost.peak, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.inclusiveCost.peak, 1, KFormat::JEDECBinaryDialect); } case InclusivePeakInstancesColumn: return static_cast(row.inclusiveCost.peak_instances); @@ -225,7 +225,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(row.inclusiveCost.leaked); } else { - return m_format.formatByteSize(row.inclusiveCost.leaked, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row.inclusiveCost.leaked, 1, KFormat::JEDECBinaryDialect); } case FunctionColumn: return row.location->function; @@ -260,23 +260,23 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const stream << '\n'; stream << i18n("inclusive: allocated %1 over %2 calls (%3 temporary, i.e. " "%4%), peak at %5, leaked %6", - m_format.formatByteSize(row.inclusiveCost.allocated, 1, KFormat::MetricBinaryDialect), + m_format.formatByteSize(row.inclusiveCost.allocated, 1, KFormat::JEDECBinaryDialect), row.inclusiveCost.allocations, row.inclusiveCost.temporary, round(float(row.inclusiveCost.temporary) * 100.f * 100.f / std::max(int64_t(1), row.inclusiveCost.allocations)) / 100.f, - m_format.formatByteSize(row.inclusiveCost.peak, 1, KFormat::MetricBinaryDialect), - m_format.formatByteSize(row.inclusiveCost.leaked, 1, KFormat::MetricBinaryDialect)); + m_format.formatByteSize(row.inclusiveCost.peak, 1, KFormat::JEDECBinaryDialect), + m_format.formatByteSize(row.inclusiveCost.leaked, 1, KFormat::JEDECBinaryDialect)); stream << '\n'; stream << i18n( "self: allocated %1 over %2 calls (%3 temporary, i.e. %4%), " "peak at %5, leaked %6", - m_format.formatByteSize(row.selfCost.allocated, 1, KFormat::MetricBinaryDialect), + m_format.formatByteSize(row.selfCost.allocated, 1, KFormat::JEDECBinaryDialect), row.selfCost.allocations, row.selfCost.temporary, round(float(row.selfCost.temporary) * 100.f * 100.f / std::max(int64_t(1), row.selfCost.allocations)) / 100.f, - m_format.formatByteSize(row.selfCost.peak, 1, KFormat::MetricBinaryDialect), - m_format.formatByteSize(row.selfCost.leaked, 1, KFormat::MetricBinaryDialect)); + m_format.formatByteSize(row.selfCost.peak, 1, KFormat::JEDECBinaryDialect), + m_format.formatByteSize(row.selfCost.leaked, 1, KFormat::JEDECBinaryDialect)); stream << '\n'; stream << ""; return tooltip; diff --git a/src/analyze/gui/chartmodel.cpp b/src/analyze/gui/chartmodel.cpp index b6858f7..1db0ac9 100644 --- a/src/analyze/gui/chartmodel.cpp +++ b/src/analyze/gui/chartmodel.cpp @@ -126,7 +126,7 @@ QVariant ChartModel::data(const QModelIndex& index, int role) const auto byteCost = [cost]() -> QString { KFormat format; - const auto formatted = format.formatByteSize(cost, 1, KFormat::MetricBinaryDialect); + const auto formatted = format.formatByteSize(cost, 1, KFormat::JEDECBinaryDialect); if (cost > 1024) { return i18nc("%1: the formatted byte size, e.g. \"1.2KB\", %2: the raw byte size, e.g. \"1300\"", "%1 (%2 bytes)", formatted, cost); diff --git a/src/analyze/gui/chartwidget.cpp b/src/analyze/gui/chartwidget.cpp index 01086f4..fbbc05d 100644 --- a/src/analyze/gui/chartwidget.cpp +++ b/src/analyze/gui/chartwidget.cpp @@ -69,7 +69,7 @@ public: const QString customizedLabel(const QString& label) const override { KFormat format(QLocale::system()); - return format.formatByteSize(label.toDouble(), 1, KFormat::MetricBinaryDialect); + return format.formatByteSize(label.toDouble(), 1, KFormat::JEDECBinaryDialect); } }; } diff --git a/src/analyze/gui/flamegraph.cpp b/src/analyze/gui/flamegraph.cpp index 07ba90f..5a27d9c 100644 --- a/src/analyze/gui/flamegraph.cpp +++ b/src/analyze/gui/flamegraph.cpp @@ -228,7 +228,7 @@ QString FrameGraphicsItem::description() const i18nc("%1: peak consumption in bytes, %2: relative number, %3: " "function label", "%1 (%2%) contribution to peak consumption in %3 and below.", - format.formatByteSize(m_cost, 1, KFormat::MetricBinaryDialect), fraction, function); + format.formatByteSize(m_cost, 1, KFormat::JEDECBinaryDialect), fraction, function); break; case PeakInstances: tooltip = @@ -239,12 +239,12 @@ QString FrameGraphicsItem::description() const break; case Leaked: tooltip = i18nc("%1: leaked bytes, %2: relative number, %3: function label", "%1 (%2%) leaked in %3 and below.", - format.formatByteSize(m_cost, 1, KFormat::MetricBinaryDialect), fraction, function); + format.formatByteSize(m_cost, 1, KFormat::JEDECBinaryDialect), fraction, function); break; case Allocated: tooltip = i18nc("%1: allocated bytes, %2: relative number, %3: function label", "%1 (%2%) allocated in %3 and below.", - format.formatByteSize(m_cost, 1, KFormat::MetricBinaryDialect), fraction, function); + format.formatByteSize(m_cost, 1, KFormat::JEDECBinaryDialect), fraction, function); break; } @@ -385,16 +385,16 @@ FrameGraphicsItem* parseData(const QVector& topDownData, CostType type, label = i18n("%1 temporary allocations in total", totalCost); break; case Peak: - label = i18n("%1 contribution to peak consumption", format.formatByteSize(totalCost, 1, KFormat::MetricBinaryDialect)); + label = i18n("%1 contribution to peak consumption", format.formatByteSize(totalCost, 1, KFormat::JEDECBinaryDialect)); break; case PeakInstances: label = i18n("%1 contribution to peak number of instances", totalCost); break; case Leaked: - label = i18n("%1 leaked in total", format.formatByteSize(totalCost, 1, KFormat::MetricBinaryDialect)); + label = i18n("%1 leaked in total", format.formatByteSize(totalCost, 1, KFormat::JEDECBinaryDialect)); break; case Allocated: - label = i18n("%1 allocated in total", format.formatByteSize(totalCost, 1, KFormat::MetricBinaryDialect)); + label = i18n("%1 allocated in total", format.formatByteSize(totalCost, 1, KFormat::JEDECBinaryDialect)); break; } auto rootItem = new FrameGraphicsItem(totalCost, type, label); @@ -776,8 +776,8 @@ void FlameGraph::setSearchValue(const QString& value) case Leaked: case Allocated: label = i18n("%1 (%2% of total of %3) matched by search.", - format.formatByteSize(match.directCost, 1, KFormat::MetricBinaryDialect), costFraction, - format.formatByteSize(m_rootItem->cost(), 1, KFormat::MetricBinaryDialect)); + format.formatByteSize(match.directCost, 1, KFormat::JEDECBinaryDialect), costFraction, + format.formatByteSize(m_rootItem->cost(), 1, KFormat::JEDECBinaryDialect)); break; } m_searchResultsLabel->setText(label); diff --git a/src/analyze/gui/histogramwidget.cpp b/src/analyze/gui/histogramwidget.cpp index 8f38b43..44b1695 100644 --- a/src/analyze/gui/histogramwidget.cpp +++ b/src/analyze/gui/histogramwidget.cpp @@ -53,7 +53,7 @@ public: const QString customizedLabel(const QString& label) const override { KFormat format(QLocale::system()); - return format.formatByteSize(label.toDouble(), 1, KFormat::MetricBinaryDialect); + return format.formatByteSize(label.toDouble(), 1, KFormat::JEDECBinaryDialect); } }; diff --git a/src/analyze/gui/mainwindow.cpp b/src/analyze/gui/mainwindow.cpp index 4f7a862..16f1404 100644 --- a/src/analyze/gui/mainwindow.cpp +++ b/src/analyze/gui/mainwindow.cpp @@ -288,7 +288,7 @@ MainWindow::MainWindow(QWidget* parent) // xgettext:no-c-format << i18n("
total runtime:
%1s
", totalTimeS) << i18n("
total system memory:
%1
", - format.formatByteSize(data.totalSystemMemory, 1, KFormat::MetricBinaryDialect)) + format.formatByteSize(data.totalSystemMemory, 1, KFormat::JEDECBinaryDialect)) << ""; } @@ -306,8 +306,8 @@ MainWindow::MainWindow(QWidget* parent) qint64(data.cost.temporary / totalTimeS)) << i18n("
bytes allocated in total (ignoring " "deallocations):
%1 (%2/s)
", - format.formatByteSize(data.cost.allocated, 2, KFormat::MetricBinaryDialect), - format.formatByteSize(data.cost.allocated / totalTimeS, 1, KFormat::MetricBinaryDialect)) + format.formatByteSize(data.cost.allocated, 2, KFormat::JEDECBinaryDialect), + format.formatByteSize(data.cost.allocated / totalTimeS, 1, KFormat::JEDECBinaryDialect)) << ""; } if (AccumulatedTraceData::isShowCoreCLRPartOption) @@ -364,13 +364,13 @@ MainWindow::MainWindow(QWidget* parent) QTextStream stream(&textRight); stream << "
" << i18n("
peak heap memory consumption:
%1 " "after %2s
", - format.formatByteSize(data.cost.peak, 1, KFormat::MetricBinaryDialect), + format.formatByteSize(data.cost.peak, 1, KFormat::JEDECBinaryDialect), peakTimeS) << i18n("
peak RSS (including heaptrack " "overhead):
%1
", - format.formatByteSize(data.peakRSS, 1, KFormat::MetricBinaryDialect)) + format.formatByteSize(data.peakRSS, 1, KFormat::JEDECBinaryDialect)) << i18n("
total memory leaked:
%1
", - format.formatByteSize(data.cost.leaked, 1, KFormat::MetricBinaryDialect)) + format.formatByteSize(data.cost.leaked, 1, KFormat::JEDECBinaryDialect)) << "
"; } diff --git a/src/analyze/gui/treemodel.cpp b/src/analyze/gui/treemodel.cpp index 936c278..09b6b6c 100644 --- a/src/analyze/gui/treemodel.cpp +++ b/src/analyze/gui/treemodel.cpp @@ -165,7 +165,7 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(abs(row->cost.allocated)); } - return m_format.formatByteSize(row->cost.allocated, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row->cost.allocated, 1, KFormat::JEDECBinaryDialect); case AllocationsColumn: if (role == SortRole || role == MaxCostRole) { return static_cast(abs(row->cost.allocations)); @@ -180,7 +180,7 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(abs(row->cost.peak)); } else { - return m_format.formatByteSize(row->cost.peak, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row->cost.peak, 1, KFormat::JEDECBinaryDialect); } case PeakInstancesColumn: if (role == SortRole || role == MaxCostRole) { @@ -191,7 +191,7 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const if (role == SortRole || role == MaxCostRole) { return static_cast(abs(row->cost.leaked)); } else { - return m_format.formatByteSize(row->cost.leaked, 1, KFormat::MetricBinaryDialect); + return m_format.formatByteSize(row->cost.leaked, 1, KFormat::JEDECBinaryDialect); } case FunctionColumn: return row->location->function; @@ -237,11 +237,11 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const const auto temporaryFractionTotal = QString::number(double(row->cost.temporary) * 100. / m_maxCost.cost.temporary, 'g', 3); stream << i18n("allocated: %1 (%2% of total)\n", - format.formatByteSize(row->cost.allocated, 1, KFormat::MetricBinaryDialect), allocatedFraction); + format.formatByteSize(row->cost.allocated, 1, KFormat::JEDECBinaryDialect), allocatedFraction); stream << i18n("peak contribution: %1 (%2% of total)\n", - format.formatByteSize(row->cost.peak, 1, KFormat::MetricBinaryDialect), peakFraction); + format.formatByteSize(row->cost.peak, 1, KFormat::JEDECBinaryDialect), peakFraction); stream << i18n("leaked: %1 (%2% of total)\n", - format.formatByteSize(row->cost.leaked, 1, KFormat::MetricBinaryDialect), leakedFraction); + format.formatByteSize(row->cost.leaked, 1, KFormat::JEDECBinaryDialect), leakedFraction); stream << i18n("allocations: %1 (%2% of total)\n", row->cost.allocations, allocationsFraction); stream << i18n("temporary: %1 (%2% of allocations, %3% of total)\n", row->cost.temporary, temporaryFraction, temporaryFractionTotal); diff --git a/src/analyze/print/heaptrack_print.cpp b/src/analyze/print/heaptrack_print.cpp index fb9e05c..d342be2 100644 --- a/src/analyze/print/heaptrack_print.cpp +++ b/src/analyze/print/heaptrack_print.cpp @@ -68,7 +68,7 @@ ostream& operator<<(ostream& out, const formatBytes data) // handle negative values return out << '-' << formatBytes(-data.m_bytes); } - if (data.m_bytes < 1000) { + if (data.m_bytes < 1024) { // no fancy formatting for plain byte values, esp. no .00 factions return out << data.m_bytes << 'B'; } @@ -77,8 +77,8 @@ ostream& operator<<(ostream& out, const formatBytes data) auto unit = units.begin(); size_t i = 0; double bytes = data.m_bytes; - while (i < units.size() - 1 && bytes > 1000.) { - bytes /= 1000.; + while (i < units.size() - 1 && bytes > 1024.) { + bytes /= 1024.; ++i; ++unit; } -- cgit v1.2.3