Track temporary allocations by their AllocationInfo index.
authorMilian Wolff <mail@milianw.de>
Sat, 4 Jun 2016 17:36:02 +0000 (19:36 +0200)
committerMilian Wolff <mail@milianw.de>
Sat, 4 Jun 2016 17:36:02 +0000 (19:36 +0200)
There is no need to output a boolean '1' for temporary allocations,
as we have the same information when looking at the AllocationInfo
index that corresponds to a unique size and location. I.e. we used
to output

+ 12
- 12 1
+ 42
- 43

But the same information is held by

+ 12
- 12
+ 42
- 43

CMakeLists.txt
accumulatedtracedata.cpp
heaptrack_interpret.cpp

index 7ae7ac0..3dd04c6 100644 (file)
@@ -8,7 +8,7 @@ if(NOT CMAKE_BUILD_TYPE)
 endif()
 
 set(HEAPTRACK_VERSION_MAJOR 1)
-set(HEAPTRACK_VERSION_MINOR 1)
+set(HEAPTRACK_VERSION_MINOR 2)
 set(HEAPTRACK_VERSION_PATCH 0)
 set(HEAPTRACK_LIB_VERSION 1.0.0)
 set(HEAPTRACK_LIB_SOVERSION 1)
index c0f455a..7e4e957 100644 (file)
@@ -166,6 +166,9 @@ bool AccumulatedTraceData::read(istream& in)
     // newer versions handle this in heaptrack_interpret already
     AllocationInfoSet allocationInfoSet;
     PointerMap pointers;
+    // in older files, this contains the pointer address, in newer formats
+    // it holds the allocation info index. both can be used to find temporary
+    // allocations, i.e. when a deallocation follows with the same data
     uint64_t lastAllocationPtr = 0;
 
     while (reader.getLine(in)) {
@@ -228,6 +231,7 @@ bool AccumulatedTraceData::read(istream& in)
                     continue;
                 }
                 info = allocationInfos[allocationIndex.index];
+                lastAllocationPtr = allocationIndex.index;
             } else { // backwards compatibility
                 uint64_t ptr = 0;
                 if (!(reader >> info.size) || !(reader >> info.traceIndex) || !(reader >> ptr)) {
@@ -266,9 +270,7 @@ bool AccumulatedTraceData::read(istream& in)
                     cerr << "failed to parse line: " << reader.line() << endl;
                     continue;
                 }
-                // optional, and thus may fail.
-                // but that's OK since we default to false anyways
-                reader >> temporary;
+                temporary = lastAllocationPtr == allocationInfoIndex.index;
             } else { // backwards compatibility
                 uint64_t ptr = 0;
                 if (!(reader >> ptr)) {
@@ -282,8 +284,8 @@ bool AccumulatedTraceData::read(istream& in)
                 }
                 allocationInfoIndex = taken.first;
                 temporary = lastAllocationPtr == ptr;
-                lastAllocationPtr = 0;
             }
+            lastAllocationPtr = 0;
 
             const auto& info = allocationInfos[allocationInfoIndex.index];
             auto& allocation = findAllocation(info.traceIndex);
index 942b3bf..206e21d 100644 (file)
@@ -404,12 +404,9 @@ int main(int /*argc*/, char** /*argv*/)
             if (!allocation.second) {
                 continue;
             }
-            fprintf(stdout, "- %x", allocation.first.index);
+            fprintf(stdout, "- %x\n", allocation.first.index);
             if (temporary) {
                 ++temporaryAllocations;
-                fputs(" 1\n", stdout);
-            } else {
-                fputc('\n', stdout);
             }
         } else {
             fputs(reader.line().c_str(), stdout);