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 197899 408e7a1d91a1758b8fdc9451c0de88e049c9f4ea
parent 197898 a0daa735e86571693584755f2b4badd67ce3a2d3
child 197900 a61517ca13ace8eace698c9066be62131ccef0fb
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenwa
bugs996285
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
     }
   }