diff options
author | Christopher Ferris <cferris@google.com> | 2020-03-25 16:30:06 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2020-03-25 16:30:06 -0700 |
commit | 9ba7d4f88a2da41ee0b92a7378e5f31644a56de9 (patch) | |
tree | 1887b3116bd540343b9a20ff82c1b13934ef56d1 | |
parent | 8b20af65492c40293b4ab351fecbf55bc1ea8294 (diff) | |
download | extras-9ba7d4f88a2da41ee0b92a7378e5f31644a56de9.tar.gz |
Fix bug in maximum number of allocs.
The previous version was trying to do an estimate, but there was
no reason to do that. The data should be good enough to figure
out the exact maximum number of allocations needed at any one
time.
Test: Ran over trace that caused a problem before.
Change-Id: Iaa5825839b6632038a3f1275bd45846714abbced
-rw-r--r-- | memory_replay/main.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/memory_replay/main.cpp b/memory_replay/main.cpp index 9873ec70..e610305e 100644 --- a/memory_replay/main.cpp +++ b/memory_replay/main.cpp @@ -37,6 +37,7 @@ constexpr size_t kDefaultMaxThreads = 512; static size_t GetMaxAllocs(const AllocEntry* entries, size_t num_entries) { + size_t max_allocs = 0; size_t num_allocs = 0; for (size_t i = 0; i < num_entries; i++) { switch (entries[i].type) { @@ -45,15 +46,28 @@ static size_t GetMaxAllocs(const AllocEntry* entries, size_t num_entries) { case MALLOC: case CALLOC: case MEMALIGN: + if (entries[i].ptr != 0) { + num_allocs++; + } + break; case REALLOC: - num_allocs++; + if (entries[i].ptr == 0 && entries[i].u.old_ptr != 0) { + num_allocs--; + } else if (entries[i].ptr != 0 && entries[i].u.old_ptr == 0) { + num_allocs++; + } break; case FREE: - num_allocs--; + if (entries[i].ptr != 0) { + num_allocs--; + } break; } + if (num_allocs > max_allocs) { + max_allocs = num_allocs; + } } - return num_allocs; + return max_allocs; } static void ProcessDump(const AllocEntry* entries, size_t num_entries, size_t max_threads) { |