Bug 1358074 (part 2) - Unexport and rename ProfilerState. r=mstange.
☠☠ backed out by 265931fd5e5a ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 21 Apr 2017 13:23:34 +1000
changeset 402699 9baa76979a717579ad43a9814d0fed9c73717b5a
parent 402698 8375b7a4be084a1be30a90c7a6df089f8b1682e0
child 402700 adec21069065815d50cc16dba70bec4cd7cfefc8
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1358074
milestone55.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 1358074 (part 2) - Unexport and rename ProfilerState. r=mstange. gPS is declared in GeckoProfiler.h so that it can be tested as non-null in a couple of functions. - These checks are of little value, so this patch removes them. - That lets us remove the ProfilerState and gPS declarations from GeckoProfiler.h. - And, because ProfilerState is now only used within platform.cpp, that lets us rename it as PS, which is how we currently refer to it (via a typedef) within platform.cpp anyway.
tools/profiler/core/ThreadInfo.h
tools/profiler/core/platform.cpp
tools/profiler/public/GeckoProfiler.h
--- a/tools/profiler/core/ThreadInfo.h
+++ b/tools/profiler/core/ThreadInfo.h
@@ -85,18 +85,18 @@ private:
   // into the final stream.
   mozilla::UniquePtr<char[]> mSavedStreamedSamples;
   mozilla::UniquePtr<char[]> mSavedStreamedMarkers;
   mozilla::Maybe<UniqueStacks> mUniqueStacks;
 
   // This is only used for the main thread.
   mozilla::Maybe<ThreadResponsiveness> mResponsiveness;
 
-  // When sampling, this holds the generation number and offset in
-  // ProfilerState::mBuffer of the most recent sample for this thread.
+  // When sampling, this holds the generation number and offset in PS::mBuffer
+  // of the most recent sample for this thread.
   ProfileBuffer::LastSample mLastSample;
 };
 
 void
 StreamSamplesAndMarkers(const char* aName, int aThreadId,
                         ProfileBuffer* aBuffer,
                         SpliceableJSONWriter& aWriter,
                         const mozilla::TimeStamp& aStartTime,
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -119,30 +119,30 @@ MOZ_THREAD_LOCAL(PseudoStack *) tlsPseud
 // currently locked. This makes it clear when gPSMutex is locked and helps
 // avoid accidental unlocked accesses to global state. There are ways to
 // circumvent this mechanism, but please don't do so without *very* good reason
 // and a detailed explanation.
 //
 // Other from the lock protection, this class is essentially a thin wrapper and
 // contains very little "smarts" itself.
 //
-class ProfilerState
+class PS
 {
 public:
   // Shorter names for local use.
   class Mutex : public mozilla::StaticMutex {};
 
   typedef mozilla::BaseAutoLock<Mutex> AutoLock;
 
   // Only functions that take a LockRef arg can modify this class's fields.
   typedef const AutoLock& LockRef;
 
   typedef std::vector<ThreadInfo*> ThreadVector;
 
-  ProfilerState()
+  PS()
     : mEntries(0)
     , mInterval(0)
     , mFeatureDisplayListDump(false)
     , mFeatureGPU(false)
     , mFeatureJava(false)
     , mFeatureJS(false)
     , mFeatureLayersDump(false)
     , mFeatureLeaf(false)
@@ -325,24 +325,24 @@ private:
   mozilla::ProfilerIOInterposeObserver* mInterposeObserver;
 
   // The current frame number and the most recent frame number recorded in a
   // sample.
   int mFrameNumber;
   int mLatestRecordedFrameNumber;
 };
 
-// A shorter name for use within this compilation unit.
-typedef ProfilerState PS;
-
 uint32_t PS::sActivityGeneration = 0;
 uint32_t PS::sNextActivityGeneration = 1;
 
-// The profiler state. Set by profiler_init(), cleared by profiler_shutdown().
-PS* gPS = nullptr;
+// The core profiler state. Null at process startup, it is set to a non-null
+// value in profiler_init() and stays that way until profiler_shutdown() is
+// called. Therefore it can be checked to determine if the profiler has been
+// initialized but not yet shut down.
+static PS* gPS = nullptr;
 
 // The mutex that guards accesses to gPS.
 static PS::Mutex gPSMutex;
 
 // The name of the main thread.
 static const char* const kMainThreadName = "GeckoMain";
 
 static bool
@@ -754,17 +754,17 @@ MergeStacksIntoProfile(PS::LockRef aLock
     if (nativeIndex >= 0) {
       nativeIndex--;
     }
   }
 
   // Update the JS context with the current profile sample buffer generation.
   //
   // Do not do this for synchronous samples, which use their own
-  // ProfileBuffers instead of the global one in ProfilerState.
+  // ProfileBuffers instead of the global one in PS.
   if (!aSample.mIsSynchronous && pseudoStack->mContext) {
     MOZ_ASSERT(aBuffer->mGeneration >= startBufferGen);
     uint32_t lapCount = aBuffer->mGeneration - startBufferGen;
     JS::UpdateJSContextProfilerSampleBufferGen(pseudoStack->mContext,
                                                aBuffer->mGeneration,
                                                lapCount);
   }
 }
