Bug 1328378 (part 6) - Eliminate SyncProfile. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 27 Feb 2017 12:56:42 +1100
changeset 374570 7becdd5d601a803789f817c7ae7d41b6f2d2c0d2
parent 374569 6de72f3b7f8abb27024a34faac7fbde24ee6ec8f
child 374571 a3f7b4d54578c23ce3ca37d7257824fac7d94a42
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
bugs1328378
milestone54.0a1
Bug 1328378 (part 6) - Eliminate SyncProfile. r=mstange. It's now a very thin wrapper around ThreadInfo, and so can be removed. The patch also has the bonus of setting mIsMainThread correctly for the ThreadInfos that used to be SyncProfiles (i.e. the ones created in profiler_get_backtrace()). As far as I can tell this has only one very minor effect, because that field is only used for those objects to determine how ThreadResponsiveness::Update() dispatches its runnables.
tools/profiler/core/ProfilerBacktrace.cpp
tools/profiler/core/ProfilerMarkers.cpp
tools/profiler/core/SyncProfile.cpp
tools/profiler/core/SyncProfile.h
tools/profiler/core/ThreadInfo.h
tools/profiler/core/platform.cpp
tools/profiler/moz.build
tools/profiler/public/ProfilerBacktrace.h
--- a/tools/profiler/core/ProfilerBacktrace.cpp
+++ b/tools/profiler/core/ProfilerBacktrace.cpp
@@ -2,33 +2,34 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ProfilerBacktrace.h"
 
 #include "ProfileJSONWriter.h"
-#include "SyncProfile.h"
+#include "ThreadInfo.h"
 
 ProfilerBacktrace::ProfilerBacktrace(ProfileBuffer* aBuffer,
-                                     SyncProfile* aProfile)
+                                     ThreadInfo* aThreadInfo)
   : mBuffer(aBuffer)
-  , mProfile(aProfile)
+  , mThreadInfo(aThreadInfo)
 {
   MOZ_COUNT_CTOR(ProfilerBacktrace);
-  MOZ_ASSERT(aProfile);
+  MOZ_ASSERT(aThreadInfo && aThreadInfo->HasProfile());
 }
 
 ProfilerBacktrace::~ProfilerBacktrace()
 {
   MOZ_COUNT_DTOR(ProfilerBacktrace);
   delete mBuffer;
-  delete mProfile;
+  delete mThreadInfo;
 }
 
 void
 ProfilerBacktrace::StreamJSON(SpliceableJSONWriter& aWriter,
                               UniqueStacks& aUniqueStacks)
 {
-  mozilla::MutexAutoLock lock(mProfile->GetMutex());
-  mProfile->StreamJSON(mBuffer, aWriter, aUniqueStacks);
+  mozilla::MutexAutoLock lock(mThreadInfo->GetMutex());
+  mThreadInfo->StreamSamplesAndMarkers(mBuffer, aWriter, /* aSinceTime */ 0,
+                                       aUniqueStacks);
 }
--- a/tools/profiler/core/ProfilerMarkers.cpp
+++ b/tools/profiler/core/ProfilerMarkers.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GeckoProfiler.h"
 #include "ProfilerBacktrace.h"
 #include "ProfilerMarkers.h"
-#include "SyncProfile.h"
 #include "gfxASurface.h"
 #include "Layers.h"
 #include "mozilla/Sprintf.h"
 
 ProfilerMarkerPayload::ProfilerMarkerPayload(UniqueProfilerBacktrace aStack)
   : mStack(mozilla::Move(aStack))
 {}
 
deleted file mode 100644
--- a/tools/profiler/core/SyncProfile.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "SyncProfile.h"
-
-SyncProfile::SyncProfile(int aThreadId, PseudoStack* aStack)
-  : ThreadInfo("SyncProfile", aThreadId, /* isMainThread = */ false, aStack,
-               /* stackTop = */ nullptr)
-{
-  MOZ_COUNT_CTOR(SyncProfile);
-  SetHasProfile();
-}
-
-SyncProfile::~SyncProfile()
-{
-  MOZ_COUNT_DTOR(SyncProfile);
-}
-
-// SyncProfiles' stacks are deduplicated in the context of the containing
-// profile in which the backtrace is as a marker payload.
-void
-SyncProfile::StreamJSON(ProfileBuffer* aBuffer, SpliceableJSONWriter& aWriter,
-                        UniqueStacks& aUniqueStacks)
-{
-  ThreadInfo::StreamSamplesAndMarkers(aBuffer, aWriter, /* aSinceTime = */ 0,
-                                      aUniqueStacks);
-}
deleted file mode 100644
--- a/tools/profiler/core/SyncProfile.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef __SYNCPROFILE_H
-#define __SYNCPROFILE_H
-
-#include "ThreadInfo.h"
-
-class SyncProfile : public ThreadInfo
-{
-public:
-  SyncProfile(int aThreadId, PseudoStack* aStack);
-  ~SyncProfile();
-
-  // SyncProfiles' stacks are deduplicated in the context of the containing
-  // profile in which the backtrace is as a marker payload.
-  void StreamJSON(ProfileBuffer* aBuffer, SpliceableJSONWriter& aWriter,
-                  UniqueStacks& aUniqueStacks);
-
-private:
-  friend class ProfilerBacktrace;
-};
-
-#endif // __SYNCPROFILE_H
-
--- a/tools/profiler/core/ThreadInfo.h
+++ b/tools/profiler/core/ThreadInfo.h
@@ -69,17 +69,16 @@ public:
                            const mozilla::TimeStamp& aStartTime);
 
   ThreadResponsiveness* GetThreadResponsiveness() { return &mRespInfo; }
 
   void UpdateThreadResponsiveness() {
     mRespInfo.Update(mIsMainThread, mThread);
   }
 
