Bug 1050498 - Record compositing operations, r=jsantell,smaug,tromey

This commit is contained in:
Victor Porof 2015-08-25 08:51:58 +03:00
parent 432213854d
commit 334b8c8024
25 changed files with 196 additions and 58 deletions

View File

@ -73,6 +73,11 @@ const TIMELINE_BLUEPRINT = {
colorName: "graphs-green",
label: L10N.getStr("marker.label.paint"),
},
"Composite": {
group: 0,
colorName: "graphs-green",
label: L10N.getStr("marker.label.composite"),
},
/* Group 1 - JS */
"DOMEvent": {

View File

@ -17,6 +17,7 @@
marker.label.styles=Recalculate Style
marker.label.reflow=Layout
marker.label.paint=Paint
marker.label.composite=Composite Layers
marker.label.javascript=Function Call
marker.label.parseHTML=Parse HTML
marker.label.parseXML=Parse XML

View File

@ -277,10 +277,12 @@ private:
// is stored on docshells directly.
friend void mozilla::TimelineConsumers::AddConsumer(nsDocShell* aDocShell);
friend void mozilla::TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell);
friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
nsDocShell* aDocShell, UniquePtr<TimelineMarker>&& aMarker);
friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
nsDocShell* aDocShell, const char* aName, TracingMetadata aMetaData);
friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
nsDocShell* aDocShell, const char* aName, const TimeStamp& aTime, TracingMetadata aMetaData);
friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
nsDocShell* aDocShell, UniquePtr<TimelineMarker>&& aMarker);
public:
// Tell the favicon service that aNewURI has the same favicon as aOldURI.

View File

