Move some helper functions into the shared file, will use that later for tooltips
authorMilian Wolff <mail@milianw.de>
Sun, 7 Jun 2015 10:43:30 +0000 (12:43 +0200)
committerMilian Wolff <mail@milianw.de>
Sun, 7 Jun 2015 10:43:30 +0000 (12:43 +0200)
accumulatedtracedata.cpp
accumulatedtracedata.h
heaptrack_print.cpp

index ac96142..2e097ae 100644 (file)
@@ -444,3 +444,69 @@ void AccumulatedTraceData::filterAllocations()
         return true;
     }), allocations.end());
 }
+
+void AccumulatedTraceData::printIndent(ostream& out, size_t indent, const char* indentString) const
+{
+    while (indent--) {
+        out << indentString;
+    }
+}
+
+void AccumulatedTraceData::printIp(const IpIndex ip, ostream &out, const size_t indent) const
+{
+    printIp(findIp(ip), out, indent);
+}
+
+void AccumulatedTraceData::printIp(const InstructionPointer& ip, ostream& out, const size_t indent) const
+{
+    printIndent(out, indent);
+
+    if (ip.functionIndex) {
+        out << prettyFunction(stringify(ip.functionIndex));
+    } else {
+        out << "0x" << hex << ip.instructionPointer << dec;
+    }
+
+    out << '\n';
+    printIndent(out, indent + 1);
+
+    if (ip.fileIndex) {
+        out << "at " << stringify(ip.fileIndex) << ':' << ip.line << '\n';
+        printIndent(out, indent + 1);
+    }
+
+    if (ip.moduleIndex) {
+        out << "in " << stringify(ip.moduleIndex);
+    } else {
+        out << "in ??";
+    }
+    out << '\n';
+}
+
+void AccumulatedTraceData::printBacktrace(const TraceIndex traceIndex, ostream& out,
+                                          const size_t indent, bool skipFirst) const
+{
+    if (!traceIndex) {
+        out << "  ??";
+        return;
+    }
+    printBacktrace(findTrace(traceIndex), out, indent, skipFirst);
+}
+
+void AccumulatedTraceData::printBacktrace(TraceNode node, ostream& out, const size_t indent,
+                                          bool skipFirst) const
+{
+    while (node.ipIndex) {
+        const auto& ip = findIp(node.ipIndex);
+        if (!skipFirst) {
+            printIp(ip, out, indent);
+        }
+        skipFirst = false;
+
+        if (isStopIndex(ip.functionIndex)) {
+            break;
+        }
+
+        node = findTrace(node.parentIndex);
+    };
+}
index 156bad8..e0767df 100644 (file)
@@ -198,6 +198,14 @@ struct AccumulatedTraceData
 
     void filterAllocations();
 
+    void printIndent(std::ostream& out, size_t indent, const char* indentString = "  ") const;
+    void printIp(const IpIndex ip, std::ostream &out, const size_t indent = 0) const;
+    void printIp(const InstructionPointer& ip, std::ostream& out, const size_t indent = 0) const;
+    void printBacktrace(const TraceIndex traceIndex, std::ostream& out,
+                        const size_t indent = 0, bool skipFirst = false) const;
+    void printBacktrace(TraceNode node, std::ostream& out, const size_t indent = 0,
+                        bool skipFirst = false) const;
+
     // indices of functions that should stop the backtrace, e.g. main or static initialization
     std::vector<StringIndex> stopIndices;
     std::unordered_map<uintptr_t, AllocationInfo> activeAllocations;
index e197f6b..53c81a2 100644 (file)
@@ -36,72 +36,6 @@ namespace po = boost::program_options;
 
 struct Printer final : public AccumulatedTraceData
 {
-    void printIp(const IpIndex ip, ostream &out, const size_t indent = 0) const
-    {
-        printIp(findIp(ip), out, indent);
-    }
-
-    void printIndent(ostream& out, size_t indent, const char* indentString = "  ") const
-    {
-        while (indent--) {
-            out << indentString;
-        }
-    }
-
-    void printIp(const InstructionPointer& ip, ostream& out, const size_t indent = 0) const
-    {
-        printIndent(out, indent);
-
-        if (ip.functionIndex) {
-            out << prettyFunction(stringify(ip.functionIndex));
-        } else {
-            out << "0x" << hex << ip.instructionPointer << dec;
-        }
-
-        out << '\n';
-        printIndent(out, indent + 1);
-
-        if (ip.fileIndex) {
-            out << "at " << stringify(ip.fileIndex) << ':' << ip.line << '\n';
-            printIndent(out, indent + 1);
-        }
-
-        if (ip.moduleIndex) {
-            out << "in " << stringify(ip.moduleIndex);
-        } else {
-            out << "in ??";
-        }
-        out << '\n';
-    }
-
-    void printBacktrace(const TraceIndex traceIndex, ostream& out,
-                        const size_t indent = 0, bool skipFirst = false) const
-    {
-        if (!traceIndex) {
-            out << "  ??";
-            return;
-        }
-        printBacktrace(findTrace(traceIndex), out, indent, skipFirst);
-    }
-
-    void printBacktrace(TraceNode node, ostream& out, const size_t indent = 0,
-                        bool skipFirst = false) const
-    {
-        while (node.ipIndex) {
-            const auto& ip = findIp(node.ipIndex);
-            if (!skipFirst) {
-                printIp(ip, out, indent);
-            }
-            skipFirst = false;
-
-            if (isStopIndex(ip.functionIndex)) {
-                break;
-            }
-
-            node = findTrace(node.parentIndex);
-        };
-    }
-
     template<typename T, typename LabelPrinter, typename SubLabelPrinter>
     void printAllocations(T AllocationData::* member, LabelPrinter label, SubLabelPrinter sublabel)
     {