forked from qt-creator/qt-creator
Fix memory usage model details
Use the same format for all memory size strings, don't pack numbers into QString, and adapt the test. Change-Id: I13de737992fb64fadc61c3e3243ff83c14446e99 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -97,6 +97,15 @@ QVariantList MemoryUsageModel::labels() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int toSameSignedInt(qint64 number)
|
||||||
|
{
|
||||||
|
if (number > std::numeric_limits<int>::max())
|
||||||
|
return std::numeric_limits<int>::max();
|
||||||
|
if (number < std::numeric_limits<int>::min())
|
||||||
|
return std::numeric_limits<int>::min();
|
||||||
|
return static_cast<int>(number);
|
||||||
|
}
|
||||||
|
|
||||||
QVariantMap MemoryUsageModel::details(int index) const
|
QVariantMap MemoryUsageModel::details(int index) const
|
||||||
{
|
{
|
||||||
QVariantMap result;
|
QVariantMap result;
|
||||||
@@ -107,14 +116,17 @@ QVariantMap MemoryUsageModel::details(int index) const
|
|||||||
else
|
else
|
||||||
result.insert(QLatin1String("displayName"), tr("Memory Freed"));
|
result.insert(QLatin1String("displayName"), tr("Memory Freed"));
|
||||||
|
|
||||||
result.insert(tr("Total"), tr("%n byte(s)", nullptr, ev->size));
|
result.insert(tr("Total"), tr("%1 byte(s)", nullptr, toSameSignedInt(ev->size)).arg(ev->size));
|
||||||
if (ev->allocations > 0) {
|
if (ev->allocations > 0) {
|
||||||
result.insert(tr("Allocated"), tr("%1 bytes").arg(ev->allocated));
|
result.insert(tr("Allocated"), tr("%1 byte(s)", nullptr, toSameSignedInt(ev->allocated))
|
||||||
result.insert(tr("Allocations"), QString::number(ev->allocations));
|
.arg(ev->allocated));
|
||||||
|
result.insert(tr("Allocations"), ev->allocations);
|
||||||
}
|
}
|
||||||
if (ev->deallocations > 0) {
|
if (ev->deallocations > 0) {
|
||||||
result.insert(tr("Deallocated"), tr("%1 bytes").arg(-ev->deallocated));
|
result.insert(tr("Deallocated"),
|
||||||
result.insert(tr("Deallocations"), QString::number(ev->deallocations));
|
tr("%1 byte(s)", nullptr, toSameSignedInt(-ev->deallocated))
|
||||||
|
.arg(-ev->deallocated));
|
||||||
|
result.insert(tr("Deallocations"), ev->deallocations);
|
||||||
}
|
}
|
||||||
QString memoryTypeName;
|
QString memoryTypeName;
|
||||||
switch (selectionId(index)) {
|
switch (selectionId(index)) {
|
||||||
|
|||||||
@@ -149,8 +149,10 @@ void MemoryUsageModelTest::testDetails()
|
|||||||
{
|
{
|
||||||
const QVariantMap allocated = model.details(0);
|
const QVariantMap allocated = model.details(0);
|
||||||
QCOMPARE(allocated[QString("displayName")].toString(), model.tr("Memory Allocated"));
|
QCOMPARE(allocated[QString("displayName")].toString(), model.tr("Memory Allocated"));
|
||||||
QCOMPARE(allocated[model.tr("Total")].toString(), model.tr("%1 bytes").arg(4096));
|
QCOMPARE(allocated[model.tr("Total")].toString(),
|
||||||
QCOMPARE(allocated[model.tr("Allocated")].toString(), model.tr("%1 bytes").arg(4096));
|
model.tr("%1 byte(s)", nullptr, 4096).arg(4096));
|
||||||
|
QCOMPARE(allocated[model.tr("Allocated")].toString(),
|
||||||
|
model.tr("%1 byte(s)", nullptr, 4096).arg(4096));
|
||||||
QCOMPARE(allocated[model.tr("Allocations")].toString(), QString::number(2));
|
QCOMPARE(allocated[model.tr("Allocations")].toString(), QString::number(2));
|
||||||
QCOMPARE(allocated[model.tr("Type")].toString(), model.tr("Heap Allocation"));
|
QCOMPARE(allocated[model.tr("Type")].toString(), model.tr("Heap Allocation"));
|
||||||
QCOMPARE(allocated[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
QCOMPARE(allocated[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
||||||
@@ -160,8 +162,10 @@ void MemoryUsageModelTest::testDetails()
|
|||||||
|
|
||||||
const QVariantMap large = model.details(2);
|
const QVariantMap large = model.details(2);
|
||||||
QCOMPARE(large[QString("displayName")].toString(), model.tr("Memory Allocated"));
|
QCOMPARE(large[QString("displayName")].toString(), model.tr("Memory Allocated"));
|
||||||
QCOMPARE(large[model.tr("Total")].toString(), model.tr("%1 bytes").arg(5120));
|
QCOMPARE(large[model.tr("Total")].toString(),
|
||||||
QCOMPARE(large[model.tr("Allocated")].toString(), model.tr("%1 bytes").arg(1024));
|
model.tr("%1 byte(s)", nullptr, 5120).arg(5120));
|
||||||
|
QCOMPARE(large[model.tr("Allocated")].toString(),
|
||||||
|
model.tr("%1 byte(s)", nullptr, 1024).arg(1024));
|
||||||
QCOMPARE(large[model.tr("Allocations")].toString(), QString::number(1));
|
QCOMPARE(large[model.tr("Allocations")].toString(), QString::number(1));
|
||||||
QCOMPARE(large[model.tr("Type")].toString(), model.tr("Large Item Allocation"));
|
QCOMPARE(large[model.tr("Type")].toString(), model.tr("Large Item Allocation"));
|
||||||
QCOMPARE(large[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
QCOMPARE(large[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
||||||
@@ -171,8 +175,10 @@ void MemoryUsageModelTest::testDetails()
|
|||||||
|
|
||||||
const QVariantMap freed = model.details(9);
|
const QVariantMap freed = model.details(9);
|
||||||
QCOMPARE(freed[QString("displayName")].toString(), model.tr("Memory Freed"));
|
QCOMPARE(freed[QString("displayName")].toString(), model.tr("Memory Freed"));
|
||||||
QCOMPARE(freed[model.tr("Total")].toString(), model.tr("%1 bytes").arg(2048));
|
QCOMPARE(freed[model.tr("Total")].toString(),
|
||||||
QCOMPARE(freed[model.tr("Deallocated")].toString(), model.tr("%1 bytes").arg(1024));
|
model.tr("%1 byte(s)", nullptr, 2048).arg(2048));
|
||||||
|
QCOMPARE(freed[model.tr("Deallocated")].toString(),
|
||||||
|
model.tr("%1 byte(s)", nullptr, 1024).arg(1024));
|
||||||
QCOMPARE(freed[model.tr("Deallocations")].toString(), QString::number(1));
|
QCOMPARE(freed[model.tr("Deallocations")].toString(), QString::number(1));
|
||||||
QCOMPARE(freed[model.tr("Type")].toString(), model.tr("Heap Usage"));
|
QCOMPARE(freed[model.tr("Type")].toString(), model.tr("Heap Usage"));
|
||||||
QCOMPARE(freed[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
QCOMPARE(freed[model.tr("Location")].toString(), QmlProfilerModelManager::tr("<bytecode>"));
|
||||||
|
|||||||
Reference in New Issue
Block a user