Skip to content

Commit

Permalink
Bug 1403868 (part 4) - Reduce tools/profiler/public/*.h to almost not…
Browse files Browse the repository at this point in the history
…hing in non-MOZ_GECKO_PROFILER builds. r=mstange.

Currently the Gecko Profiler defines a moderate amount of stuff when
MOZ_GECKO_PROFILER is undefined. It also #includes various headers, including
JS ones. This is making it difficult to separate Gecko's media stack for
inclusion in Servo.

This patch greatly simplifies how things are exposed. The starting point is:

- GeckoProfiler.h can be #included unconditionally;

- everything else from the profiler must be guarded by MOZ_GECKO_PROFILER.

In practice this introduces way too many #ifdefs, so the patch loosens it by
adding no-op macros for a number of the most common operations.

The net result is that #ifdefs and macros are used a bit more, but almost
nothing is exposed in non-MOZ_GECKO_PROFILER builds (including
ProfilerMarkerPayload.h and GeckoProfiler.h), and understanding what is exposed
is much simpler than before.

Note also that in BHR, ThreadStackHelper is now entirely absent in
non-MOZ_GECKO_PROFILER builds.
  • Loading branch information
nnethercote committed Oct 3, 2017
1 parent 24c5f71 commit dd9e0a7
Show file tree
Hide file tree
Showing 85 changed files with 396 additions and 272 deletions.
2 changes: 2 additions & 0 deletions accessible/generic/Accessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ Accessible::HandleAccEvent(AccEvent* aEvent)
{
NS_ENSURE_ARG_POINTER(aEvent);

#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
nsAutoCString strEventType;
GetAccService()->GetStringEventType(aEvent->GetEventType(), strEventType);
Expand All @@ -853,6 +854,7 @@ Accessible::HandleAccEvent(AccEvent* aEvent)
strMarker.Append(strEventType);
profiler_add_marker(strMarker.get());
}
#endif

if (IPCAccessibilityActive() && Document()) {
DocAccessibleChild* ipcDoc = mDoc->IPCDoc();
Expand Down
24 changes: 13 additions & 11 deletions dom/base/nsDOMNavigationTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ nsDOMNavigationTiming::NotifyNavigationStart(DocShellState aDocShellState)
mNavigationStartHighRes = (double)PR_Now() / PR_USEC_PER_MSEC;
mNavigationStart = TimeStamp::Now();
mDocShellHasBeenActiveSinceNavigationStart = (aDocShellState == DocShellState::eActive);
profiler_add_marker("Navigation::Start");
PROFILER_ADD_MARKER("Navigation::Start");
}

void
Expand Down Expand Up @@ -98,14 +98,14 @@ void
nsDOMNavigationTiming::NotifyUnloadEventStart()
{
mUnloadStart = TimeStamp::Now();
profiler_tracing("Navigation", "Unload", TRACING_INTERVAL_START);
PROFILER_TRACING("Navigation", "Unload", TRACING_INTERVAL_START);
}

void
nsDOMNavigationTiming::NotifyUnloadEventEnd()
{
mUnloadEnd = TimeStamp::Now();
profiler_tracing("Navigation", "Unload", TRACING_INTERVAL_END);
PROFILER_TRACING("Navigation", "Unload", TRACING_INTERVAL_END);
}

void
Expand All @@ -116,7 +116,7 @@ nsDOMNavigationTiming::NotifyLoadEventStart()
}
mLoadEventStart = TimeStamp::Now();

profiler_tracing("Navigation", "Load", TRACING_INTERVAL_START);
PROFILER_TRACING("Navigation", "Load", TRACING_INTERVAL_START);

if (IsTopLevelContentDocumentInContentProcess()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_LOAD_EVENT_START_MS,
Expand All @@ -132,7 +132,7 @@ nsDOMNavigationTiming::NotifyLoadEventEnd()
}
mLoadEventEnd = TimeStamp::Now();

profiler_tracing("Navigation", "Load", TRACING_INTERVAL_END);
PROFILER_TRACING("Navigation", "Load", TRACING_INTERVAL_END);

if (IsTopLevelContentDocumentInContentProcess()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_LOAD_EVENT_END_MS,
Expand All @@ -159,7 +159,7 @@ nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI)
mLoadedURI = aURI;
mDOMLoading = TimeStamp::Now();

profiler_add_marker("Navigation::DOMLoading");
PROFILER_ADD_MARKER("Navigation::DOMLoading");
}

void
Expand All @@ -171,7 +171,7 @@ nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI)
mLoadedURI = aURI;
mDOMInteractive = TimeStamp::Now();

profiler_add_marker("Navigation::DOMInteractive");
PROFILER_ADD_MARKER("Navigation::DOMInteractive");
}

void
Expand All @@ -183,7 +183,7 @@ nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI)
mLoadedURI = aURI;
mDOMComplete = TimeStamp::Now();

profiler_add_marker("Navigation::DOMComplete");
PROFILER_ADD_MARKER("Navigation::DOMComplete");
}

void
Expand All @@ -196,7 +196,7 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI)
mLoadedURI = aURI;
mDOMContentLoadedEventStart = TimeStamp::Now();

profiler_tracing("Navigation", "DOMContentLoaded", TRACING_INTERVAL_START);
PROFILER_TRACING("Navigation", "DOMContentLoaded", TRACING_INTERVAL_START);

if (IsTopLevelContentDocumentInContentProcess()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_CONTENT_LOADED_START_MS,
Expand All @@ -214,7 +214,7 @@ nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
mLoadedURI = aURI;
mDOMContentLoadedEventEnd = TimeStamp::Now();

profiler_tracing("Navigation", "DOMContentLoaded", TRACING_INTERVAL_END);
PROFILER_TRACING("Navigation", "DOMContentLoaded", TRACING_INTERVAL_END);

if (IsTopLevelContentDocumentInContentProcess()) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_DOM_CONTENT_LOADED_END_MS,
Expand All @@ -233,9 +233,10 @@ nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument()
}

mNonBlankPaint = TimeStamp::Now();
TimeDuration elapsed = mNonBlankPaint - mNavigationStart;

#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
TimeDuration elapsed = mNonBlankPaint - mNavigationStart;
nsAutoCString spec;
if (mLoadedURI) {
mLoadedURI->GetSpec(spec);
Expand All @@ -245,6 +246,7 @@ nsDOMNavigationTiming::NotifyNonBlankPaintForRootContentDocument()
mDocShellHasBeenActiveSinceNavigationStart ? "foreground tab" : "this tab was inactive some of the time between navigation start and first non-blank paint");
profiler_add_marker(marker.get());
}
#endif

if (mDocShellHasBeenActiveSinceNavigationStart) {
Telemetry::AccumulateTimeDelta(Telemetry::TIME_TO_NON_BLANK_PAINT_MS,
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3521,7 +3521,7 @@ PrepareForFullscreenChange(nsIPresShell* aPresShell, const nsSize& aSize,
NS_IMETHODIMP
nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal)
{
profiler_add_marker("Enter fullscreen");
PROFILER_ADD_MARKER("Enter fullscreen");
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_STATE(doc);

Expand All @@ -3544,7 +3544,7 @@ nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal)
nsresult
nsDOMWindowUtils::ExitFullscreen()
{
profiler_add_marker("Exit fullscreen");
PROFILER_ADD_MARKER("Exit fullscreen");
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_STATE(doc);

Expand Down
4 changes: 4 additions & 0 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,13 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName,
JS::MutableHandle<JS::Value> aRetval,
bool aIsSync)
{
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
NS_LossyConvertUTF16toASCII messageNameCStr(aMessageName);
AUTO_PROFILER_LABEL_DYNAMIC("nsFrameMessageManager::SendMessage", EVENTS,
messageNameCStr.get());
}
#endif

NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome");
Expand Down Expand Up @@ -1539,12 +1541,14 @@ void
nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
bool aRunInGlobalScope)
{
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
NS_LossyConvertUTF16toASCII urlCStr(aURL);
AUTO_PROFILER_LABEL_DYNAMIC(
"nsMessageManagerScriptExecutor::LoadScriptInternal", OTHER,
urlCStr.get());
}
#endif

if (!mGlobal || !sCachedScripts) {
return;
Expand Down
10 changes: 5 additions & 5 deletions dom/base/nsGlobalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7060,12 +7060,12 @@ FullscreenTransitionTask::Run()
return NS_OK;
}
if (stage == eBeforeToggle) {
profiler_add_marker("Fullscreen transition start");
PROFILER_ADD_MARKER("Fullscreen transition start");
mWidget->PerformFullscreenTransition(nsIWidget::eBeforeFullscreenToggle,
mDuration.mFadeIn, mTransitionData,
this);
} else if (stage == eToggleFullscreen) {
profiler_add_marker("Fullscreen toggle start");
PROFILER_ADD_MARKER("Fullscreen toggle start");
mFullscreenChangeStartTime = TimeStamp::Now();
if (MOZ_UNLIKELY(mWindow->mFullScreen != mFullscreen)) {
// This could happen in theory if several fullscreen requests in
Expand Down Expand Up @@ -7109,7 +7109,7 @@ FullscreenTransitionTask::Run()
mDuration.mFadeOut, mTransitionData,
this);
} else if (stage == eEnd) {
profiler_add_marker("Fullscreen transition end");
PROFILER_ADD_MARKER("Fullscreen transition end");
}
return NS_OK;
}
Expand All @@ -7130,7 +7130,7 @@ FullscreenTransitionTask::Observer::Observe(nsISupports* aSubject,
// The paint notification arrives first. Cancel the timer.
mTask->mTimer->Cancel();
shouldContinue = true;
profiler_add_marker("Fullscreen toggle end");
PROFILER_ADD_MARKER("Fullscreen toggle end");
}
} else {
#ifdef DEBUG
Expand All @@ -7141,7 +7141,7 @@ FullscreenTransitionTask::Observer::Observe(nsISupports* aSubject,
"Should only trigger this with the timer the task created");
#endif
shouldContinue = true;
profiler_add_marker("Fullscreen toggle timeout");
PROFILER_ADD_MARKER("Fullscreen toggle timeout");
}
if (shouldContinue) {
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
Expand Down
7 changes: 3 additions & 4 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,8 @@ static void
FireForgetSkippable(uint32_t aSuspected, bool aRemoveChildless,
TimeStamp aDeadline)
{
AutoProfilerTracing
tracing("CC", aDeadline.IsNull() ? "ForgetSkippable" : "IdleForgetSkippable");
AUTO_PROFILER_TRACING("CC", aDeadline.IsNull() ? "ForgetSkippable"
: "IdleForgetSkippable");
PRTime startTime = PR_Now();
TimeStamp startTimeStamp = TimeStamp::Now();
FinishAnyIncrementalGC();
Expand Down Expand Up @@ -1489,8 +1489,7 @@ nsJSContext::RunCycleCollectorSlice(TimeStamp aDeadline)
return;
}

AutoProfilerTracing
tracing("CC", aDeadline.IsNull() ? "CCSlice" : "IdleCCSlice");
AUTO_PROFILER_TRACING("CC", aDeadline.IsNull() ? "CCSlice" : "IdleCCSlice");

AUTO_PROFILER_LABEL("nsJSContext::RunCycleCollectorSlice", CC);

Expand Down
2 changes: 2 additions & 0 deletions dom/base/nsJSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ EvaluationExceptionToNSResult(JSContext* aCx)
nsJSUtils::ExecutionContext::ExecutionContext(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
:
#ifdef MOZ_GECKO_PROFILER
mAutoProfilerLabel("nsJSUtils::ExecutionContext", /* dynamicStr */ nullptr,
__LINE__, js::ProfileEntry::Category::JS),
#endif
mCx(aCx)
, mCompartment(aCx, aGlobal)
, mRetValue(aCx)
Expand Down
2 changes: 2 additions & 0 deletions dom/base/nsJSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class nsJSUtils