@ -6,7 +6,7 @@
#include "mozilla/AutoGlobalTimelineMarker.h"
#include "mozilla/TimelineConsumers.h"
#include "TimelineConsumers.h"
#include "MainThreadUtils.h"
namespace mozilla {

View File

@ -6,7 +6,7 @@
#include "mozilla/AutoTimelineMarker.h"
#include "mozilla/TimelineConsumers.h"
#include "TimelineConsumers.h"
#include "MainThreadUtils.h"
#include "nsDocShell.h"

View File

@ -15,13 +15,6 @@ ObservedDocShell::ObservedDocShell(nsDocShell* aDocShell)
: mDocShell(aDocShell)
{}
void
ObservedDocShell::AddMarker(const char* aName, TracingMetadata aMetaData)
{
TimelineMarker* marker = new TimelineMarker(mDocShell, aName, aMetaData);
mTimelineMarkers.AppendElement(marker);
}
void
ObservedDocShell::AddMarker(UniquePtr<TimelineMarker>&& aMarker)
{

View File

@ -7,7 +7,6 @@
#ifndef ObservedDocShell_h_
#define ObservedDocShell_h_
#include "GeckoProfiler.h"
#include "nsTArray.h"
#include "mozilla/nsRefPtr.h"
@ -33,7 +32,6 @@ public:
explicit ObservedDocShell(nsDocShell* aDocShell);
nsDocShell* operator*() const { return mDocShell.get(); }
void AddMarker(const char* aName, TracingMetadata aMetaData);
void AddMarker(UniquePtr<TimelineMarker>&& aMarker);
void ClearMarkers();
void PopMarkers(JSContext* aCx, nsTArray<dom::ProfileTimelineMarker>& aStore);

View File

@ -65,6 +65,27 @@ TimelineConsumers::GetKnownDocShells(Vector<nsRefPtr<nsDocShell>>& aStore)
return true;
}
void
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName,
TracingMetadata aMetaData)
{
if (aDocShell->IsObserved()) {
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aDocShell, aName, aMetaData)));
}
}
void
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName,
const TimeStamp& aTime,
TracingMetadata aMetaData)
{
if (aDocShell->IsObserved()) {
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aDocShell, aName, aTime, aMetaData)));
}
}
void
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
UniquePtr<TimelineMarker>&& aMarker)
@ -75,17 +96,33 @@ TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
}
void
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName, TracingMetadata aMetaData)
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
const char* aName,
TracingMetadata aMetaData)
{
if (aDocShell->IsObserved()) {
aDocShell->mObserved->AddMarker(aName, aMetaData);
}
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), aName, aMetaData);
}
void
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
const char* aName,
const TimeStamp& aTime,
TracingMetadata aMetaData)
{
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), aName, aTime, aMetaData);
}
void
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
UniquePtr<TimelineMarker>&& aMarker)
{
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), Move(aMarker));
}
void
TimelineConsumers::AddMarkerForDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocShells,
const char* aName, TracingMetadata aMetaData)
const char* aName,
TracingMetadata aMetaData)
{
for (Vector<nsRefPtr<nsDocShell>>::Range range = aDocShells.all();
!range.empty();
@ -95,7 +132,8 @@ TimelineConsumers::AddMarkerForDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocS
}
void
TimelineConsumers::AddMarkerForAllObservedDocShells(const char* aName, TracingMetadata aMetaData)
TimelineConsumers::AddMarkerForAllObservedDocShells(const char* aName,
TracingMetadata aMetaData)
{
Vector<nsRefPtr<nsDocShell>> docShells;
if (!GetKnownDocShells(docShells)) {

View File

@ -10,11 +10,14 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/LinkedList.h"
#include "mozilla/Vector.h"
#include "timeline/ObservedDocShell.h"
#include "GeckoProfiler.h"
class nsDocShell;
class nsIDocShell;
class TimelineMarker;
namespace mozilla {
class ObservedDocShell;
class TimelineConsumers
{
@ -30,16 +33,49 @@ public:
static bool IsEmpty();
static bool GetKnownDocShells(Vector<nsRefPtr<nsDocShell>>& aStore);
// Methods for adding markers to appropriate docshells. These will only add
// markers if the docshell is currently being observed by a timeline.
// Methods for adding markers relevant for particular docshells, or generic
// (meaning that they either can't be tied to a particular docshell, or one
// wasn't accessible in the part of the codebase where they're instantiated).
// These will only add markers if at least one docshell is currently being
// observed by a timeline. Markers tied to a particular docshell won't be
// created unless that docshell is specifically being currently observed.
// See nsIDocShell::recordProfileTimelineMarkers
// These methods create a custom marker from a name and some metadata,
// relevant for a specific docshell.
static void AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName,
TracingMetadata aMetaData);
static void AddMarkerForDocShell(nsIDocShell* aDocShell,
const char* aName,
TracingMetadata aMetaData);
static void AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName,
const TimeStamp& aTime,
TracingMetadata aMetaData);
static void AddMarkerForDocShell(nsIDocShell* aDocShell,
const char* aName,
const TimeStamp& aTime,
TracingMetadata aMetaData);
// These methods register and receive ownership of an already created marker,
// relevant for a specific docshell.
static void AddMarkerForDocShell(nsDocShell* aDocShell,
UniquePtr<TimelineMarker>&& aMarker);
static void AddMarkerForDocShell(nsDocShell* aDocShell,
const char* aName, TracingMetadata aMetaData);
static void AddMarkerForDocShell(nsIDocShell* aDocShell,
UniquePtr<TimelineMarker>&& aMarker);
// This method creates custom markers, relevant for a list of docshells.
static void AddMarkerForDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocShells,
const char* aName, TracingMetadata aMetaData);
static void AddMarkerForAllObservedDocShells(const char* aName, TracingMetadata aMetaData);
const char* aName,
TracingMetadata aMetaData);
// This method creates custom markers, none of which have to be tied to a
// particular docshell.
static void AddMarkerForAllObservedDocShells(const char* aName,
TracingMetadata aMetaData);
};
} // namespace mozilla

View File

