Bug 1467734: Add ability to remove frames from CombinedStacks; r?Dexter
MozReview-Commit-ID: EudrP5G3iaJ
--- 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;