author | Florian Quèze <florian@queze.net> |
Fri, 25 Jun 2021 13:28:01 +0000 | |
changeset 584438 | 8f7fc2f3bb310375bb8a3c4237060e748b0be1f1 |
parent 584437 | c6fa51eeceab4b086903245ebfc051f852ce39eb |
child 584439 | cd335ae78d20fc4cca8f5379a4f1fc351eedb783 |
push id | 145663 |
push user | fqueze@mozilla.com |
push date | Fri, 25 Jun 2021 13:30:32 +0000 |
treeherder | autoland@cd335ae78d20 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | gerald |
bugs | 1717991 |
milestone | 91.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
|
--- a/mozglue/baseprofiler/moz.build +++ b/mozglue/baseprofiler/moz.build @@ -8,19 +8,17 @@ # 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["IMPL_MFBT"] = True EXPORTS += [ "public/BaseProfilerSharedLibraries.h", - "public/BaseProfilingCategory.h", "public/BaseProfilingStack.h", - "public/ProfilingCategoryList.h", ] UNIFIED_SOURCES += [ "core/PageInformation.cpp", "core/platform.cpp", "core/ProfileBuffer.cpp", "core/ProfileBufferEntry.cpp", "core/ProfiledThreadData.cpp", "core/ProfileJSONWriter.cpp", @@ -67,16 +65,18 @@ if CONFIG["MOZ_GECKO_PROFILER"]: 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"] FINAL_LIBRARY = "mozglue" EXPORTS += [ "public/BaseProfiler.h", + "public/BaseProfilingCategory.h", + "public/ProfilingCategoryList.h", ] EXPORTS.mozilla += [ "public/BaseProfileJSONWriter.h", "public/BaseProfilerCounts.h", "public/BaseProfilerDetail.h", "public/BaseProfilerLabels.h", "public/BaseProfilerMarkers.h",
--- a/mozglue/baseprofiler/public/BaseProfiler.h +++ b/mozglue/baseprofiler/public/BaseProfiler.h @@ -45,19 +45,16 @@ # define AUTO_BASE_PROFILER_REGISTER_THREAD(name) # define AUTO_BASE_PROFILER_THREAD_SLEEP # define AUTO_BASE_PROFILER_THREAD_WAKE // Function stubs for when MOZ_GECKO_PROFILER is not defined. namespace mozilla { -// This won't be used, it's just there to allow the empty definition of -// `profiler_capture_backtrace`. -class ProfileChunkedBuffer {}; namespace baseprofiler { // This won't be used, it's just there to allow the empty definition of // `profiler_get_backtrace`. struct ProfilerBacktrace {}; using UniqueProfilerBacktrace = UniquePtr<ProfilerBacktrace>; // Get/Capture-backtrace functions can return nullptr or false, the result
--- a/mozglue/baseprofiler/public/BaseProfilerDetail.h +++ b/mozglue/baseprofiler/public/BaseProfilerDetail.h @@ -8,25 +8,25 @@ #ifndef BaseProfilerDetail_h #define BaseProfilerDetail_h #include "mozilla/Atomics.h" #include "mozilla/Maybe.h" #include "mozilla/PlatformMutex.h" -#ifndef MOZ_GECKO_PROFILER -# error Do not #include this header when MOZ_GECKO_PROFILER is not #defined. -#endif - namespace mozilla { namespace baseprofiler { +#ifdef MOZ_GECKO_PROFILER // Implemented in platform.cpp MFBT_API int profiler_current_thread_id(); +#else +inline int profiler_current_thread_id() { return 0; } +#endif // MOZ_GECKO_PROFILER namespace detail { // Thin shell around mozglue PlatformMutex, for Base Profiler internal use. class BaseProfilerMutex : private ::mozilla::detail::MutexImpl { public: BaseProfilerMutex() : ::mozilla::detail::MutexImpl() {} explicit BaseProfilerMutex(const char* aName)
--- a/mozglue/baseprofiler/public/BaseProfilerMarkerTypes.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkerTypes.h @@ -20,18 +20,16 @@ // !!! /!\ WORK IN PROGRESS /!\ !!! // This file contains draft marker definitions, but most are not used yet. // Further work is needed to complete these definitions, and use them to convert // existing PROFILER_ADD_MARKER calls. See meta bug 1661394. #include "mozilla/BaseProfilerMarkers.h" -#ifdef MOZ_GECKO_PROFILER - namespace mozilla::baseprofiler::markers { struct MediaSampleMarker { static constexpr Span<const char> MarkerTypeName() { return MakeStringSpan("MediaSample"); } static void StreamJSONMarkerData(SpliceableJSONWriter& aWriter, int64_t aSampleStartTimeUs, @@ -59,11 +57,9 @@ struct ContentBuildMarker { using MS = MarkerSchema; MS schema{MS::Location::markerChart, MS::Location::markerTable}; return schema; } }; } // namespace mozilla::baseprofiler::markers -#endif // MOZ_GECKO_PROFILER - #endif // BaseProfilerMarkerTypes_h
--- a/mozglue/baseprofiler/public/BaseProfilerMarkers.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkers.h @@ -27,38 +27,27 @@ // - Otherwise #include "ProfilerMarkers.h" instead, and use // `profiler_add_marker(...)`. // See these functions for more details. #ifndef BaseProfilerMarkers_h #define BaseProfilerMarkers_h #include "mozilla/BaseProfilerMarkersDetail.h" - -#ifndef MOZ_GECKO_PROFILER - -# define BASE_PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) -# define BASE_PROFILER_MARKER(markerName, categoryName, options, MarkerType, \ - ...) -# define BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) -# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, \ - text) +#include "mozilla/BaseProfilerLabels.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/Unused.h" -#else // ndef MOZ_GECKO_PROFILER - -# include "mozilla/BaseProfilerLabels.h" -# include "mozilla/TimeStamp.h" -# include "mozilla/Unused.h" - -# include <functional> -# include <string> -# include <utility> +#include <functional> +#include <string> +#include <utility> namespace mozilla::baseprofiler { +#ifdef MOZ_GECKO_PROFILER // Forward-declaration. TODO: Move to more common header, see bug 1681416. MFBT_API bool profiler_capture_backtrace_into( ProfileChunkedBuffer& aChunkedBuffer, StackCaptureOptions aCaptureOptions); // Add a marker to a given buffer. `AddMarker()` and related macros should be // used in most cases, see below for more information about them and the // parameters; This function may be useful when markers need to be recorded in a // local buffer outside of the main profiler buffer. @@ -77,68 +66,72 @@ ProfileBufferBlockIndex AddMarkerToBuffe // Add a marker (without payload) to a given buffer. inline ProfileBufferBlockIndex AddMarkerToBuffer( ProfileChunkedBuffer& aBuffer, const ProfilerString8View& aName, const MarkerCategory& aCategory, MarkerOptions&& aOptions = {}) { return AddMarkerToBuffer(aBuffer, aName, aCategory, std::move(aOptions), markers::NoPayload{}); } +#endif // MOZ_GECKO_PROFILER // Add a marker to the Base Profiler buffer. // - aName: Main name of this marker. // - aCategory: Category for this marker. // - aOptions: Optional settings (such as timing, inner window id, // backtrace...), see `MarkerOptions` for details. // - aMarkerType: Empty object that specifies the type of marker. // - aPayloadArguments: Arguments expected by this marker type's // ` StreamJSONMarkerData` function. template <typename MarkerType, typename... PayloadArguments> ProfileBufferBlockIndex AddMarker( const ProfilerString8View& aName, const MarkerCategory& aCategory, MarkerOptions&& aOptions, MarkerType aMarkerType, const PayloadArguments&... aPayloadArguments) { +#ifndef MOZ_GECKO_PROFILER + return {}; +#else if (!baseprofiler::profiler_can_accept_markers()) { return {}; } return ::mozilla::baseprofiler::AddMarkerToBuffer( base_profiler_markers_detail::CachedBaseCoreBuffer(), aName, aCategory, std::move(aOptions), aMarkerType, aPayloadArguments...); +#endif } // Add a marker (without payload) to the Base Profiler buffer. inline ProfileBufferBlockIndex AddMarker(const ProfilerString8View& aName, const MarkerCategory& aCategory, MarkerOptions&& aOptions = {}) { return AddMarker(aName, aCategory, std::move(aOptions), markers::NoPayload{}); } } // namespace mozilla::baseprofiler // Same as `AddMarker()` (without payload). This macro is safe to use even if // MOZ_GECKO_PROFILER is not #defined. -# define BASE_PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_UNTYPED); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - ##__VA_ARGS__); \ - } while (false) +#define BASE_PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_UNTYPED); \ + ::mozilla::baseprofiler::AddMarker( \ + markerName, ::mozilla::baseprofiler::category::categoryName, \ + ##__VA_ARGS__); \ + } while (false) // Same as `AddMarker()` (with payload). This macro is safe to use even if // MOZ_GECKO_PROFILER is not #defined. -# define BASE_PROFILER_MARKER(markerName, categoryName, options, MarkerType, \ - ...) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_with_##MarkerType); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - options, ::mozilla::baseprofiler::markers::MarkerType{}, \ - ##__VA_ARGS__); \ - } while (false) +#define BASE_PROFILER_MARKER(markerName, categoryName, options, MarkerType, \ + ...) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_with_##MarkerType); \ + ::mozilla::baseprofiler::AddMarker( \ + markerName, ::mozilla::baseprofiler::category::categoryName, options, \ + ::mozilla::baseprofiler::markers::MarkerType{}, ##__VA_ARGS__); \ + } while (false) namespace mozilla::baseprofiler::markers { // Most common marker type. Others are in BaseProfilerMarkerTypes.h. struct TextMarker { static constexpr Span<const char> MarkerTypeName() { return MakeStringSpan("Text"); } static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, @@ -172,23 +165,23 @@ struct Tracing { schema.AddKeyLabelFormat("category", "Type", MS::Format::string); return schema; } }; } // namespace mozilla::baseprofiler::markers // Add a text marker. This macro is safe to use even if MOZ_GECKO_PROFILER is // not #defined. -# define BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - do { \ - AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_TEXT); \ - ::mozilla::baseprofiler::AddMarker( \ - markerName, ::mozilla::baseprofiler::category::categoryName, \ - options, ::mozilla::baseprofiler::markers::TextMarker{}, text); \ - } while (false) +#define BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ + do { \ + AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_TEXT); \ + ::mozilla::baseprofiler::AddMarker( \ + markerName, ::mozilla::baseprofiler::category::categoryName, options, \ + ::mozilla::baseprofiler::markers::TextMarker{}, text); \ + } while (false) namespace mozilla::baseprofiler { // RAII object that adds a BASE_PROFILER_MARKER_TEXT when destroyed; the // marker's timing will be the interval from construction (unless an instant or // start time is already specified in the provided options) until destruction. class MOZ_RAII AutoProfilerTextMarker { public: @@ -215,33 +208,33 @@ class MOZ_RAII AutoProfilerTextMarker { protected: const char* mMarkerName; MarkerCategory mCategory; MarkerOptions mOptions; std::string mText; }; +#ifdef MOZ_GECKO_PROFILER extern template MFBT_API ProfileBufferBlockIndex AddMarker(const ProfilerString8View&, const MarkerCategory&, MarkerOptions&&, markers::TextMarker, const std::string&); extern template MFBT_API ProfileBufferBlockIndex AddMarkerToBuffer(ProfileChunkedBuffer&, const ProfilerString8View&, const MarkerCategory&, MarkerOptions&&, markers::NoPayload); extern template MFBT_API ProfileBufferBlockIndex AddMarkerToBuffer( ProfileChunkedBuffer&, const ProfilerString8View&, const MarkerCategory&, MarkerOptions&&, markers::TextMarker, const std::string&); +#endif // MOZ_GECKO_PROFILER } // namespace mozilla::baseprofiler // Creates an AutoProfilerTextMarker RAII object. This macro is safe to use // even if MOZ_GECKO_PROFILER is not #defined. -# define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, \ - text) \ - ::mozilla::baseprofiler::AutoProfilerTextMarker BASE_PROFILER_RAII( \ - markerName, ::mozilla::baseprofiler::category::categoryName, options, \ - text) - -#endif // nfed MOZ_GECKO_PROFILER else +#define AUTO_BASE_PROFILER_MARKER_TEXT(markerName, categoryName, options, \ + text) \ + ::mozilla::baseprofiler::AutoProfilerTextMarker BASE_PROFILER_RAII( \ + markerName, ::mozilla::baseprofiler::category::categoryName, options, \ + text) #endif // BaseProfilerMarkers_h
--- a/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h @@ -8,28 +8,26 @@ #define BaseProfilerMarkersDetail_h #ifndef BaseProfilerMarkers_h # error "This header should only be #included by BaseProfilerMarkers.h" #endif #include "mozilla/BaseProfilerMarkersPrerequisites.h" -#ifdef MOZ_GECKO_PROFILER - // ~~ HERE BE DRAGONS ~~ // // Everything below is internal implementation detail, you shouldn't need to // look at it unless working on the profiler code. -# include "mozilla/BaseProfileJSONWriter.h" -# include "mozilla/ProfileBufferEntryKinds.h" +#include "mozilla/BaseProfileJSONWriter.h" +#include "mozilla/ProfileBufferEntryKinds.h" -# include <limits> -# include <tuple> +#include <limits> +#include <tuple> namespace mozilla::baseprofiler { // Implemented in platform.cpp MFBT_API ProfileChunkedBuffer& profiler_get_core_buffer(); } // namespace mozilla::baseprofiler namespace mozilla::base_profiler_markers_detail { @@ -668,11 +666,9 @@ struct ProfileBufferEntryReader::Deseria MarkerOptions options; ReadInto(aER, options); return options; } }; } // namespace mozilla -#endif // MOZ_GECKO_PROFILER - #endif // BaseProfilerMarkersDetail_h
--- a/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkersPrerequisites.h @@ -19,32 +19,30 @@ enum class StackCaptureOptions { NoStack, // No stack captured. Full, // Capture a full stack, including label frames, JS frames and // native frames. NonNative, // Capture a stack without native frames for reduced overhead. }; } -#ifdef MOZ_GECKO_PROFILER +#include "BaseProfilingCategory.h" +#include "mozilla/Maybe.h" +#include "mozilla/ProfileChunkedBuffer.h" +#include "mozilla/BaseProfilerState.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/UniquePtr.h" +#include "mozilla/Variant.h" -# include "BaseProfilingCategory.h" -# include "mozilla/Maybe.h" -# include "mozilla/ProfileChunkedBuffer.h" -# include "mozilla/BaseProfilerState.h" -# include "mozilla/TimeStamp.h" -# include "mozilla/UniquePtr.h" -# include "mozilla/Variant.h" - -# include <initializer_list> -# include <string_view> -# include <string> -# include <type_traits> -# include <utility> -# include <vector> +#include <initializer_list> +#include <string_view> +#include <string> +#include <type_traits> +#include <utility> +#include <vector> namespace mozilla { // Return a NotNull<const CHAR*> pointing at the literal empty string `""`. template <typename CHAR> constexpr const CHAR* LiteralEmptyStringPointer() { static_assert(std::is_same_v<CHAR, char> || std::is_same_v<CHAR, char16_t>, "Only char and char16_t are supported in Firefox"); @@ -243,26 +241,26 @@ class MarkerCategory { }; namespace baseprofiler::category { // Each category pair name constructs a MarkerCategory. // E.g.: mozilla::baseprofiler::category::OTHER_Profiling // Profiler macros will take the category name alone without namespace. // E.g.: `PROFILER_MARKER_UNTYPED("name", OTHER_Profiling)` -# define CATEGORY_ENUM_BEGIN_CATEGORY(name, labelAsString, color) -# define CATEGORY_ENUM_SUBCATEGORY(supercategory, name, labelAsString) \ - static constexpr MarkerCategory name{ProfilingCategoryPair::name}; -# define CATEGORY_ENUM_END_CATEGORY +#define CATEGORY_ENUM_BEGIN_CATEGORY(name, labelAsString, color) +#define CATEGORY_ENUM_SUBCATEGORY(supercategory, name, labelAsString) \ + static constexpr MarkerCategory name{ProfilingCategoryPair::name}; +#define CATEGORY_ENUM_END_CATEGORY MOZ_PROFILING_CATEGORY_LIST(CATEGORY_ENUM_BEGIN_CATEGORY, CATEGORY_ENUM_SUBCATEGORY, CATEGORY_ENUM_END_CATEGORY) -# undef CATEGORY_ENUM_BEGIN_CATEGORY -# undef CATEGORY_ENUM_SUBCATEGORY -# undef CATEGORY_ENUM_END_CATEGORY +#undef CATEGORY_ENUM_BEGIN_CATEGORY +#undef CATEGORY_ENUM_SUBCATEGORY +#undef CATEGORY_ENUM_END_CATEGORY // Import `MarkerCategory` into this namespace. This will allow using this type // dynamically in macros that prepend `::mozilla::baseprofiler::category::` to // the given category, e.g.: // `PROFILER_MARKER_UNTYPED("name", MarkerCategory(...))` using MarkerCategory = ::mozilla::MarkerCategory; } // namespace baseprofiler::category @@ -530,34 +528,34 @@ class MarkerStack { private: explicit MarkerStack(StackCaptureOptions aCaptureOptions) : mCaptureOptions(aCaptureOptions) { AssertInvariants(); } // This should be called after every constructor and non-const function. void AssertInvariants() const { -# ifdef DEBUG +#ifdef DEBUG if (mCaptureOptions != StackCaptureOptions::NoStack) { MOZ_ASSERT(!mOptionalChunkedBufferStorage, "We should not hold a buffer when capture is requested"); MOZ_ASSERT(!mChunkedBuffer, "We should not point at a buffer when capture is requested"); } else { if (mOptionalChunkedBufferStorage) { MOZ_ASSERT(mChunkedBuffer == mOptionalChunkedBufferStorage.get(), "Non-null mOptionalChunkedBufferStorage must be pointed-at " "by mChunkedBuffer"); } if (mChunkedBuffer) { MOZ_ASSERT(!mChunkedBuffer->IsEmpty(), "Non-null mChunkedBuffer must not be empty"); } } -# endif // DEBUG +#endif // DEBUG } StackCaptureOptions mCaptureOptions = StackCaptureOptions::NoStack; // Optional storage for the backtrace, in case it was captured before the // add-marker call. UniquePtr<ProfileChunkedBuffer> mOptionalChunkedBufferStorage; @@ -619,36 +617,36 @@ class MarkerOptions { // Each option may be added in a chain by e.g.: // `options.Set(MarkerThreadId(123)).Set(MarkerTiming::IntervalEnd())`. // When passed to an add-marker function, it must be an rvalue, either created // on the spot, or `std::move`d from storage, e.g.: // `PROFILER_MARKER_UNTYPED("...", std::move(options).Set(...))`; // // Options can be read by their name (without "Marker"), e.g.: `o.ThreadId()`. // Add "Ref" for a non-const reference, e.g.: `o.ThreadIdRef() = ...;` -# define FUNCTIONS_ON_MEMBER(NAME) \ - MarkerOptions& Set(Marker##NAME&& a##NAME)& { \ - m##NAME = std::move(a##NAME); \ - return *this; \ - } \ - \ - MarkerOptions&& Set(Marker##NAME&& a##NAME)&& { \ - m##NAME = std::move(a##NAME); \ - return std::move(*this); \ - } \ - \ - const Marker##NAME& NAME() const { return m##NAME; } \ - \ - Marker##NAME& NAME##Ref() { return m##NAME; } +#define FUNCTIONS_ON_MEMBER(NAME) \ + MarkerOptions& Set(Marker##NAME&& a##NAME)& { \ + m##NAME = std::move(a##NAME); \ + return *this; \ + } \ + \ + MarkerOptions&& Set(Marker##NAME&& a##NAME)&& { \ + m##NAME = std::move(a##NAME); \ + return std::move(*this); \ + } \ + \ + const Marker##NAME& NAME() const { return m##NAME; } \ + \ + Marker##NAME& NAME##Ref() { return m##NAME; } FUNCTIONS_ON_MEMBER(ThreadId); FUNCTIONS_ON_MEMBER(Timing); FUNCTIONS_ON_MEMBER(Stack); FUNCTIONS_ON_MEMBER(InnerWindowId); -# undef FUNCTIONS_ON_MEMBER +#undef FUNCTIONS_ON_MEMBER private: friend ProfileBufferEntryReader::Deserializer<MarkerOptions>; MarkerThreadId mThreadId; MarkerTiming mTiming; MarkerStack mStack; MarkerInnerWindowId mInnerWindowId; @@ -758,27 +756,27 @@ class MarkerSchema { // Caller must specify location(s) or SpecialFrontendLocation above. MarkerSchema() = delete; // Optional labels in the marker chart, the chart tooltip, and the marker // table. If not provided, the marker "name" will be used. The given string // can contain element keys in braces to include data elements streamed by // `StreamJSONMarkerData()`. E.g.: "This is {text}" -# define LABEL_SETTER(name) \ - MarkerSchema& Set##name(std::string a##name) { \ - m##name = std::move(a##name); \ - return *this; \ - } +#define LABEL_SETTER(name) \ + MarkerSchema& Set##name(std::string a##name) { \ + m##name = std::move(a##name); \ + return *this; \ + } LABEL_SETTER(ChartLabel) LABEL_SETTER(TooltipLabel) LABEL_SETTER(TableLabel) -# undef LABEL_SETTER +#undef LABEL_SETTER MarkerSchema& SetAllLabels(std::string aText) { // Here we set the same text in each label. // TODO: Move to a single "label" field once the front-end allows it. SetChartLabel(aText); SetTooltipLabel(aText); SetTableLabel(std::move(aText)); return *this; @@ -863,11 +861,9 @@ class MarkerSchema { using DataRow = mozilla::Variant<DynamicData, StaticData>; using DataRowVector = std::vector<DataRow>; DataRowVector mData; }; } // namespace mozilla -#endif // MOZ_GECKO_PROFILER - #endif // BaseProfilerMarkersPrerequisites_h
--- a/mozglue/baseprofiler/public/BaseProfilerState.h +++ b/mozglue/baseprofiler/public/BaseProfilerState.h @@ -21,16 +21,25 @@ // some generic process and thread information. // It is safe to include unconditionally, but uses of structs and functions must // be guarded by `#ifdef MOZ_GECKO_PROFILER`. #ifndef MOZ_GECKO_PROFILER # define AUTO_PROFILER_STATS(name) +namespace mozilla { + +namespace baseprofiler { + +inline int profiler_main_thread_id() { return 0; } + +} // namespace baseprofiler +} // namespace mozilla + #else // !MOZ_GECKO_PROFILER # include "mozilla/Atomics.h" # include "mozilla/Maybe.h" # include <stdint.h> # include <string>
--- a/mozglue/baseprofiler/public/BaseProfilingCategory.h +++ b/mozglue/baseprofiler/public/BaseProfilingCategory.h @@ -2,20 +2,16 @@ * vim: set ts=8 sts=4 et sw=4 tw=99: * 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 BaseProfilingCategory_h #define BaseProfilingCategory_h -#ifndef MOZ_GECKO_PROFILER -# error Do not #include this header when MOZ_GECKO_PROFILER is not #defined. -#endif - #include "mozilla/Types.h" #include <cstdint> #include "ProfilingCategoryList.h" namespace mozilla { namespace baseprofiler {
--- a/mozglue/tests/TestBaseProfiler.cpp +++ b/mozglue/tests/TestBaseProfiler.cpp @@ -4374,52 +4374,45 @@ void TestProfiler() { // These don't need to make sense, we just want to know that they're defined // and don't do anything. # ifndef AUTO_BASE_PROFILER_INIT # error AUTO_BASE_PROFILER_INIT not #defined # endif // AUTO_BASE_PROFILER_INIT AUTO_BASE_PROFILER_INIT; - // This wouldn't build if the macro did output its arguments. # ifndef AUTO_BASE_PROFILER_MARKER_TEXT # error AUTO_BASE_PROFILER_MARKER_TEXT not #defined # endif // AUTO_BASE_PROFILER_MARKER_TEXT - AUTO_BASE_PROFILER_MARKER_TEXT(catch, catch, catch, catch); # ifndef AUTO_BASE_PROFILER_LABEL # error AUTO_BASE_PROFILER_LABEL not #defined # endif // AUTO_BASE_PROFILER_LABEL - AUTO_BASE_PROFILER_LABEL(catch, catch); # ifndef AUTO_BASE_PROFILER_THREAD_SLEEP # error AUTO_BASE_PROFILER_THREAD_SLEEP not #defined # endif // AUTO_BASE_PROFILER_THREAD_SLEEP AUTO_BASE_PROFILER_THREAD_SLEEP; # ifndef BASE_PROFILER_MARKER_UNTYPED # error BASE_PROFILER_MARKER_UNTYPED not #defined # endif // BASE_PROFILER_MARKER_UNTYPED - BASE_PROFILER_MARKER_UNTYPED(catch, catch); - BASE_PROFILER_MARKER_UNTYPED(catch, catch, catch); # ifndef BASE_PROFILER_MARKER # error BASE_PROFILER_MARKER not #defined # endif // BASE_PROFILER_MARKER - BASE_PROFILER_MARKER(catch, catch, catch, catch); - BASE_PROFILER_MARKER(catch, catch, catch, catch, catch); # ifndef BASE_PROFILER_MARKER_TEXT # error BASE_PROFILER_MARKER_TEXT not #defined # endif // BASE_PROFILER_MARKER_TEXT - BASE_PROFILER_MARKER_TEXT(catch, catch, catch, catch); MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_get_backtrace(), "profiler_get_backtrace should return nullptr"); - mozilla::ProfileChunkedBuffer buffer; + mozilla::ProfileChunkedBuffer buffer( + mozilla::ProfileChunkedBuffer::ThreadSafety::WithoutMutex); MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_capture_backtrace_into( buffer, mozilla::StackCaptureOptions::Full), "profiler_capture_backtrace_into should return false"); MOZ_RELEASE_ASSERT(!mozilla::baseprofiler::profiler_capture_backtrace(), "profiler_capture_backtrace should return nullptr"); } // Testing that macros are still #defined (but do nothing) when
--- a/tools/profiler/public/ProfilerMarkerTypes.h +++ b/tools/profiler/public/ProfilerMarkerTypes.h @@ -15,27 +15,22 @@ // !!! /!\ WORK IN PROGRESS /!\ !!! // This file contains draft marker definitions, but most are not used yet. // Further work is needed to complete these definitions, and use them to convert // existing PROFILER_ADD_MARKER calls. See meta bug 1661394. #include "mozilla/BaseProfilerMarkerTypes.h" #include "mozilla/ProfilerMarkers.h" - -#ifdef MOZ_GECKO_PROFILER - -# include "js/ProfilingFrameIterator.h" -# include "js/Utility.h" -# include "mozilla/Preferences.h" -# include "mozilla/ServoTraversalStatistics.h" +#include "js/ProfilingFrameIterator.h" +#include "js/Utility.h" +#include "mozilla/Preferences.h" +#include "mozilla/ServoTraversalStatistics.h" namespace geckoprofiler::markers { // Import some common markers from mozilla::baseprofiler::markers. using MediaSampleMarker = mozilla::baseprofiler::markers::MediaSampleMarker; using ContentBuildMarker = mozilla::baseprofiler::markers::ContentBuildMarker; } // namespace geckoprofiler::markers -#endif // MOZ_GECKO_PROFILER - #endif // ProfilerMarkerTypes_h
--- a/tools/profiler/public/ProfilerMarkers.h +++ b/tools/profiler/public/ProfilerMarkers.h @@ -29,38 +29,34 @@ // `profiler_add_marker(...)`. // See these functions for more details. #ifndef ProfilerMarkers_h #define ProfilerMarkers_h #include "mozilla/BaseProfilerMarkers.h" #include "mozilla/ProfilerMarkersDetail.h" - -#ifndef MOZ_GECKO_PROFILER - -# define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) -# define PROFILER_MARKER(markerName, categoryName, options, MarkerType, ...) -# define PROFILER_MARKER_TEXT(markerName, categoryName, options, text) -# define AUTO_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) -# define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair) -# define AUTO_PROFILER_TRACING_MARKER_DOCSHELL(categoryString, markerName, \ - categoryPair, docShell) - -#else // ndef MOZ_GECKO_PROFILER - -# include "mozilla/ProfilerLabels.h" -# include "nsJSUtils.h" // for nsJSUtils::GetCurrentlyRunningCodeInnerWindowID +#include "mozilla/ProfilerLabels.h" +#include "nsJSUtils.h" // for nsJSUtils::GetCurrentlyRunningCodeInnerWindowID class nsIDocShell; namespace geckoprofiler::markers::detail { // Please do not use anything from the detail namespace outside the profiler. + +#ifdef MOZ_GECKO_PROFILER mozilla::Maybe<uint64_t> profiler_get_inner_window_id_from_docshell( nsIDocShell* aDocshell); +#else +inline mozilla::Maybe<uint64_t> profiler_get_inner_window_id_from_docshell( + nsIDocShell* aDocshell) { + return mozilla::Nothing(); +} +#endif // MOZ_GECKO_PROFILER + } // namespace geckoprofiler::markers::detail // This is a helper function to get the Inner Window ID from DocShell but it's // not a recommended method to get it and it's not encouraged to use this // function. If there is a computed inner window ID, `window`, or `Document` // available in the call site, please use them. Use this function as a last // resort. inline mozilla::MarkerInnerWindowId MarkerInnerWindowIdFromDocShell( @@ -79,27 +75,28 @@ inline mozilla::MarkerInnerWindowId Mark // available in the call site, please use them. Use this function as a last // resort. inline mozilla::MarkerInnerWindowId MarkerInnerWindowIdFromJSContext( JSContext* aContext) { return mozilla::MarkerInnerWindowId( nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(aContext)); } -// Forward-declaration. TODO: Move to more common header, see bug 1681416. -bool profiler_capture_backtrace_into( - mozilla::ProfileChunkedBuffer& aChunkedBuffer, - mozilla::StackCaptureOptions aCaptureOptions); - // Bring category names from Base Profiler into the geckoprofiler::category // namespace, for consistency with other Gecko Profiler identifiers. namespace geckoprofiler::category { using namespace ::mozilla::baseprofiler::category; } +#ifdef MOZ_GECKO_PROFILER +// Forward-declaration. TODO: Move to more common header, see bug 1681416. +bool profiler_capture_backtrace_into( + mozilla::ProfileChunkedBuffer& aChunkedBuffer, + mozilla::StackCaptureOptions aCaptureOptions); + // Add a marker to a given buffer. `AddMarker()` and related macros should be // used in most cases, see below for more information about them and the // paramters; This function may be useful when markers need to be recorded in a // local buffer outside of the main profiler buffer. template <typename MarkerType, typename... PayloadArguments> mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( mozilla::ProfileChunkedBuffer& aBuffer, const mozilla::ProfilerString8View& aName, @@ -116,81 +113,86 @@ mozilla::ProfileBufferBlockIndex AddMark inline mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( mozilla::ProfileChunkedBuffer& aBuffer, const mozilla::ProfilerString8View& aName, const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions = {}) { return AddMarkerToBuffer(aBuffer, aName, aCategory, std::move(aOptions), mozilla::baseprofiler::markers::NoPayload{}); } +#endif // Add a marker to the Gecko Profiler buffer. // - aName: Main name of this marker. // - aCategory: Category for this marker. // - aOptions: Optional settings (such as timing, inner window id, // backtrace...), see `MarkerOptions` for details. // - aMarkerType: Empty object that specifies the type of marker. // - aPayloadArguments: Arguments expected by this marker type's // ` StreamJSONMarkerData` function. template <typename MarkerType, typename... PayloadArguments> mozilla::ProfileBufferBlockIndex profiler_add_marker( const mozilla::ProfilerString8View& aName, const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions, MarkerType aMarkerType, const PayloadArguments&... aPayloadArguments) { +#ifndef MOZ_GECKO_PROFILER + return {}; +#else if (!profiler_can_accept_markers()) { return {}; } return ::AddMarkerToBuffer(profiler_markers_detail::CachedCoreBuffer(), aName, aCategory, std::move(aOptions), aMarkerType, aPayloadArguments...); +#endif } // Add a marker (without payload) to the Gecko Profiler buffer. inline mozilla::ProfileBufferBlockIndex profiler_add_marker( const mozilla::ProfilerString8View& aName, const mozilla::MarkerCategory& aCategory, mozilla::MarkerOptions&& aOptions = {}) { return profiler_add_marker(aName, aCategory, std::move(aOptions), mozilla::baseprofiler::markers::NoPayload{}); } // Same as `profiler_add_marker()` (without payload). This macro is safe to use // even if MOZ_GECKO_PROFILER is not #defined. -# define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ - do { \ - AUTO_PROFILER_STATS(PROFILER_MARKER_UNTYPED); \ - ::profiler_add_marker( \ - markerName, ::geckoprofiler::category::categoryName, ##__VA_ARGS__); \ - } while (false) +#define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \ + do { \ + AUTO_PROFILER_STATS(PROFILER_MARKER_UNTYPED); \ + ::profiler_add_marker(markerName, ::geckoprofiler::category::categoryName, \ + ##__VA_ARGS__); \ + } while (false) // Same as `profiler_add_marker()` (with payload). This macro is safe to use // even if MOZ_GECKO_PROFILER is not #defined. -# define PROFILER_MARKER(markerName, categoryName, options, MarkerType, ...) \ - do { \ - AUTO_PROFILER_STATS(PROFILER_MARKER_with_##MarkerType); \ - ::profiler_add_marker( \ - markerName, ::geckoprofiler::category::categoryName, options, \ - ::geckoprofiler::markers::MarkerType{}, ##__VA_ARGS__); \ - } while (false) +#define PROFILER_MARKER(markerName, categoryName, options, MarkerType, ...) \ + do { \ + AUTO_PROFILER_STATS(PROFILER_MARKER_with_##MarkerType); \ + ::profiler_add_marker(markerName, ::geckoprofiler::category::categoryName, \ + options, ::geckoprofiler::markers::MarkerType{}, \ + ##__VA_ARGS__); \ + } while (false) namespace geckoprofiler::markers { // Most common marker types. Others are in ProfilerMarkerTypes.h. using TextMarker = ::mozilla::baseprofiler::markers::TextMarker; using Tracing = mozilla::baseprofiler::markers::Tracing; } // namespace geckoprofiler::markers // Add a text marker. This macro is safe to use even if MOZ_GECKO_PROFILER is // not #defined. -# define PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - do { \ - AUTO_PROFILER_STATS(PROFILER_MARKER_TEXT); \ - ::profiler_add_marker(markerName, \ - ::geckoprofiler::category::categoryName, options, \ - ::geckoprofiler::markers::TextMarker{}, text); \ - } while (false) +#define PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ + do { \ + AUTO_PROFILER_STATS(PROFILER_MARKER_TEXT); \ + ::profiler_add_marker(markerName, ::geckoprofiler::category::categoryName, \ + options, ::geckoprofiler::markers::TextMarker{}, \ + text); \ + } while (false) // RAII object that adds a PROFILER_MARKER_TEXT when destroyed; the marker's // timing will be the interval from construction (unless an instant or start // time is already specified in the provided options) until destruction. class MOZ_RAII AutoProfilerTextMarker { public: AutoProfilerTextMarker(const char* aMarkerName, const mozilla::MarkerCategory& aCategory, @@ -221,20 +223,20 @@ class MOZ_RAII AutoProfilerTextMarker { const char* mMarkerName; mozilla::MarkerCategory mCategory; mozilla::MarkerOptions mOptions; nsCString mText; }; // Creates an AutoProfilerTextMarker RAII object. This macro is safe to use // even if MOZ_GECKO_PROFILER is not #defined. -# define AUTO_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ - AutoProfilerTextMarker PROFILER_RAII( \ - markerName, ::mozilla::baseprofiler::category::categoryName, options, \ - text) +#define AUTO_PROFILER_MARKER_TEXT(markerName, categoryName, options, text) \ + AutoProfilerTextMarker PROFILER_RAII( \ + markerName, ::mozilla::baseprofiler::category::categoryName, options, \ + text) class MOZ_RAII AutoProfilerTracing { public: AutoProfilerTracing(const char* aCategoryString, const char* aMarkerName, mozilla::MarkerCategory aCategoryPair, const mozilla::Maybe<uint64_t>& aInnerWindowID) : mCategoryString(aCategoryString), mMarkerName(aMarkerName), @@ -284,28 +286,28 @@ class MOZ_RAII AutoProfilerTracing { protected: const char* mCategoryString; const char* mMarkerName; const mozilla::MarkerCategory mCategoryPair; const mozilla::Maybe<uint64_t> mInnerWindowID; }; // Adds a START/END pair of tracing markers. -# define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, \ - categoryPair) \ - AutoProfilerTracing PROFILER_RAII(categoryString, markerName, \ - geckoprofiler::category::categoryPair, \ - mozilla::Nothing()) -# define AUTO_PROFILER_TRACING_MARKER_DOCSHELL(categoryString, markerName, \ - categoryPair, docShell) \ - AutoProfilerTracing PROFILER_RAII( \ - categoryString, markerName, geckoprofiler::category::categoryPair, \ - geckoprofiler::markers::detail:: \ - profiler_get_inner_window_id_from_docshell(docShell)) +#define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair) \ + AutoProfilerTracing PROFILER_RAII(categoryString, markerName, \ + geckoprofiler::category::categoryPair, \ + mozilla::Nothing()) +#define AUTO_PROFILER_TRACING_MARKER_DOCSHELL(categoryString, markerName, \ + categoryPair, docShell) \ + AutoProfilerTracing PROFILER_RAII( \ + categoryString, markerName, geckoprofiler::category::categoryPair, \ + geckoprofiler::markers::detail:: \ + profiler_get_inner_window_id_from_docshell(docShell)) +#ifdef MOZ_GECKO_PROFILER extern template mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( mozilla::ProfileChunkedBuffer&, const mozilla::ProfilerString8View&, const mozilla::MarkerCategory&, mozilla::MarkerOptions&&, mozilla::baseprofiler::markers::NoPayload); extern template mozilla::ProfileBufferBlockIndex AddMarkerToBuffer( mozilla::ProfileChunkedBuffer&, const mozilla::ProfilerString8View&, const mozilla::MarkerCategory&, mozilla::MarkerOptions&&, @@ -320,12 +322,11 @@ extern template mozilla::ProfileBufferBl const mozilla::ProfilerString8View&, const mozilla::MarkerCategory&, mozilla::MarkerOptions&&, mozilla::baseprofiler::markers::TextMarker, const nsCString&); extern template mozilla::ProfileBufferBlockIndex profiler_add_marker( const mozilla::ProfilerString8View&, const mozilla::MarkerCategory&, mozilla::MarkerOptions&&, mozilla::baseprofiler::markers::Tracing, const mozilla::ProfilerString8View&); - -#endif // nfed MOZ_GECKO_PROFILER else +#endif // MOZ_GECKO_PROFILER #endif // ProfilerMarkers_h
--- a/tools/profiler/public/ProfilerState.h +++ b/tools/profiler/public/ProfilerState.h @@ -163,16 +163,17 @@ using ProfilingStateChangeCallback = std #ifndef MOZ_GECKO_PROFILER inline bool profiler_is_active() { return false; } inline bool profiler_can_accept_markers() { return false; } inline bool profiler_thread_is_being_profiled() { return false; } inline bool profiler_is_active_and_thread_is_registered() { return false; } inline bool profiler_feature_active(uint32_t aFeature) { return false; } inline bool profiler_is_locked_on_current_thread() { return false; } +inline int profiler_current_thread_id() { return 0; } inline void profiler_add_state_change_callback( ProfilingStateSet aProfilingStateSet, ProfilingStateChangeCallback&& aCallback, uintptr_t aUniqueIdentifier = 0) { } inline void profiler_remove_state_change_callback(uintptr_t aUniqueIdentifier) { } #else // !MOZ_GECKO_PROFILER