@ -20,6 +20,15 @@ TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
}
}
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData)
: TimelineMarker(aDocShell, aName, aMetaData)
{
bool isInconsistent = false;
mTime = (aTime - mozilla::TimeStamp::ProcessCreation(isInconsistent)).ToMilliseconds();
}
TimelineMarker::TimelineMarker(nsDocShell* aDocShell, const char* aName,
TracingMetadata aMetaData,
const nsAString& aCause,

View File

@ -26,6 +26,10 @@ public:
TimelineMarker(nsDocShell* aDocShell, const char* aName,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
const mozilla::TimeStamp& aTime,
TracingMetadata aMetaData);
TimelineMarker(nsDocShell* aDocShell, const char* aName,
TracingMetadata aMetaData,
const nsAString& aCause,

View File

@ -7,7 +7,9 @@
EXPORTS.mozilla += [
'AutoGlobalTimelineMarker.h',
'AutoTimelineMarker.h',
'ObservedDocShell.h',
'TimelineConsumers.h',
'TimelineMarker.h',
]
UNIFIED_SOURCES += [

View File

@ -2862,7 +2862,9 @@ TabChild::GetFrom(uint64_t aLayersId)
}
void
TabChild::DidComposite(uint64_t aTransactionId)
TabChild::DidComposite(uint64_t aTransactionId,
const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd)
{
MOZ_ASSERT(mPuppetWidget);
MOZ_ASSERT(mPuppetWidget->GetLayerManager());
@ -2871,7 +2873,8 @@ TabChild::DidComposite(uint64_t aTransactionId)
ClientLayerManager *manager =
static_cast<ClientLayerManager*>(mPuppetWidget->GetLayerManager());
manager->DidComposite(aTransactionId);
manager->DidComposite(aTransactionId, aCompositeStart, aCompositeEnd);
}
void

View File

@ -461,7 +461,10 @@ public:
static TabChild* GetFrom(nsIPresShell* aPresShell);
static TabChild* GetFrom(uint64_t aLayersId);
void DidComposite(uint64_t aTransactionId);
void DidComposite(uint64_t aTransactionId,
const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd);
void ClearCachedResources();
static inline TabChild*

View File

@ -110,7 +110,8 @@ ClientLayerManager::ClientLayerManager(nsIWidget* aWidget)
ClientLayerManager::~ClientLayerManager()
{
if (mTransactionIdAllocator) {
DidComposite(mLatestTransactionId);
TimeStamp now = TimeStamp::Now();
DidComposite(mLatestTransactionId, now, now);
}
mMemoryPressureObserver->Destroy();
ClearCachedResources();
@ -384,16 +385,18 @@ ClientLayerManager::Composite()
}
void
ClientLayerManager::DidComposite(uint64_t aTransactionId)
ClientLayerManager::DidComposite(uint64_t aTransactionId,
const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd)
{
MOZ_ASSERT(mWidget);
nsIWidgetListener *listener = mWidget->GetWidgetListener();
if (listener) {
listener->DidCompositeWindow();
listener->DidCompositeWindow(aCompositeStart, aCompositeEnd);
}
listener = mWidget->GetAttachedWidgetListener();
if (listener) {
listener->DidCompositeWindow();
listener->DidCompositeWindow(aCompositeStart, aCompositeEnd);
}
mTransactionIdAllocator->NotifyTransactionCompleted(aTransactionId);
}

View File

@ -203,7 +203,9 @@ public:
virtual bool RequestOverfill(mozilla::dom::OverfillCallback* aCallback) override;
virtual void RunOverfillCallback(const uint32_t aOverfill) override;
void DidComposite(uint64_t aTransactionId);
void DidComposite(uint64_t aTransactionId,
const mozilla::TimeStamp& aCompositeStart,
const mozilla::TimeStamp& aCompositeEnd);
virtual bool SupportsMixBlendModes(EnumSet<gfx::CompositionOp>& aMixBlendModes) override
{

View File

@ -345,15 +345,17 @@ CompositorChild::RecvUpdatePluginVisibility(const uintptr_t& aOwnerWidget,
}
bool
CompositorChild::RecvDidComposite(const uint64_t& aId, const uint64_t& aTransactionId)
CompositorChild::RecvDidComposite(const uint64_t& aId, const uint64_t& aTransactionId,
const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd)
{
if (mLayerManager) {
MOZ_ASSERT(aId == 0);
mLayerManager->DidComposite(aTransactionId);
mLayerManager->DidComposite(aTransactionId, aCompositeStart, aCompositeEnd);
} else if (aId != 0) {
dom::TabChild *child = dom::TabChild::GetFrom(aId);
if (child) {
child->DidComposite(aTransactionId);
child->DidComposite(aTransactionId, aCompositeStart, aCompositeEnd);
}
}
return true;

View File

@ -74,7 +74,9 @@ public:
RecvClearCachedResources(const uint64_t& id) override;
virtual bool
RecvDidComposite(const uint64_t& aId, const uint64_t& aTransactionId) override;
RecvDidComposite(const uint64_t& aId, const uint64_t& aTransactionId,
const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd) override;
virtual bool
RecvInvalidateAll() override;

View File

@ -831,7 +831,9 @@ CompositorParent::PauseComposition()
mPaused = true;
mCompositor->Pause();
DidComposite();
TimeStamp now = TimeStamp::Now();
DidComposite(now, now);
}
// if anyone's waiting to make sure that composition really got paused, tell them
@ -1034,7 +1036,8 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget, const gfx::IntRect* aRe
#endif
if (!CanComposite()) {
DidComposite();
TimeStamp end = TimeStamp::Now();
DidComposite(start, end);
return;
}
@ -1077,7 +1080,8 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget, const gfx::IntRect* aRe
mLayerManager->EndTransaction(time);
if (!aTarget) {
DidComposite();
TimeStamp end = TimeStamp::Now();
DidComposite(start, end);
}
// We're not really taking advantage of the stored composite-again-time here.
@ -1193,7 +1197,8 @@ CompositorParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
if (aScheduleComposite) {
ScheduleComposition();
if (mPaused) {
DidComposite();
TimeStamp now = TimeStamp::Now();
DidComposite(now, now);
}
}
mLayerManager->NotifyShadowTreeTransaction();
@ -1226,7 +1231,8 @@ CompositorParent::SetTestSampleTime(LayerTransactionParent* aLayerTree,
if (!requestNextFrame) {
CancelCurrentCompositeTask();
// Pretend we composited in case someone is wating for this event.
DidComposite();
TimeStamp now = TimeStamp::Now();
DidComposite(now, now);
}
}
@ -1258,7 +1264,8 @@ CompositorParent::ApplyAsyncProperties(LayerTransactionParent* aLayerTree)
if (!requestNextFrame) {
CancelCurrentCompositeTask();
// Pretend we composited in case someone is waiting for this event.
DidComposite();
TimeStamp now = TimeStamp::Now();
DidComposite(now, now);
}
}
}
@ -1717,7 +1724,9 @@ public:
virtual AsyncCompositionManager* GetCompositionManager(LayerTransactionParent* aParent) override;
void DidComposite(uint64_t aId);
void DidComposite(uint64_t aId,
TimeStamp& aCompositeStart,
TimeStamp& aCompositeEnd);
private:
// Private destructor, to discourage deletion outside of Release():
@ -1738,10 +1747,11 @@ private:
};
void
CompositorParent::DidComposite()
CompositorParent::DidComposite(TimeStamp& aCompositeStart,
TimeStamp& aCompositeEnd)
{
if (mPendingTransaction) {
unused << SendDidComposite(0, mPendingTransaction);
unused << SendDidComposite(0, mPendingTransaction, aCompositeStart, aCompositeEnd);
mPendingTransaction = 0;
}
if (mLayerManager) {
@ -1757,7 +1767,8 @@ CompositorParent::DidComposite()
it != sIndirectLayerTrees.end(); it++) {
LayerTreeState* lts = &it->second;
if (lts->mParent == this && lts->mCrossProcessParent) {
static_cast<CrossProcessCompositorParent*>(lts->mCrossProcessParent)->DidComposite(it->first);
static_cast<CrossProcessCompositorParent*>(lts->mCrossProcessParent)->DidComposite(
it->first, aCompositeStart, aCompositeEnd);
}
}
}
@ -2041,12 +2052,14 @@ UpdatePluginWindowState(uint64_t aId)
#endif // #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
void
CrossProcessCompositorParent::DidComposite(uint64_t aId)
CrossProcessCompositorParent::DidComposite(uint64_t aId,
TimeStamp& aCompositeStart,
TimeStamp& aCompositeEnd)
{
sIndirectLayerTreesLock->AssertCurrentThreadOwns();
LayerTransactionParent *layerTree = sIndirectLayerTrees[aId].mLayerTree;
if (layerTree && layerTree->GetPendingTransactionId()) {
unused << SendDidComposite(aId, layerTree->GetPendingTransactionId());
unused << SendDidComposite(aId, layerTree->GetPendingTransactionId(), aCompositeStart, aCompositeEnd);
layerTree->SetPendingTransactionId(0);
}
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)

