Bug 788400 - Part 2: Add a frame number to profiles. r=ehsan
authorBenoit Girard <b56girard@gmail.com>
Wed, 05 Sep 2012 11:45:17 -0400
changeset 104319 308fd7da03e659441b71855568a0d2bc879c646c
parent 104318 9000cfd0f51a0c52ac0df54fda8560ebb2863a58
child 104320 9235cf9dadaa3df30199d522b1a27a63bdbd5fca
push id14462
push userb56girard@gmail.com
push dateWed, 05 Sep 2012 21:32:11 +0000
treeherdermozilla-inbound@9235cf9dadaa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs788400
milestone18.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 788400 - Part 2: Add a frame number to profiles. r=ehsan
gfx/layers/opengl/LayerManagerOGL.cpp
tools/profiler/TableTicker.cpp
tools/profiler/sampler.h
tools/profiler/sps_sampler.h
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -752,31 +752,32 @@ LayerManagerOGL::RootLayer() const
 
 bool LayerManagerOGL::sDrawFPS = false;
 bool LayerManagerOGL::sFrameCounter = false;
 
 static uint16_t sFrameCount = 0;
 void
 FPSState::DrawFrameCounter(GLContext* context)
 {
-
-  // We intentionally overflow at 2^16.
-  uint16_t frameNumber = sFrameCount++;
+  SAMPLER_FRAME_NUMBER(sFrameCount);
+  uint16_t frameNumber = sFrameCount;
   for (size_t i = 0; i < 16; i++) {
     context->fScissor(3*i, 0, 3, 3);
 
     // We should do this using a single draw call
     // instead of 16 glClear()
     if ((frameNumber >> i) & 0x1) {
       context->fClearColor(0.0, 0.0, 0.0, 0.0);
     } else {
       context->fClearColor(1.0, 1.0, 1.0, 0.0);
     }
     context->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
   }
+  // We intentionally overflow at 2^16.
+  sFrameCount++;
 }
 
 // |aTexCoordRect| is the rectangle from the texture that we want to
 // draw using the given program.  The program already has a necessary
 // offset and scale, so the geometry that needs to be drawn is a unit
 // square from 0,0 to 1,1.
 //
 // |aTexSize| is the actual size of the texture, as it can be larger
@@ -970,17 +971,17 @@ LayerManagerOGL::Render()
     mFPS = new FPSState();
   } else if (!sDrawFPS && mFPS) {
     mFPS = nullptr;
   }
 
   if (mFPS) {
     mFPS->DrawFPS(TimeStamp::Now(), mGLContext, GetProgram(Copy2DProgramType));
   } else if (sFrameCounter) {
-    DrawFrameCounter(mGLContext);
+    FPSState::DrawFrameCounter(mGLContext);
   }
 
   if (mGLContext->IsDoubleBuffered()) {
     mGLContext->SwapBuffers();
     LayerManager::PostPresent();
     mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
     return;
   }
--- a/tools/profiler/TableTicker.cpp
+++ b/tools/profiler/TableTicker.cpp
@@ -90,16 +90,18 @@ mozilla::ThreadLocal<ProfileStack *> tls
 mozilla::ThreadLocal<TableTicker *> tlsTicker;
 // We need to track whether we've been initialized otherwise
 // we end up using tlsStack without initializing it.
 // Because tlsStack is totally opaque to us we can't reuse
 // it as the flag itself.
 bool stack_key_initialized;
 
 TimeStamp sLastTracerEvent;