// ExecutionContext is used to switch compartment.
class MOZ_STACK_CLASS ExecutionContext {
#ifdef MOZ_GECKO_PROFILER
// Register stack annotations for the Gecko profiler.
mozilla::AutoProfilerLabel mAutoProfilerLabel;
#endif

JSContext* mCx;

Expand Down
10 changes: 8 additions & 2 deletions dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "EventListenerService.h"
#include "GeckoProfiler.h"
#include "ProfilerMarkerPayload.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
Expand All @@ -53,6 +52,10 @@
#include "nsIFrame.h"
#include "nsDisplayList.h"

#ifdef MOZ_GECKO_PROFILER
#include "ProfilerMarkerPayload.h"
#endif

namespace mozilla {

using namespace dom;
Expand Down Expand Up @@ -1262,6 +1265,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
}

nsresult rv = NS_OK;
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
// Add a profiler label and a profiler marker for the actual
// dispatch of the event.
Expand All @@ -1285,7 +1289,9 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
MakeUnique<DOMEventMarkerPayload>(typeStr, phase,
aEvent->mTimeStamp,
startTime, endTime));
} else {
} else
#endif
{
rv = HandleEventSubType(listener, *aDOMEvent, aCurrentTarget);
}

Expand Down
9 changes: 7 additions & 2 deletions dom/indexedDB/ProfilerHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ LoggingHelper(bool aUseProfiler, const char* aFmt, ...)
static const mozilla::LogLevel logLevel = LogLevel::Warning;

