Bug 1340928 (part 8) - Pass gStartTime to DuplicateLastSample(). r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Feb 2017 10:18:51 +1100
changeset 373480 8ac2f3a144257a917ac118499f54c6e18862bd21
parent 373479 6e4aa11ecb4d6873c113abf48f0694c9da8150d1
child 373481 b6b681adb0173c3d41faec2e7ff1cea163b6fdb6
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1340928
milestone54.0a1
Bug 1340928 (part 8) - Pass gStartTime to DuplicateLastSample(). r=mstange. This removes the one use of gStartTime outside of platform*.cpp, which lets us restrict its visibility to just that compilation unit.
tools/profiler/core/ProfileBuffer.h
tools/profiler/core/ProfileEntry.cpp
tools/profiler/core/ThreadInfo.cpp
tools/profiler/core/ThreadInfo.h
tools/profiler/core/platform-linux-android.cpp
tools/profiler/core/platform-macos.cpp
tools/profiler/core/platform-win32.cpp
tools/profiler/core/platform.cpp
tools/profiler/core/platform.h
--- a/tools/profiler/core/ProfileBuffer.h
+++ b/tools/profiler/core/ProfileBuffer.h
@@ -7,30 +7,31 @@
 #define MOZ_PROFILE_BUFFER_H
 
 #include "ProfileEntry.h"
 #include "platform.h"
 #include "ProfileJSONWriter.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/RefCounted.h"
 
-class ProfileBuffer : public mozilla::RefCounted<ProfileBuffer> {
+class ProfileBuffer : public mozilla::RefCounted<ProfileBuffer>
+{
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ProfileBuffer)
 
   explicit ProfileBuffer(int aEntrySize);
 
   virtual ~ProfileBuffer();
 
   void addTag(const ProfileEntry& aTag);
   void StreamSamplesToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
                            JSContext* cx, UniqueStacks& aUniqueStacks);
   void StreamMarkersToJSON(SpliceableJSONWriter& aWriter, int aThreadId, double aSinceTime,
                            UniqueStacks& aUniqueStacks);
-  void DuplicateLastSample(int aThreadId);
+  void DuplicateLastSample(int aThreadId, const mozilla::TimeStamp& aStartTime);
 
   void addStoredMarker(ProfilerMarker* aStoredMarker);
 
   // The following two methods are not signal safe! They delete markers.
   void deleteExpiredStoredMarkers();
   void reset();
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
--- a/tools/profiler/core/ProfileEntry.cpp
+++ b/tools/profiler/core/ProfileEntry.cpp
@@ -13,23 +13,23 @@
 // JS
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "js/TrackedOptimizationInfo.h"
 
 // Self
 #include "ProfileEntry.h"
 
+using mozilla::JSONWriter;
 using mozilla::MakeUnique;
-using mozilla::UniquePtr;
 using mozilla::Maybe;
+using mozilla::Nothing;
 using mozilla::Some;
-using mozilla::Nothing;
-using mozilla::JSONWriter;
-
+using mozilla::TimeStamp;
+using mozilla::UniquePtr;
 
 ////////////////////////////////////////////////////////////////////////
 // BEGIN ProfileEntry
 
 ProfileEntry::ProfileEntry()
   : mTagData(nullptr)
   , mKind(Kind::INVALID)
 { }
@@ -749,17 +749,18 @@ int ProfileBuffer::FindLastSampleOfThrea
     if (entry.isThreadId() && entry.mTagInt == aThreadId) {
       return readPos;
     }
   }
 
   return -1;
 }
 
