From: Milian Wolff Date: Sun, 7 Jun 2015 10:43:30 +0000 (+0200) Subject: Move some helper functions into the shared file, will use that later for tooltips X-Git-Tag: submit/tizen/20180620.112952^2~328^2~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=804d0c4767939e397d59cbf8b9b7dd74534eb44d;p=sdk%2Ftools%2Fheaptrack.git Move some helper functions into the shared file, will use that later for tooltips --- diff --git a/accumulatedtracedata.cpp b/accumulatedtracedata.cpp index ac96142..2e097ae 100644 --- a/accumulatedtracedata.cpp +++ b/accumulatedtracedata.cpp @@ -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); + }; +} diff --git a/accumulatedtracedata.h b/accumulatedtracedata.h index 156bad8..e0767df 100644 --- a/accumulatedtracedata.h +++ b/accumulatedtracedata.h @@ -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 stopIndices; std::unordered_map activeAllocations; diff --git a/heaptrack_print.cpp b/heaptrack_print.cpp index e197f6b..53c81a2 100644 --- a/heaptrack_print.cpp +++ b/heaptrack_print.cpp @@ -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 void printAllocations(T AllocationData::* member, LabelPrinter label, SubLabelPrinter sublabel) {