if (MOZ_LOG_TEST(logModule, logLevel) ||
(aUseProfiler && profiler_is_active())) {
#ifdef MOZ_GECKO_PROFILER
(aUseProfiler && profiler_is_active())
#else
false
#endif
) {
nsAutoCString message;

{
Expand All @@ -306,7 +311,7 @@ LoggingHelper(bool aUseProfiler, const char* aFmt, ...)
MOZ_LOG(logModule, logLevel, ("%s", message.get()));

if (aUseProfiler) {
profiler_add_marker(message.get());
PROFILER_ADD_MARKER(message.get());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webaudio/blink/HRTFDatabaseLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void HRTFDatabaseLoader::MainThreadRelease()
// Asynchronously load the database in this thread.
static void databaseLoaderEntry(void* threadData)
{
AutoProfilerRegisterThread registerThread("HRTFDatabaseLdr");
AUTO_PROFILER_REGISTER_THREAD("HRTFDatabaseLdr");
NS_SetCurrentThreadName("HRTFDatabaseLdr");

HRTFDatabaseLoader* loader = reinterpret_cast<HRTFDatabaseLoader*>(threadData);
Expand Down
9 changes: 8 additions & 1 deletion dom/performance/Performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "GeckoProfiler.h"
#include "nsRFPService.h"
#include "ProfilerMarkerPayload.h"
#include "PerformanceEntry.h"
#include "PerformanceMainThread.h"
#include "PerformanceMark.h"
Expand All @@ -28,6 +27,10 @@
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"

#ifdef MOZ_GECKO_PROFILER
#include "ProfilerMarkerPayload.h"
#endif

#define PERFLOG(msg, ...) printf_stderr(msg, ##__VA_ARGS__)

namespace mozilla {
Expand Down Expand Up @@ -266,11 +269,13 @@ Performance::Mark(const nsAString& aName, ErrorResult& aRv)
new PerformanceMark(GetParentObject(), aName, Now());
InsertUserEntry(performanceMark);

#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
profiler_add_marker(
"UserTiming",
MakeUnique<UserTimingMarkerPayload>(aName, TimeStamp::Now()));
}
#endif
}

void
Expand Down Expand Up @@ -352,6 +357,7 @@ Performance::Measure(const nsAString& aName,
new PerformanceMeasure(GetParentObject(), aName, startTime, endTime);
InsertUserEntry(performanceMeasure);

#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
TimeStamp startTimeStamp = CreationTimeStamp() +
TimeDuration::FromMilliseconds(startTime);
Expand All @@ -361,6 +367,7 @@ Performance::Measure(const nsAString& aName,
"UserTiming",
MakeUnique<UserTimingMarkerPayload>(aName, startTimeStamp, endTimeStamp));
}
#endif
}

void
Expand Down
2 changes: 1 addition & 1 deletion dom/storage/StorageDBThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ StorageDBThread::SetDefaultPriority()
void
StorageDBThread::ThreadFunc(void* aArg)
{
AutoProfilerRegisterThread registerThread("localStorage DB");
AUTO_PROFILER_REGISTER_THREAD("localStorage DB");
NS_SetCurrentThreadName("localStorage DB");
mozilla::IOInterposer::RegisterCurrentThread();

Expand Down
2 changes: 1 addition & 1 deletion dom/vr/VRDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ VRDisplay::GetLayers(nsTArray<VRLayer>& result)
void
VRDisplay::SubmitFrame()
{
AutoProfilerTracing tracing("VR", "SubmitFrameAtVRDisplay");
AUTO_PROFILER_TRACING("VR", "SubmitFrameAtVRDisplay");

if (mPresentation) {
mPresentation->SubmitFrame();
Expand Down
Loading

0 comments on commit dd9e0a7

Please sign in to comment.