Bug 1717991 - Profiler headers should declare all the marker related functions even when MOZ_GECKO_PROFILER is not defined, r=gerald.

Differential Revision: https://phabricator.services.mozilla.com/D118679
This commit is contained in:
Florian Quèze 2021-06-25 13:28:01 +00:00
parent 75b303b538
commit c87b4eb7b7
13 changed files with 168 additions and 195 deletions

View File

@ -13,9 +13,7 @@ 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",
@ -72,6 +70,8 @@ if CONFIG["MOZ_GECKO_PROFILER"]:
EXPORTS += [
"public/BaseProfiler.h",
"public/BaseProfilingCategory.h",
"public/ProfilingCategoryList.h",
]
EXPORTS.mozilla += [

View File

@ -50,9 +50,6 @@
// 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

View File

@ -13,15 +13,15 @@
#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 {

View File

@ -25,8 +25,6 @@
#include "mozilla/BaseProfilerMarkers.h"
#ifdef MOZ_GECKO_PROFILER
namespace mozilla::baseprofiler::markers {
struct MediaSampleMarker {
@ -64,6 +62,4 @@ struct ContentBuildMarker {
} // namespace mozilla::baseprofiler::markers
#endif // MOZ_GECKO_PROFILER
#endif // BaseProfilerMarkerTypes_h

View File

@ -32,18 +32,6 @@
#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)
#else // ndef MOZ_GECKO_PROFILER
#include "mozilla/BaseProfilerLabels.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Unused.h"
@ -54,6 +42,7 @@
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);
@ -82,6 +71,7 @@ inline ProfileBufferBlockIndex AddMarkerToBuffer(
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.
@ -96,12 +86,16 @@ 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.
@ -130,9 +124,8 @@ inline ProfileBufferBlockIndex AddMarker(const ProfilerString8View& aName,
do { \
AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_with_##MarkerType); \
::mozilla::baseprofiler::AddMarker( \
markerName, ::mozilla::baseprofiler::category::categoryName, \
options, ::mozilla::baseprofiler::markers::MarkerType{}, \
##__VA_ARGS__); \
markerName, ::mozilla::baseprofiler::category::categoryName, options, \
::mozilla::baseprofiler::markers::MarkerType{}, ##__VA_ARGS__); \
} while (false)
namespace mozilla::baseprofiler::markers {
@ -181,8 +174,8 @@ struct Tracing {
do { \
AUTO_PROFILER_STATS(BASE_PROFILER_MARKER_TEXT); \
::mozilla::baseprofiler::AddMarker( \
markerName, ::mozilla::baseprofiler::category::categoryName, \
options, ::mozilla::baseprofiler::markers::TextMarker{}, text); \
markerName, ::mozilla::baseprofiler::category::categoryName, options, \
::mozilla::baseprofiler::markers::TextMarker{}, text); \
} while (false)
namespace mozilla::baseprofiler {
@ -220,6 +213,7 @@ class MOZ_RAII AutoProfilerTextMarker {
std::string mText;
};
#ifdef MOZ_GECKO_PROFILER
extern template MFBT_API ProfileBufferBlockIndex
AddMarker(const ProfilerString8View&, const MarkerCategory&, MarkerOptions&&,
markers::TextMarker, const std::string&);
@ -231,6 +225,7 @@ AddMarkerToBuffer(ProfileChunkedBuffer&, const ProfilerString8View&,
extern template MFBT_API ProfileBufferBlockIndex AddMarkerToBuffer(
ProfileChunkedBuffer&, const ProfilerString8View&, const MarkerCategory&,
MarkerOptions&&, markers::TextMarker, const std::string&);
#endif // MOZ_GECKO_PROFILER
} // namespace mozilla::baseprofiler
@ -242,6 +237,4 @@ extern template MFBT_API ProfileBufferBlockIndex AddMarkerToBuffer(
markerName, ::mozilla::baseprofiler::category::categoryName, options, \
text)
#endif // nfed MOZ_GECKO_PROFILER else
#endif // BaseProfilerMarkers_h

View File

@ -13,8 +13,6 @@
#include "mozilla/BaseProfilerMarkersPrerequisites.h"
#ifdef MOZ_GECKO_PROFILER
// ~~ HERE BE DRAGONS ~~
//
// Everything below is internal implementation detail, you shouldn't need to
@ -673,6 +671,4 @@ struct ProfileBufferEntryReader::Deserializer<MarkerOptions> {
} // namespace mozilla
#endif // MOZ_GECKO_PROFILER
#endif // BaseProfilerMarkersDetail_h

View File

@ -24,8 +24,6 @@ enum class StackCaptureOptions {
}
#ifdef MOZ_GECKO_PROFILER
#include "BaseProfilingCategory.h"
#include "mozilla/Maybe.h"
#include "mozilla/ProfileChunkedBuffer.h"
@ -868,6 +866,4 @@ class MarkerSchema {
} // namespace mozilla
#endif // MOZ_GECKO_PROFILER
#endif // BaseProfilerMarkersPrerequisites_h

View File

@ -26,6 +26,15 @@
# 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"

View File

@ -7,10 +7,6 @@
#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>

View File

@ -4379,16 +4379,13 @@ void TestProfiler() {
# 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
@ -4398,23 +4395,19 @@ void TestProfiler() {
# 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");

View File

@ -20,9 +20,6 @@
#include "mozilla/BaseProfilerMarkerTypes.h"
#include "mozilla/ProfilerMarkers.h"
#ifdef MOZ_GECKO_PROFILER
#include "js/ProfilingFrameIterator.h"
#include "js/Utility.h"
#include "mozilla/Preferences.h"
@ -36,6 +33,4 @@ using ContentBuildMarker = mozilla::baseprofiler::markers::ContentBuildMarker;
} // namespace geckoprofiler::markers
#endif // MOZ_GECKO_PROFILER
#endif // ProfilerMarkerTypes_h

View File

@ -34,19 +34,6 @@
#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
@ -54,8 +41,17 @@ 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
@ -84,17 +80,18 @@ inline mozilla::MarkerInnerWindowId MarkerInnerWindowIdFromJSContext(
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
@ -121,6 +118,7 @@ inline mozilla::ProfileBufferBlockIndex AddMarkerToBuffer(
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.
@ -135,12 +133,16 @@ 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.
@ -157,8 +159,8 @@ inline mozilla::ProfileBufferBlockIndex profiler_add_marker(
#define PROFILER_MARKER_UNTYPED(markerName, categoryName, ...) \
do { \
AUTO_PROFILER_STATS(PROFILER_MARKER_UNTYPED); \
::profiler_add_marker( \
markerName, ::geckoprofiler::category::categoryName, ##__VA_ARGS__); \
::profiler_add_marker(markerName, ::geckoprofiler::category::categoryName, \
##__VA_ARGS__); \
} while (false)
// Same as `profiler_add_marker()` (with payload). This macro is safe to use
@ -166,9 +168,9 @@ inline mozilla::ProfileBufferBlockIndex profiler_add_marker(
#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__); \
::profiler_add_marker(markerName, ::geckoprofiler::category::categoryName, \
options, ::geckoprofiler::markers::MarkerType{}, \
##__VA_ARGS__); \
} while (false)
namespace geckoprofiler::markers {
@ -182,9 +184,9 @@ using Tracing = mozilla::baseprofiler::markers::Tracing;
#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); \
::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
@ -289,8 +291,7 @@ class MOZ_RAII AutoProfilerTracing {
};
// Adds a START/END pair of tracing markers.
# define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, \
categoryPair) \
#define AUTO_PROFILER_TRACING_MARKER(categoryString, markerName, categoryPair) \
AutoProfilerTracing PROFILER_RAII(categoryString, markerName, \
geckoprofiler::category::categoryPair, \
mozilla::Nothing())
@ -301,6 +302,7 @@ class MOZ_RAII AutoProfilerTracing {
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&&,
@ -325,7 +327,6 @@ 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

View File

@ -168,6 +168,7 @@ 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) {