Support --hide-unmanaged-stacks option.
authorRuben Ayrapetyan <r.ayrapetyan@samsung.com>
Fri, 15 Sep 2017 18:14:06 +0000 (21:14 +0300)
committerRuben Ayrapetyan <r.ayrapetyan@samsung.com>
Fri, 15 Sep 2017 18:11:24 +0000 (21:11 +0300)
src/analyze/accumulatedtracedata.cpp
src/analyze/accumulatedtracedata.h
src/analyze/gui/gui.cpp
src/analyze/gui/parser.cpp
src/interpret/heaptrack_interpret.cpp
src/track/tracetree.h

index d5f643bbb2853f5830b7cb6b590b47f4e7e9fa2a..e1db0058e5e6f1752889e28b56d31e1a6eb98d54 100644 (file)
@@ -41,6 +41,8 @@ using namespace std;
 
 AllocationData::DisplayId AllocationData::display = AllocationData::DisplayId::malloc;
 
+bool AccumulatedTraceData::isHideUnmanagedStackParts = false;
+
 namespace {
 
 template <typename Base>
@@ -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;
index 43eb47f361f4ddab90f48729f80f4e4330bbb109..8a4cbfd9aa29cb89c88c4a73312c995333e2dbde 100644 (file)
@@ -59,6 +59,7 @@ struct InstructionPointer
     uint64_t moduleOffset = 0;
     Frame frame;
     std::vector<Frame> inlined;
+    int isManaged;
 
     bool compareWithoutAddress(const InstructionPointer& other) const
     {
@@ -336,6 +337,8 @@ struct AccumulatedTraceData
     std::vector<AllocationInfo> allocationInfos;
 
     AddressRangesMap addressRangeInfos;
+
+    static bool isHideUnmanagedStackParts;
 };
 
 #endif // ACCUMULATEDTRACEDATA_H
index 529eb3c33da0d5b8c1070e9f09050d23a23fefc0..7b5d5948782ce6d62301f854390d32b4b0fc4364 100644 (file)
@@ -22,6 +22,7 @@
 #include <KAboutData>
 #include <KLocalizedString>
 
+#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);
index 4741ad942d268401553ce7a83055cb360a81d697..95395d2d98ec33165d5c788e75f71d9e39f84602 100644 (file)
@@ -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;
             }
index 761d5b549e4cfe0d9b0aac7ebeb4abc501400893..927adbc8d9c39fe610ea9b38cd50b6f77027a4fb 100644 (file)
@@ -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 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 %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) {
index 1aacd827f0f7417b51316475596165565f7f6945..f43b5fad765c53a50885a940ca40cdab16d46583 100644 (file)
@@ -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<void *>(stackIter->m_funcId);