From c56f9b604bcf08b36e85a9d2c4e1c3d53605a5f8 Mon Sep 17 00:00:00 2001 From: chiajung hung Date: Thu, 19 Mar 2015 02:19:00 +0100 Subject: [PATCH] Bug 1129249 - Add a "restyle" feature to profiler and split the style label in Cleopatra based on the restyleSource, r=dholbert,mstange --HG-- extra : rebase_source : 0da0203824cfbf2265b42229b298274156633ddd --- layout/base/RestyleTracker.cpp | 11 +++++++++++ layout/base/RestyleTracker.h | 10 ++++++++-- tools/profiler/GeckoProfiler.h | 25 +++++++++++++++++++++++++ tools/profiler/platform.cpp | 7 +++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/layout/base/RestyleTracker.cpp b/layout/base/RestyleTracker.cpp index 99425bf50dbd..294c7144cbcb 100644 --- a/layout/base/RestyleTracker.cpp +++ b/layout/base/RestyleTracker.cpp @@ -83,6 +83,7 @@ CollectLaterSiblings(nsISupports* aElement, struct RestyleEnumerateData : RestyleTracker::Hints { nsRefPtr mElement; + UniquePtr mBacktrace; }; struct RestyleCollector { @@ -140,6 +141,7 @@ CollectRestyles(nsISupports* aElement, currentRestyle->mElement = element; currentRestyle->mRestyleHint = aData->mRestyleHint; currentRestyle->mChangeHint = aData->mChangeHint; + currentRestyle->mBacktrace = Move(aData->mBacktrace); #ifdef RESTYLE_LOGGING collector->count++; @@ -305,6 +307,10 @@ RestyleTracker::DoProcessRestyles() continue; } + Maybe profilerRAII; + if (profiler_feature_active("restyle")) { + profilerRAII.emplace("Paint", "Styles", Move(data->mBacktrace)); + } ProcessOneRestyle(element, data->mRestyleHint, data->mChangeHint); AddRestyleRootsIfAwaitingRestyle(data->mDescendants); } @@ -340,6 +346,11 @@ RestyleTracker::DoProcessRestyles() FrameTagToString(currentRestyle->mElement).get(), index++, collector.count); LOG_RESTYLE_INDENT(); + + Maybe profilerRAII; + if (profiler_feature_active("restyle")) { + profilerRAII.emplace("Paint", "Styles", Move(currentRestyle->mBacktrace)); + } ProcessOneRestyle(currentRestyle->mElement, currentRestyle->mRestyleHint, currentRestyle->mChangeHint); diff --git a/layout/base/RestyleTracker.h b/layout/base/RestyleTracker.h index a58ee1db4f60..f295c2414fd0 100644 --- a/layout/base/RestyleTracker.h +++ b/layout/base/RestyleTracker.h @@ -16,6 +16,8 @@ #include "nsContainerFrame.h" #include "mozilla/SplayTree.h" #include "mozilla/RestyleLogging.h" +#include "ProfilerBacktrace.h" +#include "GeckoProfiler.h" namespace mozilla { @@ -291,6 +293,7 @@ public: // that we called AddPendingRestyle for and found the element this is // the RestyleData for as its nearest restyle root. nsTArray> mDescendants; + UniquePtr mBacktrace; }; /** @@ -388,8 +391,11 @@ RestyleTracker::AddPendingRestyleToTable(Element* aElement, } if (!existingData) { - mPendingRestyles.Put(aElement, - new RestyleData(aRestyleHint, aMinChangeHint)); + RestyleData* rd = new RestyleData(aRestyleHint, aMinChangeHint); + if (profiler_feature_active("restyle")) { + rd->mBacktrace.reset(profiler_get_backtrace()); + } + mPendingRestyles.Put(aElement, rd); return false; } diff --git a/tools/profiler/GeckoProfiler.h b/tools/profiler/GeckoProfiler.h index 6c6c6fcf57de..e2e6e1e8ea41 100644 --- a/tools/profiler/GeckoProfiler.h +++ b/tools/profiler/GeckoProfiler.h @@ -50,6 +50,7 @@ #define SAMPLER_H #include "js/TypeDecls.h" +#include "mozilla/UniquePtr.h" namespace mozilla { class TimeStamp; @@ -230,4 +231,28 @@ public: } }; +class ProfilerBacktrace; + +class MOZ_STACK_CLASS GeckoProfilerTracingRAII { +public: + GeckoProfilerTracingRAII(const char* aCategory, const char* aInfo, + mozilla::UniquePtr aBacktrace + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mCategory(aCategory) + , mInfo(aInfo) + { + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + profiler_tracing(mCategory, mInfo, aBacktrace.release(), TRACING_INTERVAL_START); + } + + ~GeckoProfilerTracingRAII() { + profiler_tracing(mCategory, mInfo, TRACING_INTERVAL_END); + } + +protected: + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER + const char* mCategory; + const char* mInfo; +}; + #endif // ifndef SAMPLER_H diff --git a/tools/profiler/platform.cpp b/tools/profiler/platform.cpp index eb17bd5b93fe..8e9a38025443 100644 --- a/tools/profiler/platform.cpp +++ b/tools/profiler/platform.cpp @@ -48,6 +48,7 @@ static bool sIsProfiling = false; // is raced on static bool sIsGPUProfiling = false; // is raced on static bool sIsLayersDump = false; // is raced on static bool sIsDisplayListDump = false; // is raced on +static bool sIsRestyleProfiling = false; // is raced on // env variables to control the profiler const char* PROFILER_MODE = "MOZ_PROFILER_MODE"; @@ -763,6 +764,7 @@ void mozilla_sampler_start(int aProfileEntries, double aInterval, sIsGPUProfiling = t->ProfileGPU(); sIsLayersDump = t->LayersDump(); sIsDisplayListDump = t->DisplayListDump(); + sIsRestyleProfiling = t->ProfileRestyle(); if (Sampler::CanNotifyObservers()) { nsCOMPtr os = mozilla::services::GetObserverService(); @@ -835,6 +837,7 @@ void mozilla_sampler_stop() sIsGPUProfiling = false; sIsLayersDump = false; sIsDisplayListDump = false; + sIsRestyleProfiling = false; if (Sampler::CanNotifyObservers()) { nsCOMPtr os = mozilla::services::GetObserverService(); @@ -883,6 +886,10 @@ bool mozilla_sampler_feature_active(const char* aName) return sIsDisplayListDump; } + if (strcmp(aName, "restyle") == 0) { + return sIsRestyleProfiling; + } + return false; }