Bug 1467734: Add ability to remove frames from CombinedStacks; r?Dexter draft
authorCarl Corcoran <ccorcoran@mozilla.com>
Fri, 08 Jun 2018 12:49:32 +0200
changeset 811379 4e8b4b6ea19f995b8d29629ece8fdaec8232470b
parent 808416 257c191e7903523a1132e04460a0b2460d950809
push id114285
push userbmo:ccorcoran@mozilla.com
push dateWed, 27 Jun 2018 14:35:15 +0000
reviewersDexter
bugs1467734
milestone62.0a1
Bug 1467734: Add ability to remove frames from CombinedStacks; r?Dexter MozReview-Commit-ID: EudrP5G3iaJ
toolkit/components/telemetry/CombinedStacks.cpp
toolkit/components/telemetry/CombinedStacks.h
--- a/toolkit/components/telemetry/CombinedStacks.cpp
+++ b/toolkit/components/telemetry/CombinedStacks.cpp
@@ -31,18 +31,19 @@ CombinedStacks::GetModuleCount() const {
 
 const Telemetry::ProcessedStack::Module&
 CombinedStacks::GetModule(unsigned aIndex) const {
   return mModules[aIndex];
 }
 
 size_t
 CombinedStacks::AddStack(const Telemetry::ProcessedStack& aStack) {
+  size_t index = mNextIndex;
   // Advance the indices of the circular queue holding the stacks.
-  size_t index = mNextIndex++ % mMaxStacksCount;
+  mNextIndex = (mNextIndex + 1) % mMaxStacksCount;
   // Grow the vector up to the maximum size, if needed.
   if (mStacks.size() < mMaxStacksCount) {
     mStacks.resize(mStacks.size() + 1);
   }
   // Get a reference to the location holding the new stack.
   CombinedStacks::Stack& adjustedStack = mStacks[index];
   // If we're using an old stack to hold aStack, clear it.
   adjustedStack.clear();
@@ -93,16 +94,35 @@ CombinedStacks::SizeOfExcludingThis() co
   n += mModules.capacity() * sizeof(Telemetry::ProcessedStack::Module);
   n += mStacks.capacity() * sizeof(Stack);
   for (const auto & s : mStacks) {
     n += s.capacity() * sizeof(Telemetry::ProcessedStack::Frame);
   }
   return n;
 }
 
+void
+CombinedStacks::RemoveStack(unsigned aIndex) {
+  MOZ_ASSERT(aIndex < mStacks.size());
+
+  mStacks.erase(mStacks.begin() + aIndex);
+
+  if (aIndex < mNextIndex) {
+    if (mNextIndex == 0) {
+      mNextIndex = mStacks.size();
+    } else {
+      mNextIndex--;
+    }
+  }
+
+  if (mNextIndex > mStacks.size()) {
+    mNextIndex = mStacks.size();
+  }
+}
+
 #if defined(MOZ_GECKO_PROFILER)
 void
 CombinedStacks::Clear() {
   mNextIndex = 0;
   mStacks.clear();
   mModules.clear();
 }
 #endif
--- a/toolkit/components/telemetry/CombinedStacks.h
+++ b/toolkit/components/telemetry/CombinedStacks.h
@@ -27,16 +27,17 @@ public:
 
   typedef std::vector<Telemetry::ProcessedStack::Frame> Stack;
   const Telemetry::ProcessedStack::Module& GetModule(unsigned aIndex) const;
   size_t GetModuleCount() const;
   const Stack& GetStack(unsigned aIndex) const;
   size_t AddStack(const Telemetry::ProcessedStack& aStack);
   size_t GetStackCount() const;
   size_t SizeOfExcludingThis() const;
+  void RemoveStack(unsigned aIndex);
 
 #if defined(MOZ_GECKO_PROFILER)
   /** Clears the contents of vectors and resets the index. */
   void Clear();
 #endif
 
 private:
   std::vector<Telemetry::ProcessedStack::Module> mModules;