Bug 1492121 - Copy most of Gecko Profiler code to mozglue/baseprofiler - r=njn
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 06 Jun 2019 06:16:57 +0000
changeset 477561 64fe004165930d67c1fc54830aec644eef7b8111
parent 477560 73a4875ecd33cdbf3a5ad1148c399bb21867f71a
child 477562 1a63bc8f0afd889023b7405ad9735b97a20da0bf
push id36119
push userncsoregi@mozilla.com
push dateThu, 06 Jun 2019 21:52:09 +0000
treeherdermozilla-central@6a81efd823db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1492121
milestone69.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 1492121 - Copy most of Gecko Profiler code to mozglue/baseprofiler - r=njn Almost-straight copy of a subset of files from tools/profiler to mozglue/baseprofiler. Some minor changes first: - Reduced moz.build to only mention actually-copied files. - Headers in 'public' prefixed with "Base" (to distinguish them from their originals, in case they later get #included from the same units). - Also copied profiling categories from js/src/vm/GeckoProfiler.cpp to ProfilingCategory.cpp, and copied js/src/vm/ProfilingStack.cpp, and their respective headers -- as they are needed for a significant part of the profiler API, and are not strictly js-specific. baseprofiler not yet added to parent mozglue/moz.build, so it won't be built yet. Differential Revision: https://phabricator.services.mozilla.com/D31923
mozglue/baseprofiler/core/EHABIStackWalk.cpp
mozglue/baseprofiler/core/EHABIStackWalk.h
mozglue/baseprofiler/core/PageInformation.cpp
mozglue/baseprofiler/core/PageInformation.h
mozglue/baseprofiler/core/PlatformMacros.h
mozglue/baseprofiler/core/ProfileBuffer.cpp
mozglue/baseprofiler/core/ProfileBuffer.h
mozglue/baseprofiler/core/ProfileBufferEntry.cpp
mozglue/baseprofiler/core/ProfileBufferEntry.h
mozglue/baseprofiler/core/ProfileJSONWriter.cpp
mozglue/baseprofiler/core/ProfiledThreadData.cpp
mozglue/baseprofiler/core/ProfiledThreadData.h
mozglue/baseprofiler/core/ProfilerBacktrace.cpp
mozglue/baseprofiler/core/ProfilerBacktrace.h
mozglue/baseprofiler/core/ProfilerMarker.h
mozglue/baseprofiler/core/ProfilerMarkerPayload.cpp
mozglue/baseprofiler/core/ProfilingCategory.cpp
mozglue/baseprofiler/core/ProfilingStack.cpp
mozglue/baseprofiler/core/RegisteredThread.cpp
mozglue/baseprofiler/core/RegisteredThread.h
mozglue/baseprofiler/core/ThreadInfo.h
mozglue/baseprofiler/core/VTuneProfiler.cpp
mozglue/baseprofiler/core/VTuneProfiler.h
mozglue/baseprofiler/core/platform-linux-android.cpp
mozglue/baseprofiler/core/platform-macos.cpp
mozglue/baseprofiler/core/platform-win32.cpp
mozglue/baseprofiler/core/platform.cpp
mozglue/baseprofiler/core/platform.h
mozglue/baseprofiler/core/shared-libraries-linux.cc
mozglue/baseprofiler/core/shared-libraries-macos.cc
mozglue/baseprofiler/core/shared-libraries-win32.cc
mozglue/baseprofiler/core/vtune/ittnotify.h
mozglue/baseprofiler/lul/AutoObjectMapper.cpp
mozglue/baseprofiler/lul/AutoObjectMapper.h
mozglue/baseprofiler/lul/LulCommon.cpp
mozglue/baseprofiler/lul/LulCommonExt.h
mozglue/baseprofiler/lul/LulDwarf.cpp
mozglue/baseprofiler/lul/LulDwarfExt.h
mozglue/baseprofiler/lul/LulDwarfInt.h
mozglue/baseprofiler/lul/LulDwarfSummariser.cpp
mozglue/baseprofiler/lul/LulDwarfSummariser.h
mozglue/baseprofiler/lul/LulElf.cpp
mozglue/baseprofiler/lul/LulElfExt.h
mozglue/baseprofiler/lul/LulElfInt.h
mozglue/baseprofiler/lul/LulMain.cpp
mozglue/baseprofiler/lul/LulMain.h
mozglue/baseprofiler/lul/LulMainInt.h
mozglue/baseprofiler/lul/platform-linux-lul.cpp
mozglue/baseprofiler/lul/platform-linux-lul.h
mozglue/baseprofiler/moz.build
mozglue/baseprofiler/public/BaseProfileJSONWriter.h
mozglue/baseprofiler/public/BaseProfiler.h
mozglue/baseprofiler/public/BaseProfilerCounts.h
mozglue/baseprofiler/public/BaseProfilerMarkerPayload.h
mozglue/baseprofiler/public/BaseProfilerSharedLibraries.h
mozglue/baseprofiler/public/BaseProfilingCategory.h
mozglue/baseprofiler/public/BaseProfilingStack.h
copy from tools/profiler/core/EHABIStackWalk.cpp
copy to mozglue/baseprofiler/core/EHABIStackWalk.cpp
--- a/tools/profiler/core/EHABIStackWalk.cpp
+++ b/mozglue/baseprofiler/core/EHABIStackWalk.cpp
@@ -19,17 +19,17 @@
  *
  * This file uses "struct" for structures in the exception tables and
  * "class" otherwise.  We should avoid violating the C++11
  * standard-layout rules in the former.
  */
 
 #include "EHABIStackWalk.h"
 
-#include "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 #include "platform.h"
 
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EndianUtils.h"
 
 #include <algorithm>
copy from tools/profiler/core/EHABIStackWalk.h
copy to mozglue/baseprofiler/core/EHABIStackWalk.h
copy from tools/profiler/core/PageInformation.cpp
copy to mozglue/baseprofiler/core/PageInformation.cpp
--- a/tools/profiler/core/PageInformation.cpp
+++ b/mozglue/baseprofiler/core/PageInformation.cpp
@@ -1,17 +1,17 @@
 /* -*- 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 "PageInformation.h"
 
-#include "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 
 PageInformation::PageInformation(const nsID& aDocShellId,
                                  uint32_t aDocShellHistoryId,
                                  const nsCString& aUrl, bool aIsSubFrame)
     : mDocShellId(aDocShellId),
       mDocShellHistoryId(aDocShellHistoryId),
       mUrl(aUrl),
       mIsSubFrame(aIsSubFrame) {}
copy from tools/profiler/core/PageInformation.h
copy to mozglue/baseprofiler/core/PageInformation.h
copy from tools/profiler/core/PlatformMacros.h
copy to mozglue/baseprofiler/core/PlatformMacros.h
copy from tools/profiler/core/ProfileBuffer.cpp
copy to mozglue/baseprofiler/core/ProfileBuffer.cpp
copy from tools/profiler/core/ProfileBuffer.h
copy to mozglue/baseprofiler/core/ProfileBuffer.h
copy from tools/profiler/core/ProfileBufferEntry.cpp
copy to mozglue/baseprofiler/core/ProfileBufferEntry.cpp
copy from tools/profiler/core/ProfileBufferEntry.h
copy to mozglue/baseprofiler/core/ProfileBufferEntry.h
--- a/tools/profiler/core/ProfileBufferEntry.h
+++ b/mozglue/baseprofiler/core/ProfileBufferEntry.h
@@ -2,17 +2,17 @@
 /* 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 ProfileBufferEntry_h
 #define ProfileBufferEntry_h
 
-#include "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 
 #include "gtest/MozGtestFriend.h"
 #include "js/ProfilingCategory.h"
 #include "js/ProfilingFrameIterator.h"
 #include "js/TrackedOptimizationInfo.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/HashTable.h"
 #include "mozilla/Maybe.h"
copy from tools/profiler/core/ProfileJSONWriter.cpp
copy to mozglue/baseprofiler/core/ProfileJSONWriter.cpp
--- a/tools/profiler/core/ProfileJSONWriter.cpp
+++ b/mozglue/baseprofiler/core/ProfileJSONWriter.cpp
@@ -1,14 +1,14 @@
 /* -*- 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 "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 
 #include "mozilla/HashFunctions.h"
 
 void ChunkedJSONWriteFunc::Write(const char* aStr) {
   MOZ_ASSERT(mChunkPtr >= mChunkList.back().get() && mChunkPtr <= mChunkEnd);
   MOZ_ASSERT(mChunkEnd >= mChunkList.back().get() + mChunkLengths.back());
   MOZ_ASSERT(*mChunkPtr == '\0');
 
copy from tools/profiler/core/ProfiledThreadData.cpp
copy to mozglue/baseprofiler/core/ProfiledThreadData.cpp
--- a/tools/profiler/core/ProfiledThreadData.cpp
+++ b/mozglue/baseprofiler/core/ProfiledThreadData.cpp
@@ -2,17 +2,17 @@
 /* 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 "ProfiledThreadData.h"
 
 #include "ProfileBuffer.h"
-#include "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 
 #include "js/TraceLoggerAPI.h"
 #include "mozilla/dom/ContentChild.h"
 
 #if defined(GP_OS_darwin)
 #  include <pthread.h>
 #endif
 
copy from tools/profiler/core/ProfiledThreadData.h
copy to mozglue/baseprofiler/core/ProfiledThreadData.h
copy from tools/profiler/core/ProfilerBacktrace.cpp
copy to mozglue/baseprofiler/core/ProfilerBacktrace.cpp
--- a/tools/profiler/core/ProfilerBacktrace.cpp
+++ b/mozglue/baseprofiler/core/ProfilerBacktrace.cpp
@@ -3,17 +3,17 @@
 /* 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 "ProfileBuffer.h"
 #include "ProfiledThreadData.h"
-#include "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 #include "ThreadInfo.h"
 
 ProfilerBacktrace::ProfilerBacktrace(const char* aName, int aThreadId,
                                      mozilla::UniquePtr<ProfileBuffer> aBuffer)
     : mName(strdup(aName)), mThreadId(aThreadId), mBuffer(std::move(aBuffer)) {
   MOZ_COUNT_CTOR(ProfilerBacktrace);
 }
 
copy from tools/profiler/core/ProfilerBacktrace.h
copy to mozglue/baseprofiler/core/ProfilerBacktrace.h
copy from tools/profiler/core/ProfilerMarker.h
copy to mozglue/baseprofiler/core/ProfilerMarker.h
--- a/tools/profiler/core/ProfilerMarker.h
+++ b/mozglue/baseprofiler/core/ProfilerMarker.h
@@ -3,18 +3,18 @@
 /* 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 ProfilerMarker_h
 #define ProfilerMarker_h
 
 #include "ProfileBufferEntry.h"
-#include "ProfileJSONWriter.h"
-#include "ProfilerMarkerPayload.h"
+#include "BaseProfileJSONWriter.h"
+#include "BaseProfilerMarkerPayload.h"
 
 #include "mozilla/UniquePtrExtensions.h"
 
 template <typename T>
 class ProfilerLinkedList;
 
 class ProfilerMarker {
   friend class ProfilerLinkedList<ProfilerMarker>;
copy from tools/profiler/core/ProfilerMarkerPayload.cpp
copy to mozglue/baseprofiler/core/ProfilerMarkerPayload.cpp
--- a/tools/profiler/core/ProfilerMarkerPayload.cpp
+++ b/mozglue/baseprofiler/core/ProfilerMarkerPayload.cpp
@@ -1,18 +1,18 @@
 /* -*- 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 "ProfilerMarkerPayload.h"
+#include "BaseProfilerMarkerPayload.h"
 
-#include "GeckoProfiler.h"
+#include "BaseProfiler.h"
 #include "ProfileBufferEntry.h"
-#include "ProfileJSONWriter.h"
+#include "BaseProfileJSONWriter.h"
 #include "ProfilerBacktrace.h"
 
 #include "gfxASurface.h"
 #include "Layers.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/net/HttpBaseChannel.h"
 #include "mozilla/Sprintf.h"
 
copy from js/src/vm/GeckoProfiler.cpp
copy to mozglue/baseprofiler/core/ProfilingCategory.cpp
copy from js/src/vm/ProfilingStack.cpp
copy to mozglue/baseprofiler/core/ProfilingStack.cpp
copy from tools/profiler/core/RegisteredThread.cpp
copy to mozglue/baseprofiler/core/RegisteredThread.cpp
copy from tools/profiler/core/RegisteredThread.h
copy to mozglue/baseprofiler/core/RegisteredThread.h
--- a/tools/profiler/core/RegisteredThread.h
+++ b/mozglue/baseprofiler/core/RegisteredThread.h
@@ -4,17 +4,17 @@
  * 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 RegisteredThread_h
 #define RegisteredThread_h
 
 #include "platform.h"
 #include "ProfilerMarker.h"
-#include "ProfilerMarkerPayload.h"
+#include "BaseProfilerMarkerPayload.h"
 #include "ThreadInfo.h"
 
 #include "js/TraceLoggerAPI.h"
 #include "jsapi.h"
 #include "mozilla/UniquePtr.h"
 #include "nsIEventTarget.h"
 
 // This class contains the state for a single thread that is accessible without
copy from tools/profiler/core/ThreadInfo.h
copy to mozglue/baseprofiler/core/ThreadInfo.h
copy from tools/profiler/core/VTuneProfiler.cpp
copy to mozglue/baseprofiler/core/VTuneProfiler.cpp
copy from tools/profiler/core/VTuneProfiler.h
copy to mozglue/baseprofiler/core/VTuneProfiler.h
--- a/tools/profiler/core/VTuneProfiler.h
+++ b/mozglue/baseprofiler/core/VTuneProfiler.h
@@ -19,17 +19,17 @@
 #  define VTUNE_INIT()
 #  define VTUNE_SHUTDOWN()
 
 #  define VTUNE_TRACING(name, kind)
 #  define VTUNE_REGISTER_THREAD(name)
 
 #else
 
-#  include "GeckoProfiler.h"
+#  include "BaseProfiler.h"
 
 // This is the regular Intel header, these functions are actually defined for
 // us inside js/src/vtune by an intel C file which actually dynamically resolves
 // them to the correct DLL. Through libxul these will 'magically' resolve.
 #  include "vtune/ittnotify.h"
 
 #  include <stddef.h>
 #  include <unordered_map>
copy from tools/profiler/core/platform-linux-android.cpp
copy to mozglue/baseprofiler/core/platform-linux-android.cpp
copy from tools/profiler/core/platform-macos.cpp
copy to mozglue/baseprofiler/core/platform-macos.cpp
copy from tools/profiler/core/platform-win32.cpp
copy to mozglue/baseprofiler/core/platform-win32.cpp
copy from tools/profiler/core/platform.cpp
copy to mozglue/baseprofiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/mozglue/baseprofiler/core/platform.cpp
@@ -23,27 +23,27 @@
 // - A "backtrace" sample is the simplest kind. It is done in response to an
 //   API call (profiler_suspend_and_sample_thread()). It involves getting a
 //   stack trace via a ProfilerStackCollector; it does not write to a
 //   ProfileBuffer. The sampling is done from off-thread, and so uses
 //   SuspendAndSampleAndResumeThread() to get the register values.
 
 #include "platform.h"
 
-#include "GeckoProfiler.h"
+#include "BaseProfiler.h"
 #include "GeckoProfilerReporter.h"
 #include "PageInformation.h"
 #include "ProfiledThreadData.h"
 #include "ProfilerBacktrace.h"
 #include "ProfileBuffer.h"
 #include "ProfilerIOInterposeObserver.h"
-#include "ProfilerMarkerPayload.h"
+#include "BaseProfilerMarkerPayload.h"
 #include "ProfilerParent.h"
 #include "RegisteredThread.h"
-#include "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 #include "ThreadInfo.h"
 #include "VTuneProfiler.h"
 
 #include "js/TraceLoggerAPI.h"
 #include "memory_hooks.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/AutoProfilerLabel.h"
@@ -1024,21 +1024,21 @@ MOZ_THREAD_LOCAL(RegisteredThread*) TLSR
 
 // Although you can access a thread's ProfilingStack via
 // TLSRegisteredThread::sRegisteredThread, we also have a second TLS pointer
 // directly to the ProfilingStack. Here's why.
 //
 // - We need to be able to push to and pop from the ProfilingStack in
 //   AutoProfilerLabel.
 //
-// - The class functions are hot and must be defined in GeckoProfiler.h so they
+// - The class functions are hot and must be defined in BaseProfiler.h so they
 //   can be inlined.
 //
 // - We don't want to expose TLSRegisteredThread (and RegisteredThread) in
-//   GeckoProfiler.h.
+//   BaseProfiler.h.
 //
 // This second pointer isn't ideal, but does provide a way to satisfy those
 // constraints. TLSRegisteredThread is responsible for updating it.
 MOZ_THREAD_LOCAL(ProfilingStack*) AutoProfilerLabel::sProfilingStack;
 
 // The name of the main thread.
 static const char* const kMainThreadName = "GeckoMain";
 
copy from tools/profiler/core/platform.h
copy to mozglue/baseprofiler/core/platform.h
--- a/tools/profiler/core/platform.h
+++ b/mozglue/baseprofiler/core/platform.h
@@ -26,17 +26,17 @@
 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 // SUCH DAMAGE.
 
 #ifndef TOOLS_PLATFORM_H_
 #define TOOLS_PLATFORM_H_
 
 #include "PlatformMacros.h"
 
-#include "GeckoProfiler.h"
+#include "BaseProfiler.h"
 
 #include "mozilla/Logging.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Vector.h"
 #include "nsString.h"
 
 #include <functional>
 #include <stdint.h>
copy from tools/profiler/core/shared-libraries-linux.cc
copy to mozglue/baseprofiler/core/shared-libraries-linux.cc
--- a/tools/profiler/core/shared-libraries-linux.cc
+++ b/mozglue/baseprofiler/core/shared-libraries-linux.cc
@@ -1,26 +1,25 @@
 /* -*- Mode: C++; tab-width: 8; 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 "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 
 #define PATH_MAX_TOSTRING(x) #x
 #define PATH_MAX_STRING(x) PATH_MAX_TOSTRING(x)
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
 #include <unistd.h>
 #include <fstream>
 #include "platform.h"
-#include "shared-libraries.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/Unused.h"
 #include "nsDebug.h"
 #include "nsNativeCharsetUtils.h"
 #include <nsTArray.h>
 
 #include "common/linux/file_id.h"
 #include <algorithm>
copy from tools/profiler/core/shared-libraries-macos.cc
copy to mozglue/baseprofiler/core/shared-libraries-macos.cc
--- a/tools/profiler/core/shared-libraries-macos.cc
+++ b/mozglue/baseprofiler/core/shared-libraries-macos.cc
@@ -1,14 +1,14 @@
 /* -*- 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 "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 
 #include "ClearOnShutdown.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/Unused.h"
 #include "nsNativeCharsetUtils.h"
 #include <AvailabilityMacros.h>
 
 #include <dlfcn.h>
copy from tools/profiler/core/shared-libraries-win32.cc
copy to mozglue/baseprofiler/core/shared-libraries-win32.cc
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/mozglue/baseprofiler/core/shared-libraries-win32.cc
@@ -3,17 +3,17 @@
  * 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 <windows.h>
 #include <dbghelp.h>
 #include <sstream>
 #include <psapi.h>
 
-#include "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 #include "nsWindowsHelpers.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 
 #define CV_SIGNATURE 0x53445352  // 'SDSR'
copy from tools/profiler/core/vtune/ittnotify.h
copy to mozglue/baseprofiler/core/vtune/ittnotify.h
--- a/tools/profiler/core/vtune/ittnotify.h
+++ b/mozglue/baseprofiler/core/vtune/ittnotify.h
@@ -1,8 +1,10 @@
+// clang-format off
+
 /* <copyright>
   This file is provided under a dual BSD/GPLv2 license.  When using or
   redistributing this file, you may do so under either license.
 
   GPL LICENSE SUMMARY
 
   Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
 
@@ -51,17 +53,17 @@
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 </copyright> */
 #ifndef _ITTNOTIFY_H_
-#define _ITTNOTIFY_H_
+#  define _ITTNOTIFY_H_
 
 /**
 @file
 @brief Public User API functions and types
 @mainpage
 
 The ITT API is used to annotate a user's program with additional information
 that can be used by correctness and performance tools. The user inserts
@@ -4116,8 +4118,10 @@ ITT_STUB(ITTAPI, const char*, api_versio
 
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
 
 #endif /* _ITTNOTIFY_PRIVATE_ */
 
 #endif /* INTEL_ITTNOTIFY_API_PRIVATE */
+
+// clang-format on
copy from tools/profiler/lul/AutoObjectMapper.cpp
copy to mozglue/baseprofiler/lul/AutoObjectMapper.cpp
copy from tools/profiler/lul/AutoObjectMapper.h
copy to mozglue/baseprofiler/lul/AutoObjectMapper.h
copy from tools/profiler/lul/LulCommon.cpp
copy to mozglue/baseprofiler/lul/LulCommon.cpp
copy from tools/profiler/lul/LulCommonExt.h
copy to mozglue/baseprofiler/lul/LulCommonExt.h
copy from tools/profiler/lul/LulDwarf.cpp
copy to mozglue/baseprofiler/lul/LulDwarf.cpp
copy from tools/profiler/lul/LulDwarfExt.h
copy to mozglue/baseprofiler/lul/LulDwarfExt.h
copy from tools/profiler/lul/LulDwarfInt.h
copy to mozglue/baseprofiler/lul/LulDwarfInt.h
copy from tools/profiler/lul/LulDwarfSummariser.cpp
copy to mozglue/baseprofiler/lul/LulDwarfSummariser.cpp
copy from tools/profiler/lul/LulDwarfSummariser.h
copy to mozglue/baseprofiler/lul/LulDwarfSummariser.h
copy from tools/profiler/lul/LulElf.cpp
copy to mozglue/baseprofiler/lul/LulElf.cpp
copy from tools/profiler/lul/LulElfExt.h
copy to mozglue/baseprofiler/lul/LulElfExt.h
copy from tools/profiler/lul/LulElfInt.h
copy to mozglue/baseprofiler/lul/LulElfInt.h
copy from tools/profiler/lul/LulMain.cpp
copy to mozglue/baseprofiler/lul/LulMain.cpp
--- a/tools/profiler/lul/LulMain.cpp
+++ b/mozglue/baseprofiler/lul/LulMain.cpp
@@ -24,17 +24,17 @@
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 
 #include "LulCommonExt.h"
 #include "LulElfExt.h"
 
 #include "LulMainInt.h"
 
-#include "GeckoProfiler.h"  // for profiler_current_thread_id()
+#include "BaseProfiler.h"  // for profiler_current_thread_id()
 
 // Set this to 1 for verbose logging
 #define DEBUG_MAIN 0
 
 namespace lul {
 
 using mozilla::CheckedInt;
 using mozilla::DebugOnly;
copy from tools/profiler/lul/LulMain.h
copy to mozglue/baseprofiler/lul/LulMain.h
copy from tools/profiler/lul/LulMainInt.h
copy to mozglue/baseprofiler/lul/LulMainInt.h
copy from tools/profiler/lul/platform-linux-lul.cpp
copy to mozglue/baseprofiler/lul/platform-linux-lul.cpp
--- a/tools/profiler/lul/platform-linux-lul.cpp
+++ b/mozglue/baseprofiler/lul/platform-linux-lul.cpp
@@ -7,17 +7,17 @@
 #include <signal.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
 
 #include "platform.h"
 #include "PlatformMacros.h"
 #include "LulMain.h"
-#include "shared-libraries.h"
+#include "BaseProfilerSharedLibraries.h"
 #include "AutoObjectMapper.h"
 
 // Contains miscellaneous helpers that are used to connect the Gecko Profiler
 // and LUL.
 
 // Find out, in a platform-dependent way, where the code modules got
 // mapped in the process' virtual address space, and get |aLUL| to
 // load unwind info for them.
copy from tools/profiler/lul/platform-linux-lul.h
copy to mozglue/baseprofiler/lul/platform-linux-lul.h
copy from tools/profiler/moz.build
copy to mozglue/baseprofiler/moz.build
--- a/tools/profiler/moz.build
+++ b/mozglue/baseprofiler/moz.build
@@ -1,175 +1,102 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
+# This is pretty much a copy from tools/profiler, cut down to exclude anything
+# that cannot work in mozglue (because they are totally dependent on libxul-
+# specific code).
+# All exported headers now prefixed with "Base" to avoid #include name clashes.
+
 if CONFIG['MOZ_GECKO_PROFILER']:
-    DEFINES['MOZ_REPLACE_MALLOC_PREFIX'] = 'profiler'
-    XPIDL_MODULE = 'profiler'
-    XPIDL_SOURCES += [
-        'gecko/nsIProfiler.idl',
-    ]
+    DEFINES['IMPL_MFBT'] = True
     EXPORTS += [
-        'public/ChildProfilerController.h',
-        'public/GeckoProfilerReporter.h',
-        'public/ProfileJSONWriter.h',
-        'public/ProfilerChild.h',
-        'public/ProfilerMarkerPayload.h',
-        'public/ProfilerParent.h',
-        'public/shared-libraries.h',
+        'public/BaseProfileJSONWriter.h',
+        'public/BaseProfilerMarkerPayload.h',
+        'public/BaseProfilerSharedLibraries.h',
+        'public/BaseProfilingCategory.h',
+        'public/BaseProfilingStack.h',
     ]
     UNIFIED_SOURCES += [
         'core/PageInformation.cpp',
         'core/platform.cpp',
         'core/ProfileBuffer.cpp',
         'core/ProfileBufferEntry.cpp',
         'core/ProfiledThreadData.cpp',
         'core/ProfileJSONWriter.cpp',
         'core/ProfilerBacktrace.cpp',
         'core/ProfilerMarkerPayload.cpp',
+        'core/ProfilingCategory.cpp',
+        'core/ProfilingStack.cpp',
         'core/RegisteredThread.cpp',
-        'gecko/ChildProfilerController.cpp',
-        'gecko/nsProfilerStartParams.cpp',
-        'gecko/ProfilerChild.cpp',
-        'gecko/ProfilerIOInterposeObserver.cpp',
-        'gecko/ProfilerParent.cpp',
-        'gecko/ThreadResponsiveness.cpp',
     ]
-    if CONFIG['MOZ_REPLACE_MALLOC'] and CONFIG['MOZ_PROFILER_MEMORY']:
-        SOURCES += [
-            'core/memory_hooks.cpp', # Non-unified because of order of #includes
-        ]
-
-    XPCOM_MANIFESTS += [
-        'gecko/components.conf',
-    ]
-
-    if CONFIG['OS_TARGET'] == 'Darwin':
-        # This file cannot be built in unified mode because it includes
-        # "nsLocalFile.h", which pulls in a system header which uses a type
-        # called TextRange, which conflicts with mozilla::TextRange due to
-        # a "using namespace mozilla;" declaration from a different file.
-        SOURCES += [
-            'gecko/nsProfiler.cpp',
-        ]
-    else:
-        UNIFIED_SOURCES += [
-            'gecko/nsProfiler.cpp',
-        ]
 
     if CONFIG['OS_TARGET'] in ('Android', 'Linux'):
         if CONFIG['CPU_ARCH'] in ('arm', 'aarch64', 'x86', 'x86_64', 'mips64'):
             UNIFIED_SOURCES += [
                 'lul/AutoObjectMapper.cpp',
                 'lul/LulCommon.cpp',
                 'lul/LulDwarf.cpp',
                 'lul/LulDwarfSummariser.cpp',
                 'lul/LulElf.cpp',
                 'lul/LulMain.cpp',
                 'lul/platform-linux-lul.cpp',
             ]
         # These files cannot be built in unified mode because of name clashes with mozglue headers on Android.
         SOURCES += [
             'core/shared-libraries-linux.cc',
         ]
-        if not CONFIG['MOZ_CRASHREPORTER']:
-            SOURCES += [
-                '/toolkit/crashreporter/google-breakpad/src/common/linux/elfutils.cc',
-                '/toolkit/crashreporter/google-breakpad/src/common/linux/file_id.cc',
-                '/toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc',
-                '/toolkit/crashreporter/google-breakpad/src/common/linux/memory_mapped_file.cc',
-            ]
         if CONFIG['CPU_ARCH'] == 'arm':
             SOURCES += [
                 'core/EHABIStackWalk.cpp',
             ]
     elif CONFIG['OS_TARGET'] == 'Darwin':
         UNIFIED_SOURCES += [
             'core/shared-libraries-macos.cc',
         ]
     elif CONFIG['OS_TARGET'] == 'WINNT':
         SOURCES += [
             'core/shared-libraries-win32.cc',
         ]
 
     LOCAL_INCLUDES += [
-        '/caps',
-        '/docshell/base',
-        '/ipc/chromium/src',
+        '/mozglue/baseprofiler/core/',
         '/mozglue/linker',
-        '/netwerk/base',
-        '/netwerk/protocol/http',
-        '/toolkit/crashreporter/google-breakpad/src',
-        '/tools/profiler/core/',
-        '/tools/profiler/gecko/',
-        '/xpcom/base',
     ]
 
     if CONFIG['OS_TARGET'] == 'Android':
         DEFINES['ANDROID_NDK_MAJOR_VERSION'] = CONFIG['ANDROID_NDK_MAJOR_VERSION']
         DEFINES['ANDROID_NDK_MINOR_VERSION'] = CONFIG['ANDROID_NDK_MINOR_VERSION']
         LOCAL_INCLUDES += [
-            # We need access to Breakpad's getcontext(3) which is suitable for Android
-            '/toolkit/crashreporter/google-breakpad/src/common/android/include',
             'lul',
         ]
 
-    if not CONFIG['MOZ_CRASHREPORTER'] and CONFIG['OS_TARGET'] == 'Android':
-        SOURCES += ['/toolkit/crashreporter/google-breakpad/src/common/android/breakpad_getcontext.S']
-
-    if CONFIG['ENABLE_TESTS']:
-        DIRS += ['tests/gtest']
+    FINAL_LIBRARY = 'mozglue'
 
-    FINAL_LIBRARY = 'xul'
-
-IPDL_SOURCES += [
-    'gecko/PProfiler.ipdl',
-    'gecko/ProfilerTypes.ipdlh',
+# BaseProfiler.h and BaseProfilerCounts.h are the only headers that are usable
+# in non-MOZ_GECKO_PROFILER builds, and they only contains no-op macros in that
+# case.
+EXPORTS += [
+    'public/BaseProfiler.h',
 ]
 
-include('/ipc/chromium/chromium-config.mozbuild')
-
-# GeckoProfiler.h and ProfilerCounts.h are the only code that's visible in
-# non-MOZ_GECKO_PROFILER builds, and they only contains no-op macros in that
-# case.
-EXPORTS += [
-    'public/GeckoProfiler.h',
-]
-
-# vm/GeckoProfiler.h needs to include this and doesn't like #include "ProfilerCounts.h"
 EXPORTS.mozilla += [
-    'public/ProfilerCounts.h',
+    'public/BaseProfilerCounts.h',
 ]
 
 if CONFIG['MOZ_VTUNE']:
     DEFINES['MOZ_VTUNE_INSTRUMENTATION'] = True
     UNIFIED_SOURCES += [
         'core/VTuneProfiler.cpp',
     ]
 
 
-if CONFIG['MOZ_TASK_TRACER']:
-    EXPORTS += [
-        'tasktracer/GeckoTaskTracer.h',
-        'tasktracer/GeckoTaskTracerImpl.h',
-        'tasktracer/SourceEventTypeMap.h',
-        'tasktracer/TracedTaskCommon.h',
-    ]
-    UNIFIED_SOURCES += [
-        'tasktracer/GeckoTaskTracer.cpp',
-        'tasktracer/TracedTaskCommon.cpp',
-    ]
-
-XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
-MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
-BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
-
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += [
         '-Wno-error=shadow',
         '-Wno-ignored-qualifiers', # due to use of breakpad headers
     ]
 
 with Files('**'):
     BUG_COMPONENT = ('Core', 'Gecko Profiler')
copy from tools/profiler/public/ProfileJSONWriter.h
copy to mozglue/baseprofiler/public/BaseProfileJSONWriter.h
copy from tools/profiler/public/GeckoProfiler.h
copy to mozglue/baseprofiler/public/BaseProfiler.h
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/mozglue/baseprofiler/public/BaseProfiler.h
@@ -12,23 +12,23 @@
 // Samples are collected to form a timeline with optional timeline event
 // (markers) used for filtering. The samples include both native stacks and
 // platform-independent "label stack" frames.
 
 #ifndef GeckoProfiler_h
 #define GeckoProfiler_h
 
 // everything in here is also safe to include unconditionally, and only defines
-// empty macros if MOZ_GECKO_PROFILER is unset
-#include "mozilla/ProfilerCounts.h"
+// empty macros if MOZ_BASE_PROFILER is unset
+#include "mozilla/BaseProfilerCounts.h"
 
-#ifndef MOZ_GECKO_PROFILER
+#ifndef MOZ_BASE_PROFILER
 
 // This file can be #included unconditionally. However, everything within this
-// file must be guarded by a #ifdef MOZ_GECKO_PROFILER, *except* for the
+// file must be guarded by a #ifdef MOZ_BASE_PROFILER, *except* for the
 // following macros, which encapsulate the most common operations and thus
 // avoid the need for many #ifdefs.
 
 #  define AUTO_PROFILER_INIT
 
 #  define PROFILER_REGISTER_THREAD(name)
 #  define PROFILER_UNREGISTER_THREAD()
 #  define AUTO_PROFILER_REGISTER_THREAD(name)
@@ -62,17 +62,17 @@
 #  define AUTO_PROFILER_TRACING_DOCSHELL(categoryString, markerName, \
                                          categoryPair, docShell)
 #  define AUTO_PROFILER_TEXT_MARKER_CAUSE(markerName, text, categoryPair, cause)
 #  define AUTO_PROFILER_TEXT_MARKER_DOCSHELL(markerName, text, categoryPair, \
                                              docShell)
 #  define AUTO_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE( \
       markerName, text, categoryPair, docShell, cause)
 
