summaryrefslogtreecommitdiff
path: root/lldb/source/Target/StackFrameList.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-05-24 00:58:29 +0000
committerGreg Clayton <gclayton@apple.com>2013-05-24 00:58:29 +0000
commit7bcb93d5a5cd4effcb8ddb1fa1ac1b54716309e1 (patch)
tree297afeae0a9860918b6b6c9ebb56d266a9f11571 /lldb/source/Target/StackFrameList.cpp
parent48ed4b614cb055fa2f8a3948b284f0ad8730ec3f (diff)
<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. llvm-svn: 182627
Diffstat (limited to 'lldb/source/Target/StackFrameList.cpp')
-rw-r--r--lldb/source/Target/StackFrameList.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp
index ef798cbb13ab..69309dfae7b6 100644
--- a/lldb/source/Target/StackFrameList.cpp
+++ b/lldb/source/Target/StackFrameList.cpp
@@ -595,19 +595,42 @@ StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
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;
}