Fix visualization of memory consumption values (use 2^10 instead of 10^3 as divisor...
authorRuben Ayrapetyan <r.ayrapetyan@samsung.com>
Fri, 15 Sep 2017 19:23:05 +0000 (22:23 +0300)
committerRuben Ayrapetyan <r.ayrapetyan@samsung.com>
Fri, 15 Sep 2017 19:23:04 +0000 (22:23 +0300)
src/analyze/gui/callercalleemodel.cpp
src/analyze/gui/chartmodel.cpp
src/analyze/gui/chartwidget.cpp
src/analyze/gui/flamegraph.cpp
src/analyze/gui/histogramwidget.cpp
src/analyze/gui/mainwindow.cpp
src/analyze/gui/treemodel.cpp
src/analyze/print/heaptrack_print.cpp

index b6888c7..5ce63d9 100644 (file)
@@ -183,7 +183,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const
             if (role == SortRole || role == MaxCostRole) {
                 return static_cast<qint64>(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<qint64>(row.selfCost.allocations);
@@ -193,7 +193,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const
             if (role == SortRole || role == MaxCostRole) {
                 return static_cast<qint64>(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<qint64>(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<qint64>(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<qint64>(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<qint64>(row.inclusiveCost.allocations);
@@ -217,7 +217,7 @@ QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const
             if (role == SortRole || role == MaxCostRole) {
                 return static_cast<qint64>(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<qint64>(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<qint64>(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 << "</pre></qt>";
         return tooltip;
index b6858f7..1db0ac9 100644 (file)
@@ -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);
index 01086f4..fbbc05d 100644 (file)
@@ -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);
     }
 };
 }
index 07ba90f..5a27d9c 100644 (file)
@@ -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<RowData>& 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);
index 8f38b43..44b1695 100644 (file)
@@ -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);
     }
 };
 
index 4f7a862..16f1404 100644 (file)
@@ -288,7 +288,7 @@ MainWindow::MainWindow(QWidget* parent)
                    // xgettext:no-c-format
                    << i18n("<dt><b>total runtime</b>:</dt><dd>%1s</dd>", totalTimeS)
                    << i18n("<dt><b>total system memory</b>:</dt><dd>%1</dd>",
-                           format.formatByteSize(data.totalSystemMemory, 1, KFormat::MetricBinaryDialect))
+                           format.formatByteSize(data.totalSystemMemory, 1, KFormat::JEDECBinaryDialect))
                    << "</dl></qt>";
         }
 
@@ -306,8 +306,8 @@ MainWindow::MainWindow(QWidget* parent)
                            qint64(data.cost.temporary / totalTimeS))
                    << i18n("<dt><b>bytes allocated in total</b> (ignoring "
                            "deallocations):</dt><dd>%1 (%2/s)</dd>",
-                           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))
                    << "</dl></qt>";
         }
         if (AccumulatedTraceData::isShowCoreCLRPartOption)
@@ -364,13 +364,13 @@ MainWindow::MainWindow(QWidget* parent)
             QTextStream stream(&textRight);
             stream << "<qt><dl>" << i18n("<dt><b>peak heap memory consumption</b>:</dt><dd>%1 "
                                          "after %2s</dd>",
-                                         format.formatByteSize(data.cost.peak, 1, KFormat::MetricBinaryDialect),
+                                         format.formatByteSize(data.cost.peak, 1, KFormat::JEDECBinaryDialect),
                                          peakTimeS)
                    << i18n("<dt><b>peak RSS</b> (including heaptrack "
                            "overhead):</dt><dd>%1</dd>",
-                           format.formatByteSize(data.peakRSS, 1, KFormat::MetricBinaryDialect))
+                           format.formatByteSize(data.peakRSS, 1, KFormat::JEDECBinaryDialect))
                    << i18n("<dt><b>total memory leaked</b>:</dt><dd>%1</dd>",
-                           format.formatByteSize(data.cost.leaked, 1, KFormat::MetricBinaryDialect))
+                           format.formatByteSize(data.cost.leaked, 1, KFormat::JEDECBinaryDialect))
                    << "</dl></qt>";
         }
 
index 936c278..09b6b6c 100644 (file)
@@ -165,7 +165,7 @@ QVariant TreeModel::data(const QModelIndex& index, int role) const
             if (role == SortRole || role == MaxCostRole) {
                 return static_cast<qint64>(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<qint64>(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<qint64>(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<qint64>(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);
index fb9e05c..d342be2 100644 (file)
@@ -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;
     }