-protected:
   void StreamSamplesAndMarkers(ProfileBuffer* aBuffer,
                                SpliceableJSONWriter& aWriter,
                                double aSinceTime,
                                UniqueStacks& aUniqueStacks);
 
 private:
   FRIEND_TEST(ThreadProfile, InsertOneTag);
   FRIEND_TEST(ThreadProfile, InsertOneTagWithTinyBuffer);
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2436,20 +2436,23 @@ profiler_get_backtrace()
   PseudoStack* stack = tlsPseudoStack.get();
   if (!stack) {
     MOZ_ASSERT(stack);
     return nullptr;
   }
   Thread::tid_t tid = Thread::GetCurrentId();
 
   ProfileBuffer* buffer = new ProfileBuffer(GET_BACKTRACE_DEFAULT_ENTRIES);
-  SyncProfile* profile = new SyncProfile(tid, stack);
+  ThreadInfo* threadInfo =
+    new ThreadInfo("SyncProfile", tid, NS_IsMainThread(), stack,
+                   /* stackTop */ nullptr);
+  threadInfo->SetHasProfile();
 
   TickSample sample;
-  sample.threadInfo = profile;
+  sample.threadInfo = threadInfo;
 
 #if defined(HAVE_NATIVE_UNWIND)
 #if defined(GP_OS_windows) || defined(GP_OS_linux) || defined(GP_OS_android)
   tickcontext_t context;
   sample.PopulateContext(&context);
 #elif defined(GP_OS_darwin)
   sample.PopulateContext(nullptr);
 #else
@@ -2457,17 +2460,17 @@ profiler_get_backtrace()
 #endif
 #endif
 
   sample.isSamplingCurrentThread = true;
   sample.timestamp = mozilla::TimeStamp::Now();
 
   Tick(buffer, &sample);
 
-  return UniqueProfilerBacktrace(new ProfilerBacktrace(buffer, profile));
+  return UniqueProfilerBacktrace(new ProfilerBacktrace(buffer, threadInfo));
 }
 
 void
 ProfilerBacktraceDestructor::operator()(ProfilerBacktrace* aBacktrace)
 {
   delete aBacktrace;
 }
 
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -22,17 +22,16 @@ if CONFIG['MOZ_GECKO_PROFILER']:
     UNIFIED_SOURCES += [
         'core/platform.cpp',
         'core/ProfileBuffer.cpp',
         'core/ProfileBufferEntry.cpp',
         'core/ProfileJSONWriter.cpp',
         'core/ProfilerBacktrace.cpp',
         'core/ProfilerMarkers.cpp',
         'core/StackTop.cpp',
-        'core/SyncProfile.cpp',
         'core/ThreadInfo.cpp',
         'gecko/nsProfiler.cpp',
         'gecko/nsProfilerFactory.cpp',
         'gecko/nsProfilerStartParams.cpp',
         'gecko/ProfilerIOInterposeObserver.cpp',
         'gecko/ThreadResponsiveness.cpp',
     ]
     if CONFIG['OS_TARGET'] == 'Darwin':
--- a/tools/profiler/public/ProfilerBacktrace.h
+++ b/tools/profiler/public/ProfilerBacktrace.h
@@ -3,36 +3,36 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __PROFILER_BACKTRACE_H
 #define __PROFILER_BACKTRACE_H
 
 class ProfileBuffer;
-class SyncProfile;
 class SpliceableJSONWriter;
+class ThreadInfo;
 class UniqueStacks;
 
 class ProfilerBacktrace
 {
 public:
-  explicit ProfilerBacktrace(ProfileBuffer* aBuffer, SyncProfile* aProfile);
+  explicit ProfilerBacktrace(ProfileBuffer* aBuffer, ThreadInfo* aThreadInfo);
   ~ProfilerBacktrace();
 
   // ProfilerBacktraces' stacks are deduplicated in the context of the
   // profile that contains the backtrace as a marker payload.
   //
   // That is, markers that contain backtraces should not need their own stack,
   // frame, and string tables. They should instead reuse their parent
   // profile's tables.
   void StreamJSON(SpliceableJSONWriter& aWriter, UniqueStacks& aUniqueStacks);
 
 private:
   ProfilerBacktrace(const ProfilerBacktrace&);
   ProfilerBacktrace& operator=(const ProfilerBacktrace&);
 
   ProfileBuffer* mBuffer;
-  SyncProfile* mProfile;
+  ThreadInfo* mThreadInfo;
 };
 
 #endif // __PROFILER_BACKTRACE_H