View File

@ -439,7 +439,7 @@ protected:
*/
bool CanComposite();
void DidComposite();
void DidComposite(TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd);
nsRefPtr<LayerManagerComposite> mLayerManager;
nsRefPtr<Compositor> mCompositor;

View File

@ -45,7 +45,8 @@ child:
// the root layer tree).
// transactionId is the id of the transaction before this composite, or 0
// if there was no transaction since the last composite.
async DidComposite(uint64_t id, uint64_t transactionId);
async DidComposite(uint64_t id, uint64_t transactionId,
TimeStamp compositeStart, TimeStamp compositeEnd);
// The parent sends the child the requested fill ratio numbers.
async Overfill(uint32_t aOverfill);

View File

@ -18,6 +18,7 @@
#include "nsXULPopupManager.h"
#include "nsIWidgetListener.h"
#include "nsContentUtils.h" // for nsAutoScriptBlocker
#include "mozilla/TimelineConsumers.h"
using namespace mozilla;
@ -1071,12 +1072,28 @@ nsView::DidPaintWindow()
}
void
nsView::DidCompositeWindow()
nsView::DidCompositeWindow(const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd)
{
nsIPresShell* presShell = mViewManager->GetPresShell();
if (presShell) {
nsAutoScriptBlocker scriptBlocker;
presShell->GetPresContext()->GetDisplayRootPresContext()->GetRootPresContext()->NotifyDidPaintForSubtree(nsIPresShell::PAINT_COMPOSITE);
nsPresContext* context = presShell->GetPresContext();
context->GetDisplayRootPresContext()->GetRootPresContext()->NotifyDidPaintForSubtree(nsIPresShell::PAINT_COMPOSITE);
// If the two timestamps are identical, this was likely a fake composite
// event which wouldn't be terribly useful to display.
if (aCompositeStart == aCompositeEnd) {
return;
}
nsIDocShell* docShell = context->GetDocShell();
TimelineConsumers::AddMarkerForDocShell(docShell,
"Composite", aCompositeStart, TRACING_INTERVAL_START);
TimelineConsumers::AddMarkerForDocShell(docShell,
"Composite", aCompositeEnd, TRACING_INTERVAL_END);
}
}

