Bug 1444296 part 2 - Have a separate marker for styles to present stats. r=mstange
MozReview-Commit-ID: FXYnFXDvajw
new file mode 100644
--- /dev/null
+++ b/layout/base/AutoProfilerStyleMarker.h
@@ -0,0 +1,54 @@
+/* -*- 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/. */
+
+#ifndef mozilla_AutoProfilerStyleMarker_h
+#define mozilla_AutoProfilerStyleMarker_h
+
+#include "mozilla/Attributes.h"
+#include "mozilla/ServoTraversalStatistics.h"
+#include "mozilla/TimeStamp.h"
+#include "GeckoProfiler.h"
+#include "ProfilerMarkerPayload.h"
+
+namespace mozilla {
+
+class MOZ_RAII AutoProfilerStyleMarker
+{
+public:
+ explicit AutoProfilerStyleMarker(UniqueProfilerBacktrace aCause)
+ : mActive(profiler_is_active())
+ , mStartTime(TimeStamp::Now())
+ , mCause(Move(aCause))
+ {
+ if (!mActive) {
+ return;
+ }
+ MOZ_ASSERT(!ServoTraversalStatistics::sActive,
+ "Nested AutoProfilerStyleMarker");
+ ServoTraversalStatistics::sSingleton = ServoTraversalStatistics();
+ ServoTraversalStatistics::sActive = true;
+ }
+
+ ~AutoProfilerStyleMarker()
+ {
+ if (!mActive) {
+ return;
+ }
+ ServoTraversalStatistics::sActive = false;
+ profiler_add_marker("Styles", MakeUnique<StyleMarkerPayload>(
+ mStartTime, TimeStamp::Now(), Move(mCause),
+ ServoTraversalStatistics::sSingleton));
+ }
+
+private:
+ bool mActive;
+ TimeStamp mStartTime;
+ UniqueProfilerBacktrace mCause;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_AutoProfilerStyleMarker_h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -89,16 +89,19 @@
#include "nsLayoutUtils.h"
#include "nsViewportInfo.h"
#include "nsCSSRendering.h"
// for |#ifdef DEBUG| code
#include "prenv.h"
#include "nsDisplayList.h"
#include "nsRegion.h"
#include "nsAutoLayoutPhase.h"
+#ifdef MOZ_GECKO_PROFILER
+#include "AutoProfilerStyleMarker.h"
+#endif
#ifdef MOZ_REFLOW_PERF
#include "nsFontMetrics.h"
#endif
#include "PositionedEventTargeting.h"
#include "nsIReflowCallback.h"
#include "nsPIDOMWindow.h"
@@ -4183,19 +4186,17 @@ PresShell::DoFlushPendingNotifications(m
if (aFlush.mFlushAnimations && mPresContext->EffectCompositor()) {
mPresContext->EffectCompositor()->PostRestyleForThrottledAnimations();
}
// The FlushResampleRequests() above flushed style changes.
if (!mIsDestroying) {
nsAutoScriptBlocker scriptBlocker;
#ifdef MOZ_GECKO_PROFILER
- AutoProfilerTracing tracingStyleFlush("Paint", "Styles",
- Move(mStyleCause));
- mStyleCause = nullptr;
+ AutoProfilerStyleMarker tracingStyleFlush(Move(mStyleCause));
#endif
mPresContext->RestyleManager()->ProcessPendingRestyles();
}
}
// Process whatever XBL constructors those restyles queued up. This
// ensures that onload doesn't fire too early and that we won't do extra
@@ -4209,19 +4210,17 @@ PresShell::DoFlushPendingNotifications(m
// In particular, reflow depends on style being completely up to
// date. If it's not, then style context reparenting, which can
// happen during reflow, might suddenly pick up the new rules and
// we'll end up with frames whose style doesn't match the frame
// type.
if (!mIsDestroying) {
nsAutoScriptBlocker scriptBlocker;
#ifdef MOZ_GECKO_PROFILER
- AutoProfilerTracing tracingStyleFlush("Paint", "Styles",
- Move(mStyleCause));
- mStyleCause = nullptr;
+ AutoProfilerStyleMarker tracingStyleFlush(Move(mStyleCause));
#endif
mPresContext->RestyleManager()->ProcessPendingRestyles();
// Clear mNeedStyleFlush here agagin to make this flag work properly for
// optimization since the flag might have set in ProcessPendingRestyles().
mNeedStyleFlush = false;
}
--- a/tools/profiler/core/ProfilerMarkerPayload.cpp
+++ b/tools/profiler/core/ProfilerMarkerPayload.cpp
@@ -172,8 +172,22 @@ GCMinorMarkerPayload::StreamPayload(Spli
void
HangMarkerPayload::StreamPayload(SpliceableJSONWriter& aWriter,
const TimeStamp& aProcessStartTime,
UniqueStacks& aUniqueStacks)
{
StreamCommonProps("BHR-detected hang", aWriter, aProcessStartTime, aUniqueStacks);
}
+
+void
+StyleMarkerPayload::StreamPayload(SpliceableJSONWriter& aWriter,
+ const TimeStamp& aProcessStartTime,
+ UniqueStacks& aUniqueStacks)
+{
+ StreamCommonProps("Styles", aWriter, aProcessStartTime, aUniqueStacks);
+ aWriter.StringProperty("category", "Paint");
+ aWriter.IntProperty("elementsTraversed", mStats.mElementsTraversed);
+ aWriter.IntProperty("elementsStyled", mStats.mElementsStyled);
+ aWriter.IntProperty("elementsMatched", mStats.mElementsMatched);
+ aWriter.IntProperty("stylesShared", mStats.mStylesShared);
+ aWriter.IntProperty("stylesReused", mStats.mStylesReused);
+}
--- a/tools/profiler/public/ProfilerMarkerPayload.h
+++ b/tools/profiler/public/ProfilerMarkerPayload.h
@@ -13,16 +13,17 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtrExtensions.h"
#include "nsString.h"
#include "GeckoProfiler.h"
#include "js/Utility.h"
#include "gfxASurface.h"
+#include "mozilla/ServoTraversalStatistics.h"
namespace mozilla {
namespace layers {
class Layer;
} // namespace layers
} // namespace mozilla
class SpliceableJSONWriter;
@@ -264,9 +265,30 @@ public:
const mozilla::TimeStamp& aEndTime)
: ProfilerMarkerPayload(aStartTime, aEndTime)
{}
DECL_STREAM_PAYLOAD
private:
};
+class StyleMarkerPayload : public ProfilerMarkerPayload
+{
+public:
+ StyleMarkerPayload(const mozilla::TimeStamp& aStartTime,
+ const mozilla::TimeStamp& aEndTime,
+ UniqueProfilerBacktrace aCause,
+ const mozilla::ServoTraversalStatistics& aStats)
+ : ProfilerMarkerPayload(aStartTime, aEndTime)
+ , mStats(aStats)
+ {
+ if (aCause) {
+ SetStack(Move(aCause));
+ }
+ }
+
+ DECL_STREAM_PAYLOAD
+
+private:
+ mozilla::ServoTraversalStatistics mStats;
+};
+
#endif // ProfilerMarkerPayload_h