Prettify output of top-allocator places.
authorMilian Wolff <mail@milianw.de>
Tue, 26 Aug 2014 00:01:56 +0000 (02:01 +0200)
committerMilian Wolff <mail@milianw.de>
Tue, 26 Aug 2014 00:01:56 +0000 (02:01 +0200)
TODO: do something similar in the other places as well.

heaptrack_print.cpp

index 24306d0..05c25d2 100644 (file)
@@ -572,19 +572,32 @@ int main(int argc, char** argv)
 
     if (printAllocs) {
         // sort by amount of allocations
+        cout << "MOST CALLS TO ALLOCATION FUNCTIONS\n";
         sort(data.mergedAllocations.begin(), data.mergedAllocations.end(),
             [] (const MergedAllocation& l, const MergedAllocation &r) {
                 return l.allocations > r.allocations;
             });
-        cout << "MOST CALLS TO ALLOCATION FUNCTIONS\n";
         for (size_t i = 0; i < min(10lu, data.mergedAllocations.size()); ++i) {
-            const auto& allocation = data.mergedAllocations[i];
-            cout << allocation.allocations << " allocations at:\n";
+            auto& allocation = data.mergedAllocations[i];
+            cout << allocation.allocations << " calls to allocation functions from:\n";
             data.printIp(allocation.ipIndex, cout);
-            for (const auto& trace : allocation.traces) {
-                cout << "  " << trace.allocations << " from:\n";
+
+            sort(allocation.traces.begin(), allocation.traces.end(),
+                [] (const Allocation& l, const Allocation &r) {
+                    return l.allocations > r.allocations;
+                });
+            size_t handled = 0;
+            const size_t subTracesToPrint = 5;
+            for (size_t j = 0; j < min(subTracesToPrint, allocation.traces.size()); ++j) {
+                const auto& trace = allocation.traces[j];
+                cout << "  " << trace.allocations << " calls from:\n";
+                handled += trace.allocations;
                 data.printBacktrace(trace.traceIndex, cout, 2, true);
             }
+            if (allocation.traces.size() > subTracesToPrint) {
+                cout << "  and " << (allocation.allocations - handled) << " calls from "
+                    << (allocation.traces.size() - subTracesToPrint) << " other places\n";
+            }
             cout << '\n';
         }
         cout << endl;