[test runner] Use allocation peak values for memory metrics

This commit is contained in:
Mikhail Pozdnyakov
2019-08-27 11:38:17 +03:00
parent 1b020eeb11
commit 766392f1f8
5 changed files with 25 additions and 10 deletions

View File

@@ -9,6 +9,7 @@
namespace {
std::atomic_size_t indexedMemorySize{0};
std::atomic_size_t indexedMemoryPeak{0};
std::atomic_size_t allocationsCount{0};
std::unordered_map<void*, size_t> memoryIndex;
std::atomic_bool suppresIndexing{false};
@@ -30,6 +31,7 @@ void addToIndex(std::size_t sz, void* ptr) {
FlagGuard flk(suppresIndexing);
allocationsCount++;
indexedMemorySize += sz;
if (indexedMemoryPeak < indexedMemorySize) indexedMemoryPeak = size_t(indexedMemorySize);
memoryIndex[ptr] = sz;
}
@@ -67,6 +69,7 @@ void AllocationIndex::reset() {
memoryIndex.clear();
indexedMemorySize = 0;
allocationsCount = 0;
indexedMemoryPeak = 0;
}
// static
@@ -91,3 +94,8 @@ size_t AllocationIndex::getAllocatedSize() {
size_t AllocationIndex::getAllocationsCount() {
return allocationsCount;
}
// static
size_t AllocationIndex::getAllocatedSizePeak() {
return indexedMemoryPeak;
}

View File

@@ -43,4 +43,11 @@ public:
* @return size_t
*/
static size_t getAllocationsCount();
};
/**
* @brief Returns the maximum size (in bytes) of the allocated data in the index, since last `reset()` call.
*
* @return size_t
*/
static size_t getAllocatedSizePeak();
};

View File

@@ -31,11 +31,11 @@ struct TestPaths {
struct MemoryProbe {
MemoryProbe() = default;
MemoryProbe(size_t size_, size_t allocations_)
: size(size_)
MemoryProbe(size_t peak_, size_t allocations_)
: peak(peak_)
, allocations(allocations_) {}
size_t size;
size_t peak;
size_t allocations;
};

View File

@@ -199,7 +199,7 @@ std::string serializeMetrics(const TestMetrics& metrics) {
assert(!memoryProbe.first.empty());
writer.StartArray();
writer.String(memoryProbe.first.c_str());
writer.Uint64(memoryProbe.second.size);
writer.Uint64(memoryProbe.second.peak);
writer.Uint64(memoryProbe.second.allocations);
writer.EndArray();
}

View File

@@ -131,10 +131,10 @@ bool TestRunner::checkResults(mbgl::PremultipliedImage&& actualImage, TestMetada
metadata.errorMessage = "Failed to find memory probe: " + expected.first;
return false;
}
if (actual->second.size > expected.second.size) {
if (actual->second.peak > expected.second.peak) {
std::stringstream ss;
ss << "Allocated size at memory probe \" " << expected.first << "\" is "
<< actual->second.size << " bytes, expected is " << expected.second.size << " bytes.";
ss << "Allocated memory peak size at probe \"" << expected.first << "\" is "
<< actual->second.peak << " bytes, expected is " << expected.second.peak << " bytes.";
metadata.errorMessage = ss.str();
return false;
@@ -142,7 +142,7 @@ bool TestRunner::checkResults(mbgl::PremultipliedImage&& actualImage, TestMetada
if (actual->second.allocations > expected.second.allocations) {
std::stringstream ss;
ss << "Number of allocations at memory probe \" " << expected.first << "\" is "
ss << "Number of allocations at probe \"" << expected.first << "\" is "
<< actual->second.allocations << ", expected is " << expected.second.allocations << ".";
metadata.errorMessage = ss.str();
@@ -447,7 +447,7 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) {
metadata.metrics.memory.emplace(std::piecewise_construct,
std::forward_as_tuple(std::move(mark)),
std::forward_as_tuple(AllocationIndex::getAllocatedSize(), AllocationIndex::getAllocationsCount()));
std::forward_as_tuple(AllocationIndex::getAllocatedSizePeak(), AllocationIndex::getAllocationsCount()));
// probeMemoryEnd
} else if (operationArray[0].GetString() == memoryProbeEndOp) {
assert(AllocationIndex::isActive());