View File

@ -381,7 +381,8 @@ public:
virtual void WillPaintWindow(nsIWidget* aWidget) override;
virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) override;
virtual void DidPaintWindow() override;
virtual void DidCompositeWindow() override;
virtual void DidCompositeWindow(const mozilla::TimeStamp& aCompositeStart,
const mozilla::TimeStamp& aCompositeEnd) override;
virtual void RequestRepaint() override;
virtual nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
bool aUseAttachedEvents) override;

View File

@ -107,7 +107,8 @@ nsIWidgetListener::DidPaintWindow()
}
void
nsIWidgetListener::DidCompositeWindow()
nsIWidgetListener::DidCompositeWindow(const TimeStamp& aCompositeStart,
const TimeStamp& aCompositeEnd)
{
}

View File

@ -8,6 +8,7 @@
#include <stdint.h>
#include "mozilla/EventForwards.h"
#include "mozilla/TimeStamp.h"
class nsView;
class nsIntRegion;
@ -135,7 +136,8 @@ public:
*/
virtual void DidPaintWindow();
virtual void DidCompositeWindow();
virtual void DidCompositeWindow(const mozilla::TimeStamp& aCompositeStart,
const mozilla::TimeStamp& aCompositeEnd);
/**
* Request that layout schedules a repaint on the next refresh driver tick.