-void ProfileBuffer::DuplicateLastSample(int aThreadId)
+void
+ProfileBuffer::DuplicateLastSample(int aThreadId, const TimeStamp& aStartTime)
 {
   int lastSampleStartPos = FindLastSampleOfThread(aThreadId);
   if (lastSampleStartPos == -1) {
     return;
   }
 
   MOZ_ASSERT(mEntries[lastSampleStartPos].isThreadId());
 
@@ -770,17 +771,17 @@ void ProfileBuffer::DuplicateLastSample(
        readPos != mWritePos;
        readPos = (readPos + 1) % mEntrySize) {
     switch (mEntries[readPos].kind()) {
       case ProfileEntry::Kind::ThreadId:
         // We're done.
         return;
       case ProfileEntry::Kind::Time:
         // Copy with new time
-        addTag(ProfileEntry::Time((mozilla::TimeStamp::Now() - gStartTime).ToMilliseconds()));
+        addTag(ProfileEntry::Time((TimeStamp::Now() - aStartTime).ToMilliseconds()));
         break;
       case ProfileEntry::Kind::Marker:
         // Don't copy markers
         break;
       default:
         // Copy anything else we don't know about
         addTag(mEntries[readPos]);
         break;
--- a/tools/profiler/core/ThreadInfo.cpp
+++ b/tools/profiler/core/ThreadInfo.cpp
@@ -251,19 +251,19 @@ ThreadInfo::EndUnwind()
 
 mozilla::Mutex&
 ThreadInfo::GetMutex()
 {
   return *mMutex.get();
 }
 
 void
-ThreadInfo::DuplicateLastSample()
+ThreadInfo::DuplicateLastSample(const TimeStamp& aStartTime)
 {
-  mBuffer->DuplicateLastSample(mThreadId);
+  mBuffer->DuplicateLastSample(mThreadId, aStartTime);
 }
 
 size_t
 ThreadInfo::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
   size_t n = aMallocSizeOf(this);
 
   n += aMallocSizeOf(mName.get());
--- a/tools/profiler/core/ThreadInfo.h
+++ b/tools/profiler/core/ThreadInfo.h
@@ -68,17 +68,17 @@ public:
 
   // Call this method when the JS entries inside the buffer are about to
   // become invalid, i.e., just before JS shutdown.
   void FlushSamplesAndMarkers();
 
   void BeginUnwind();
   virtual void EndUnwind();
 
-  void DuplicateLastSample();
+  void DuplicateLastSample(const mozilla::TimeStamp& aStartTime);
 
   ThreadResponsiveness* GetThreadResponsiveness() { return &mRespInfo; }
 
   void UpdateThreadResponsiveness() {
     mRespInfo.Update(mIsMainThread, mThread);
   }
 
   uint32_t bufferGeneration() const { return mBuffer->mGeneration; }
--- a/tools/profiler/core/platform-linux-android.cpp
+++ b/tools/profiler/core/platform-linux-android.cpp
@@ -281,17 +281,17 @@ SigprofSender(void* aArg)
         ThreadInfo* info = (*gRegisteredThreads)[i];
 
         // This will be null if we're not interested in profiling this thread.
         if (!info->hasProfile() || info->IsPendingDelete()) {
           continue;
         }
 
         if (info->Stack()->CanDuplicateLastSampleDueToSleep()) {
-          info->DuplicateLastSample();
+          info->DuplicateLastSample(gStartTime);
           continue;
         }
 
         info->UpdateThreadResponsiveness();
 
         // We use gCurrentThreadInfo to pass the ThreadInfo for the
         // thread we're profiling to the signal handler.
         gCurrentThreadInfo = info;
--- a/tools/profiler/core/platform-macos.cpp
+++ b/tools/profiler/core/platform-macos.cpp
@@ -159,17 +159,17 @@ public:
           ThreadInfo* info = (*gRegisteredThreads)[i];
 
           // This will be null if we're not interested in profiling this thread.
           if (!info->hasProfile() || info->IsPendingDelete()) {
             continue;
           }
 
           if (info->Stack()->CanDuplicateLastSampleDueToSleep()) {
-            info->DuplicateLastSample();
+            info->DuplicateLastSample(gStartTime);
             continue;
           }
 
           info->UpdateThreadResponsiveness();
 
           SampleContext(info, isFirstProfiledThread);
           isFirstProfiledThread = false;
         }
--- a/tools/profiler/core/platform-win32.cpp
+++ b/tools/profiler/core/platform-win32.cpp
@@ -169,17 +169,17 @@ class SamplerThread
           ThreadInfo* info = (*gRegisteredThreads)[i];
 
           // This will be null if we're not interested in profiling this thread.
           if (!info->hasProfile() || info->IsPendingDelete()) {
             continue;
           }
 
           if (info->Stack()->CanDuplicateLastSampleDueToSleep()) {
-            info->DuplicateLastSample();
+            info->DuplicateLastSample(gStartTime);
             continue;
           }
 
           info->UpdateThreadResponsiveness();
 
           SampleContext(info, isFirstProfiledThread);
           isFirstProfiledThread = false;
         }
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -135,17 +135,17 @@ static Atomic<bool> gIsPaused(false);
 // 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;
 
 // XXX: This is set by profiler_init() and profiler_start() on the main thread.
 // It is read off the main thread, e.g. by Tick(). It might require more
 // inter-thread synchronization than it currently has.
-mozilla::TimeStamp gStartTime;
+static mozilla::TimeStamp gStartTime;
 
 // XXX: These are accessed by multiple threads and might require more
 // inter-thread synchronization than they currently have.
 static int gFrameNumber = 0;
 static int gLastFrameNumber = 0;
 
 static int gInitCount = 0; // Each init must have a matched shutdown.
 
--- a/tools/profiler/core/platform.h
+++ b/tools/profiler/core/platform.h
@@ -88,18 +88,16 @@ bool profiler_verbose();
     } while (0)
 
 #endif
 
 #if defined(GP_OS_android) && !defined(MOZ_WIDGET_GONK)
 #define PROFILE_JAVA
 #endif
 
-extern mozilla::TimeStamp gStartTime;
-
 typedef uint8_t* Address;
 
 // ----------------------------------------------------------------------------
 // Thread
 //
 // This class has static methods for the different platform specific
 // functions. Add methods here to cope with differences between the
 // supported platforms.