@@ -1791,18 +1791,18 @@ GeckoProfilerReporter::CollectReports(ns
       lul::LUL* lul = gPS->LUL(lock);
       lulSize = lul ? lul->SizeOfIncludingThis(GeckoProfilerMallocSizeOf) : 0;
 #endif
     }
   }
 
   MOZ_COLLECT_REPORT(
     "explicit/profiler/profiler-state", KIND_HEAP, UNITS_BYTES, profSize,
-    "Memory used by the Gecko Profiler's ProfilerState object (excluding "
-    "memory used by LUL).");
+    "Memory used by the Gecko Profiler's global state (excluding memory used "
+    "by LUL).");
 
 #if defined(USE_LUL_STACKWALK)
   MOZ_COLLECT_REPORT(
     "explicit/profiler/lul", KIND_HEAP, UNITS_BYTES, lulSize,
     "Memory used by LUL, a stack unwinder used by the Gecko Profiler.");
 #endif
 
   return NS_OK;
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -324,24 +324,16 @@ class ProfilerMarkerPayload;
 // Non-owning PseudoStack references are also temporarily used by
 // profiler_call_{enter,exit}() pairs. RAII classes ensure these calls are
 // balanced, and they occur on the thread itself, which means they are
 // necessarily bounded by the lifetime of the thread, which ensures they can't
 // be used after the PseudoStack is destroyed.
 //
 extern MOZ_THREAD_LOCAL(PseudoStack*) tlsPseudoStack;
 
-class ProfilerState;
-
-// The core profiler state. Null at process startup, it is set to a non-null
-// value in profiler_init() and stays that way until profiler_shutdown() is
-// called. Therefore it can be checked to determine if the profiler has been
-// initialized but not yet shut down.
-extern ProfilerState* gPS;
-
 #ifndef SAMPLE_FUNCTION_NAME
 # if defined(__GNUC__) || defined(_MSC_VER)
 #  define SAMPLE_FUNCTION_NAME __FUNCTION__
 # else
 #  define SAMPLE_FUNCTION_NAME __func__  // defined in C99, supported in various C++ compilers. Just raw function name.
 # endif
 #endif
 
@@ -350,36 +342,32 @@ extern ProfilerState* gPS;
 static inline void*
 profiler_call_enter(const char* aInfo,
                     js::ProfileEntry::Category aCategory,
                     void *aFrameAddress, bool aCopy, uint32_t line,
                     const char* aDynamicString = nullptr)
 {
   // This function runs both on and off the main thread.
 
-  MOZ_RELEASE_ASSERT(gPS);
-
   PseudoStack* stack = tlsPseudoStack.get();
   if (!stack) {
     return stack;
   }
   stack->push(aInfo, aCategory, aFrameAddress, aCopy, line, aDynamicString);
 
   // The handle is meant to support future changes but for now it is simply
   // used to avoid having to call tlsPseudoStack.get() in profiler_call_exit().
   return stack;
 }
 
 static inline void
 profiler_call_exit(void* aHandle)
 {
   // This function runs both on and off the main thread.
 
-  MOZ_RELEASE_ASSERT(gPS);
-
   if (!aHandle) {
     return;
   }
 
   PseudoStack *stack = (PseudoStack*)aHandle;
   stack->pop();
 }
 
@@ -493,18 +481,16 @@ private:
 
 } // namespace mozilla
 
 inline PseudoStack*
 profiler_get_pseudo_stack(void)
 {
   // This function runs both on and off the main thread.
 
-  MOZ_RELEASE_ASSERT(gPS);
-
   return tlsPseudoStack.get();
 }
 
 void profiler_set_js_context(JSContext* aCx);
 void profiler_clear_js_context();
 
 class GeckoProfilerReporter final : public nsIMemoryReporter
 {