[Lldb-commits] [lldb] r182627 - <rdar://problem/13643315>

Greg Clayton gclayton at apple.com
Thu May 23 17:58:30 PDT 2013


Author: gclayton
Date: Thu May 23 19:58:29 2013
New Revision: 182627

URL: http://llvm.org/viewvc/llvm-project?rev=182627&view=rev
Log:
<rdar://problem/13643315> 

Fixed performance issues that arose after changing SBTarget, SBProcess, SBThread and SBFrame over to using a std::shared_ptr to a ExecutionContextRef. The ExecutionContextRef doesn't store a std::weak_ptr to a stack frame because stack frames often get replaced with new version, so it held onto a StackID object that would allow us to ask the thread each time for the frame for the StackID. The linear function was too slow for large recursive stacks. We also fixed an issue where anytime the std::shared_ptr<ExecutionContextRef> in any SBTarget, SBProcess, SBThread objects was turned into an ExecutionContext object, it would try to resolve all items in the ExecutionContext which are shared pointers. Even if the StackID in the ExecutionContextRef was invalid, it was looking through all frames in every thread. This causes a lot of unnecessary frame accesses.


Modified:
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/source/Target/ExecutionContext.cpp
    lldb/trunk/source/Target/StackFrameList.cpp

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=182627&r1=182626&r2=182627&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Thu May 23 19:58:29 2013
@@ -381,7 +381,9 @@ public:
     virtual lldb::StackFrameSP
     GetFrameWithStackID (const StackID &stack_id)
     {
-        return GetStackFrameList()->GetFrameWithStackID (stack_id);
+        if (stack_id.IsValid())
+            return GetStackFrameList()->GetFrameWithStackID (stack_id);
+        return lldb::StackFrameSP();
     }
 
     uint32_t

Modified: lldb/trunk/source/Target/ExecutionContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ExecutionContext.cpp?rev=182627&r1=182626&r2=182627&view=diff
==============================================================================
--- lldb/trunk/source/Target/ExecutionContext.cpp (original)
+++ lldb/trunk/source/Target/ExecutionContext.cpp Thu May 23 19:58:29 2013
@@ -806,9 +806,12 @@ ExecutionContextRef::GetThreadSP () cons
 lldb::StackFrameSP
 ExecutionContextRef::GetFrameSP () const
 {
-    lldb::ThreadSP thread_sp (GetThreadSP());
-    if (thread_sp)
-        return thread_sp->GetFrameWithStackID (m_stack_id);
+    if (m_stack_id.IsValid())
+    {
+        lldb::ThreadSP thread_sp (GetThreadSP());
+        if (thread_sp)
+            return thread_sp->GetFrameWithStackID (m_stack_id);
+    }
     return lldb::StackFrameSP();
 }
 

Modified: lldb/trunk/source/Target/StackFrameList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrameList.cpp?rev=182627&r1=182626&r2=182627&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrameList.cpp (original)
+++ lldb/trunk/source/Target/StackFrameList.cpp Thu May 23 19:58:29 2013
@@ -595,19 +595,42 @@ StackFrameList::GetFrameWithConcreteFram
     return frame_sp;
 }
 
+static bool
+CompareStackID (const StackFrameSP &stack_sp, const StackID &stack_id)
+{
+    return stack_sp->GetStackID() < stack_id;
+}
+
 StackFrameSP
 StackFrameList::GetFrameWithStackID (const StackID &stack_id)
 {
-    uint32_t frame_idx = 0;
     StackFrameSP frame_sp;
-    do
+    
+    if (stack_id.IsValid())
     {
-        frame_sp = GetFrameAtIndex (frame_idx);
-        if (frame_sp && frame_sp->GetStackID() == stack_id)
-            break;
-        frame_idx++;
+        Mutex::Locker locker (m_mutex);
+        uint32_t frame_idx = 0;
+        // Do a binary search in case the stack frame is already in our cache
+        collection::const_iterator begin = m_frames.begin();
+        collection::const_iterator end = m_frames.end();
+        if (begin != end)
+        {
+            collection::const_iterator pos = std::lower_bound (begin, end, stack_id, CompareStackID);
+            if (pos != end && (*pos)->GetStackID() == stack_id)
+                return *pos;
+            
+            if (m_frames.back()->GetStackID() < stack_id)
+                frame_idx = m_frames.size();
+        }
+        do
+        {
+            frame_sp = GetFrameAtIndex (frame_idx);
+            if (frame_sp && frame_sp->GetStackID() == stack_id)
+                break;
+            frame_idx++;
+        }
+        while (frame_sp);
     }
-    while (frame_sp);
     return frame_sp;
 }
 





More information about the lldb-commits mailing list