From: Ruben Ayrapetyan Date: Fri, 15 Sep 2017 18:14:06 +0000 (+0300) Subject: Support --hide-unmanaged-stacks option. X-Git-Tag: submit/tizen/20180620.112952^2~33^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a38947a4049e097d1df794d595be3743c2e5139;p=sdk%2Ftools%2Fheaptrack.git Support --hide-unmanaged-stacks option. --- diff --git a/src/analyze/accumulatedtracedata.cpp b/src/analyze/accumulatedtracedata.cpp index d5f643b..e1db005 100644 --- a/src/analyze/accumulatedtracedata.cpp +++ b/src/analyze/accumulatedtracedata.cpp @@ -41,6 +41,8 @@ using namespace std; AllocationData::DisplayId AllocationData::display = AllocationData::DisplayId::malloc; +bool AccumulatedTraceData::isHideUnmanagedStackParts = false; + namespace { template @@ -228,6 +230,20 @@ bool AccumulatedTraceData::read(istream& in, const ParsePass pass) while (find(opNewIpIndices.begin(), opNewIpIndices.end(), node.ipIndex) != opNewIpIndices.end()) { node = findTrace(node.parentIndex); } + + if (isHideUnmanagedStackParts) { + while (node.ipIndex) { + const auto& ip = findIp(node.ipIndex); + + if (ip.isManaged) + { + break; + } + + node = findTrace(node.parentIndex); + } + } + traces.push_back(node); } else if (reader.mode() == 'i') { if (pass != FirstPass) { @@ -235,6 +251,7 @@ bool AccumulatedTraceData::read(istream& in, const ParsePass pass) } InstructionPointer ip; reader >> ip.instructionPointer; + reader >> ip.isManaged; reader >> ip.moduleIndex; reader >> ip.moduleOffset; diff --git a/src/analyze/accumulatedtracedata.h b/src/analyze/accumulatedtracedata.h index 43eb47f..8a4cbfd 100644 --- a/src/analyze/accumulatedtracedata.h +++ b/src/analyze/accumulatedtracedata.h @@ -59,6 +59,7 @@ struct InstructionPointer uint64_t moduleOffset = 0; Frame frame; std::vector inlined; + int isManaged; bool compareWithoutAddress(const InstructionPointer& other) const { @@ -336,6 +337,8 @@ struct AccumulatedTraceData std::vector allocationInfos; AddressRangesMap addressRangeInfos; + + static bool isHideUnmanagedStackParts; }; #endif // ACCUMULATEDTRACEDATA_H diff --git a/src/analyze/gui/gui.cpp b/src/analyze/gui/gui.cpp index 529eb3c..7b5d594 100644 --- a/src/analyze/gui/gui.cpp +++ b/src/analyze/gui/gui.cpp @@ -22,6 +22,7 @@ #include #include +#include "../accumulatedtracedata.h" #include "../allocationdata.h" #include "mainwindow.h" @@ -65,6 +66,9 @@ int main(int argc, char** argv) parser.addOption(showPrivateCleanOption); parser.addOption(showSharedOption); + QCommandLineOption hideUnmanagedStackPartsOption(QStringLiteral("hide-unmanaged-stacks"), QStringLiteral("Hide unmanaged parts of call stacks")); + parser.addOption(hideUnmanagedStackPartsOption); + parser.process(app); aboutData.processCommandLine(&parser); @@ -72,6 +76,7 @@ int main(int argc, char** argv) bool isShowPrivateDirty = parser.isSet(showPrivateDirtyOption); bool isShowPrivateClean = parser.isSet(showPrivateCleanOption); bool isShowShared = parser.isSet(showSharedOption); + bool isHideUnmanagedStackParts = parser.isSet(hideUnmanagedStackPartsOption); if ((isShowMalloc ? 1 : 0) + (isShowPrivateDirty ? 1 : 0) @@ -94,6 +99,10 @@ int main(int argc, char** argv) AllocationData::display = AllocationData::DisplayId::shared; } + if (isHideUnmanagedStackParts) { + AccumulatedTraceData::isHideUnmanagedStackParts = true; + } + auto createWindow = []() -> MainWindow* { auto window = new MainWindow; window->setAttribute(Qt::WA_DeleteOnClose); diff --git a/src/analyze/gui/parser.cpp b/src/analyze/gui/parser.cpp index 4741ad9..95395d2 100644 --- a/src/analyze/gui/parser.cpp +++ b/src/analyze/gui/parser.cpp @@ -364,12 +364,14 @@ TreeData mergeAllocations(const ParserData& data, bool bIncludeLeaves) const auto& trace = data.findTrace(traceIndex); const auto& ip = data.findIp(trace.ipIndex); - auto location = data.stringCache.location(trace.ipIndex, ip, isUntrackedLocation); - rows = addRow(rows, location, *stats); - for (const auto& inlined : ip.inlined) { - auto inlinedLocation = data.stringCache.frameLocation(inlined, ip, isUntrackedLocation); - rows = addRow(rows, inlinedLocation, *stats); - } + if (!(AccumulatedTraceData::isHideUnmanagedStackParts && !ip.isManaged)) { + auto location = data.stringCache.location(trace.ipIndex, ip, isUntrackedLocation); + rows = addRow(rows, location, *stats); + for (const auto& inlined : ip.inlined) { + auto inlinedLocation = data.stringCache.frameLocation(inlined, ip, isUntrackedLocation); + rows = addRow(rows, inlinedLocation, *stats); + } + } if (data.isStopIndex(ip.frame.functionIndex)) { break; } diff --git a/src/interpret/heaptrack_interpret.cpp b/src/interpret/heaptrack_interpret.cpp index 761d5b5..927adbc 100644 --- a/src/interpret/heaptrack_interpret.cpp +++ b/src/interpret/heaptrack_interpret.cpp @@ -302,10 +302,10 @@ struct AccumulatedTraceData if (isManaged) { size_t functionIndex = intern(m_managedNames[instructionPointer]); - fprintf(stdout, "i %llx 0 0 %zx\n", (1ull << 63) | instructionPointer, functionIndex); + fprintf(stdout, "i %llx 1 0 0 %zx\n", (1ull << 63) | instructionPointer, functionIndex); } else { const auto ip = resolve(instructionPointer); - fprintf(stdout, "i %zx %zx %zx", instructionPointer, ip.moduleIndex, ip.frame.moduleOffset); + fprintf(stdout, "i %zx 0 %zx %zx", instructionPointer, ip.moduleIndex, ip.frame.moduleOffset); if (ip.frame.functionIndex || ip.frame.fileIndex) { fprintf(stdout, " %zx", ip.frame.functionIndex); if (ip.frame.fileIndex) { diff --git a/src/track/tracetree.h b/src/track/tracetree.h index 1aacd82..f43b5fa 100644 --- a/src/track/tracetree.h +++ b/src/track/tracetree.h @@ -93,7 +93,7 @@ public: void* managedStack[Trace::MAX_SIZE]; int managedStackSize = 0; - managedStack[managedStackSize++] = (void *) (uintptr_t) -1; + handleIP((void *) (uintptr_t) -1, false); while (stackIter != nullptr && managedStackSize < Trace::MAX_SIZE) { void *ip = reinterpret_cast(stackIter->m_funcId);