Bug 996285 - Profiler stops duplicating samples during sleeping periods after buffer wraps. r=benwa
authorViktor Stanchev <vstanchev@mozilla.com>
Mon, 21 Apr 2014 11:46:48 -0400
changeset 179809 408e7a1d91a1758b8fdc9451c0de88e049c9f4ea
parent 179808 a0daa735e86571693584755f2b4badd67ce3a2d3
child 179810 a61517ca13ace8eace698c9066be62131ccef0fb
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbenwa
bugs996285
milestone31.0a1
Bug 996285 - Profiler stops duplicating samples during sleeping periods after buffer wraps. r=benwa
tools/profiler/ProfileEntry.cpp
--- a/tools/profiler/ProfileEntry.cpp
+++ b/tools/profiler/ProfileEntry.cpp
@@ -457,34 +457,36 @@ void ThreadProfile::EndUnwind()
 
 mozilla::Mutex* ThreadProfile::GetMutex()
 {
   return &mMutex;
 }
 
 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
           case 't':
             addTag(ProfileEntry('t', static_cast<float>((mozilla::TimeStamp::Now() - sStartTime).ToMilliseconds())));
             break;
           // Don't copy markers
           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;
         }
       }
       break;
     }
   }