-#else  // !MOZ_GECKO_PROFILER
+#else  // !MOZ_BASE_PROFILER
 
 #  include "js/ProfilingStack.h"
 #  include "js/RootingAPI.h"
 #  include "js/TypeDecls.h"
 #  include "mozilla/Assertions.h"
 #  include "mozilla/Atomics.h"
 #  include "mozilla/Attributes.h"
 #  include "mozilla/GuardObjects.h"
@@ -1012,11 +1012,11 @@ class MOZ_RAII AutoProfilerTracing {
 // to make that child process start with the same profiler settings as
 // in the current process.  The given function is invoked once for
 // each variable to be set.
 void GetProfilerEnvVarsForChildProcess(
     std::function<void(const char* key, const char* value)>&& aSetEnv);
 
 }  // namespace mozilla
 
-#endif  // !MOZ_GECKO_PROFILER
+#endif  // !MOZ_BASE_PROFILER
 
 #endif  // GeckoProfiler_h
copy from tools/profiler/public/ProfilerCounts.h
copy to mozglue/baseprofiler/public/BaseProfilerCounts.h
--- a/tools/profiler/public/ProfilerCounts.h
+++ b/mozglue/baseprofiler/public/BaseProfilerCounts.h
@@ -2,17 +2,17 @@
 /* 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 ProfilerCounts_h
 #define ProfilerCounts_h
 
-#ifndef MOZ_GECKO_PROFILER
+#ifndef MOZ_BASE_PROFILER
 
 #  define PROFILER_DEFINE_COUNT_TOTAL(label, category, description)
 #  define PROFILER_DEFINE_COUNT(label, category, description)
 #  define PROFILER_DEFINE_STATIC_COUNT_TOTAL(label, category, description)
 #  define AUTO_PROFILER_TOTAL(label, count)
 #  define AUTO_PROFILER_COUNT(label)
 #  define AUTO_PROFILER_STATIC_COUNT(label, count)
 
@@ -261,11 +261,11 @@ class ProfilerCounterTotal final : publi
          * them                                                             \
          */                                                                 \
         AutoCount_##label.reset(new BaseProfilerCount(                      \
             #label, &profiler_count_##label, &profiler_number_##label,      \
             profiler_category_##label, profiler_description_##label));      \
       }                                                                     \
     } while (0)
 
