From 0f296aff8a85040bcd52584ab8051ab88a61e84e Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Mon, 21 Apr 2014 11:46:48 -0400 Subject: [PATCH] Bug 996285 - Profiler stops duplicating samples during sleeping periods after buffer wraps. r=benwa --- tools/profiler/ProfileEntry.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/profiler/ProfileEntry.cpp b/tools/profiler/ProfileEntry.cpp index d696a98de194..59da484ec508 100644 --- a/tools/profiler/ProfileEntry.cpp +++ b/tools/profiler/ProfileEntry.cpp @@ -462,13 +462,15 @@ mozilla::Mutex* ThreadProfile::GetMutex() void ThreadProfile::DuplicateLastSample() { // Scan the whole buffer (even unflushed parts) - // we add mEntrySize to mReadPos to make sure that when - // we wrap around the result is mEntrySize-1 and not -1 - for (int readPos = mWritePos; readPos != (mReadPos + mEntrySize - 1) % mEntrySize; readPos = (readPos + mEntrySize - 1) % mEntrySize) { - // Found the start of the last entry at position i + // Adding mEntrySize makes the result of the modulus positive + // We search backwards from mWritePos-1 to mReadPos + for (int readPos = (mWritePos + mEntrySize - 1) % mEntrySize; + readPos != (mReadPos + mEntrySize - 1) % mEntrySize; + readPos = (readPos + mEntrySize - 1) % mEntrySize) { if (mEntries[readPos].mTagName == 's') { + // Found the start of the last entry at position readPos int copyEndIdx = mWritePos; - // Go through the whole entry and duplicate it using a simple state machine + // Go through the whole entry and duplicate it for (;readPos != copyEndIdx; readPos = (readPos + 1) % mEntrySize) { switch (mEntries[readPos].mTagName) { // Copy with new time @@ -479,7 +481,7 @@ void ThreadProfile::DuplicateLastSample() { case 'm': break; // Copy anything else we don't know about - // L, B, S, m, c, s, d, l, f, h, r, t, p + // L, B, S, c, s, d, l, f, h, r, t, p default: addTag(mEntries[readPos]); break;