+int sFrameNumber = 0;
+int sLastFrameNumber = 0;
 
 class ThreadProfile;
 
 class ProfileEntry
 {
 public:
   ProfileEntry()
     : mTagData(NULL)
@@ -314,16 +316,23 @@ public:
           break;
         case 'r':
           {
             if (sample) {
               b.DefineProperty(sample, "responsiveness", entry.mTagFloat);
             }
           }
           break;
+        case 'f':
+          {
+            if (sample) {
+              b.DefineProperty(sample, "frameNumber", entry.mTagLine);
+            }
+          }
+          break;
         case 't':
           {
             if (sample) {
               b.DefineProperty(sample, "time", entry.mTagFloat);
             }
           }
           break;
         case 'c':
@@ -921,16 +930,21 @@ void TableTicker::Tick(TickSample* sampl
     TimeDuration delta = sample->timestamp - sLastTracerEvent;
     mPrimaryThreadProfile.addTag(ProfileEntry('r', delta.ToMilliseconds()));
   }
 
   if (sample) {
     TimeDuration delta = sample->timestamp - mStartTime;
     mPrimaryThreadProfile.addTag(ProfileEntry('t', delta.ToMilliseconds()));
   }
+
+  if (sLastFrameNumber != sFrameNumber) {
+    mPrimaryThreadProfile.addTag(ProfileEntry('f', sFrameNumber));
+    sLastFrameNumber = sFrameNumber;
+  }
 }
 
 std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile)
 {
   int readPos = profile.mReadPos;
   while (readPos != profile.mLastFlushPos) {
     stream << profile.mEntries[readPos];
     readPos = (readPos + 1) % profile.mEntrySize;
@@ -1138,8 +1152,12 @@ void mozilla_sampler_responsiveness(Time
   sLastTracerEvent = aTime;
 }
 
 const double* mozilla_sampler_get_responsiveness()
 {
   return sResponsivenessTimes;
 }
 
+void mozilla_sampler_frame_number(int frameNumber)
+{
+  sFrameNumber = frameNumber;
+}
--- a/tools/profiler/sampler.h
+++ b/tools/profiler/sampler.h
@@ -63,16 +63,17 @@
 #define SAMPLER_START(entries, interval, features, featureCount)
 #define SAMPLER_STOP()
 #define SAMPLER_IS_ACTIVE() false
 #define SAMPLER_SAVE()
 // Returned string must be free'ed
 #define SAMPLER_GET_PROFILE() NULL
 #define SAMPLER_GET_PROFILE_DATA(ctx) NULL
 #define SAMPLER_RESPONSIVENESS(time) NULL
+#define SAMPLER_FRAME_NUMBER(frameNumber)
 #define SAMPLER_GET_RESPONSIVENESS() NULL
 #define SAMPLER_GET_FEATURES() NULL
 #define SAMPLE_LABEL(name_space, info)
 // Provide a default literal string to use if profiling is disabled
 // and a printf argument to be computed if profiling is enabled.
 // NOTE: This will store the formated string on the stack and consume
 //       over 128 bytes on the stack.
 #define SAMPLE_LABEL_PRINTF(name_space, info, format, ...)
--- a/tools/profiler/sps_sampler.h
+++ b/tools/profiler/sps_sampler.h
@@ -43,16 +43,17 @@ extern bool stack_key_initialized;
 
 #define SAMPLER_INIT() mozilla_sampler_init()
 #define SAMPLER_DEINIT() mozilla_sampler_deinit()
 #define SAMPLER_START(entries, interval, features, featureCount) mozilla_sampler_start(entries, interval, features, featureCount)
 #define SAMPLER_STOP() mozilla_sampler_stop()
 #define SAMPLER_IS_ACTIVE() mozilla_sampler_is_active()
 #define SAMPLER_RESPONSIVENESS(time) mozilla_sampler_responsiveness(time)
 #define SAMPLER_GET_RESPONSIVENESS() mozilla_sampler_get_responsiveness()
+#define SAMPLER_FRAME_NUMBER(frameNumber) mozilla_sampler_frame_number(frameNumber)
 #define SAMPLER_SAVE() mozilla_sampler_save()
 #define SAMPLER_GET_PROFILE() mozilla_sampler_get_profile()
 #define SAMPLER_GET_PROFILE_DATA(ctx) mozilla_sampler_get_profile_data(ctx)
 #define SAMPLER_GET_FEATURES() mozilla_sampler_get_features()
 // we want the class and function name but can't easily get that using preprocessor macros
 // __func__ doesn't have the class name and __PRETTY_FUNCTION__ has the parameters
 
 #define SAMPLER_APPEND_LINE_NUMBER_PASTE(id, line) id ## line
@@ -138,16 +139,17 @@ LinuxKernelMemoryBarrierFunc pLinuxKerne
 inline void* mozilla_sampler_call_enter(const char *aInfo, void *aFrameAddress = NULL, bool aCopy = false, uint32_t line = 0);
 inline void  mozilla_sampler_call_exit(void* handle);
 inline void  mozilla_sampler_add_marker(const char *aInfo);
 
 void mozilla_sampler_start(int aEntries, int aInterval, const char** aFeatures, uint32_t aFeatureCount);
 void mozilla_sampler_stop();
 bool mozilla_sampler_is_active();
 void mozilla_sampler_responsiveness(TimeStamp time);
+void mozilla_sampler_frame_number(int frameNumber);
 const double* mozilla_sampler_get_responsiveness();
 void mozilla_sampler_save();
 char* mozilla_sampler_get_profile();
 JSObject *mozilla_sampler_get_profile_data(JSContext *aCx);
 const char** mozilla_sampler_get_features();
 void mozilla_sampler_init();
 
 namespace mozilla {