-#endif  // !MOZ_GECKO_PROFILER
+#endif  // !MOZ_BASE_PROFILER
 
 #endif  // ProfilerCounts_h
copy from tools/profiler/public/ProfilerMarkerPayload.h
copy to mozglue/baseprofiler/public/BaseProfilerMarkerPayload.h
--- a/tools/profiler/public/ProfilerMarkerPayload.h
+++ b/mozglue/baseprofiler/public/BaseProfilerMarkerPayload.h
@@ -11,17 +11,17 @@
 #include "mozilla/Maybe.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "mozilla/net/TimingStruct.h"
 
 #include "nsString.h"
-#include "GeckoProfiler.h"
+#include "BaseProfiler.h"
 
 #include "js/Utility.h"
 #include "gfxASurface.h"
 #include "mozilla/ServoTraversalStatistics.h"
 
 namespace mozilla {
 namespace layers {
 class Layer;
copy from tools/profiler/public/shared-libraries.h
copy to mozglue/baseprofiler/public/BaseProfilerSharedLibraries.h
--- a/tools/profiler/public/shared-libraries.h
+++ b/mozglue/baseprofiler/public/BaseProfilerSharedLibraries.h
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 SHARED_LIBRARIES_H_
-#define SHARED_LIBRARIES_H_
+#ifndef BASE_PROFILER_SHARED_LIBRARIES_H_
+#define BASE_PROFILER_SHARED_LIBRARIES_H_
 
-#ifndef MOZ_GECKO_PROFILER
+#ifndef MOZ_BASE_PROFILER
 #  error This header does not have a useful implementation on your platform!
 #endif
 
 #include "nsNativeCharsetUtils.h"
 #include "nsString.h"
 #include <nsID.h>
 
 #include <algorithm>
@@ -147,9 +147,9 @@ class SharedLibraryInfo {
   }
 
   void Clear() { mEntries.clear(); }
 
  private:
   std::vector<SharedLibrary> mEntries;
 };
 
-#endif
+#endif  // BASE_PROFILER_SHARED_LIBRARIES_H_
copy from js/public/ProfilingCategory.h
copy to mozglue/baseprofiler/public/BaseProfilingCategory.h
copy from js/public/ProfilingStack.h
copy to mozglue/baseprofiler/public/BaseProfilingStack.h