Bug 934710 - log text perf metrics at reflow end, load complete and presshell teardown. r=heycam

This commit is contained in:
John Daggett 2013-11-25 14:00:00 +09:00
Родитель 11931c9dfc
Коммит 5a92bd2828
4 изменённых файлов: 156 добавлений и 6 удалений

Просмотреть файл

@ -1025,6 +1025,7 @@ nsDocumentViewer::LoadComplete(nsresult aStatus)
// mPresShell could have been removed now, see bug 378682/421432
if (mPresShell) {
mPresShell->ScrollToAnchor();
mPresShell->LoadComplete();
}
}

Просмотреть файл

@ -417,6 +417,11 @@ public:
*/
virtual bool IsLayoutFlushObserver() = 0;
/**
* Called when document load completes.
*/
virtual NS_HIDDEN_(void) LoadComplete() = 0;
/**
* This calls through to the frame manager to get the root frame.
*/

Просмотреть файл

@ -878,12 +878,106 @@ PresShell::Init(nsIDocument* aDocument,
SetupFontInflation();
}
#ifdef PR_LOGGING
enum TextPerfLogType {
eLog_reflow,
eLog_loaddone,
eLog_totals
};
static void
LogTextPerfStats(gfxTextPerfMetrics* aTextPerf,
PresShell* aPresShell,
const gfxTextPerfMetrics::TextCounts& aCounts,
float aTime, TextPerfLogType aLogType, const char* aURL)
{
char prefix[256];
switch (aLogType) {
case eLog_reflow:
sprintf(prefix, "(textperf-reflow) %p time-ms: %7.0f", aPresShell, aTime);
break;
case eLog_loaddone:
sprintf(prefix, "(textperf-loaddone) %p time-ms: %7.0f", aPresShell, aTime);
break;
default:
MOZ_ASSERT(aLogType == eLog_totals, "unknown textperf log type");
sprintf(prefix, "(textperf-totals) %p", aPresShell);
}
PRLogModuleInfo* tpLog = gfxPlatform::GetLog(eGfxLog_textperf);
// ignore XUL contexts unless at debug level
PRLogModuleLevel logLevel = PR_LOG_WARNING;
if (aCounts.numContentTextRuns == 0) {
logLevel = PR_LOG_DEBUG;
}
double hitRatio = 0.0;
uint32_t lookups = aCounts.wordCacheHit + aCounts.wordCacheMiss;
if (lookups) {
hitRatio = double(aCounts.wordCacheHit) / double(lookups);
}
if (aLogType == eLog_loaddone) {
PR_LOG(tpLog, logLevel,
("%s reflow: %d chars: %d "
"[%s] "
"content-textruns: %d chrome-textruns: %d "
"max-textrun-len: %d "
"word-cache-lookups: %d word-cache-hit-ratio: %4.3f "
"word-cache-space: %d word-cache-long: %d "
"pref-fallbacks: %d system-fallbacks: %d "
"textruns-const: %d textruns-destr: %d "
"cumulative-textruns-destr: %d\n",
prefix, aTextPerf->reflowCount, aCounts.numChars,
(aURL ? aURL : ""),
aCounts.numContentTextRuns, aCounts.numChromeTextRuns,
aCounts.maxTextRunLen,
lookups, hitRatio,
aCounts.wordCacheSpaceRules, aCounts.wordCacheLong,
aCounts.fallbackPrefs, aCounts.fallbackSystem,
aCounts.textrunConst, aCounts.textrunDestr,
aTextPerf->cumulative.textrunDestr));
} else {
PR_LOG(tpLog, logLevel,
("%s reflow: %d chars: %d "
"content-textruns: %d chrome-textruns: %d "
"max-textrun-len: %d "
"word-cache-lookups: %d word-cache-hit-ratio: %4.3f "
"word-cache-space: %d word-cache-long: %d "
"pref-fallbacks: %d system-fallbacks: %d "
"textruns-const: %d textruns-destr: %d "
"cumulative-textruns-destr: %d\n",
prefix, aTextPerf->reflowCount, aCounts.numChars,
aCounts.numContentTextRuns, aCounts.numChromeTextRuns,
aCounts.maxTextRunLen,
lookups, hitRatio,
aCounts.wordCacheSpaceRules, aCounts.wordCacheLong,
aCounts.fallbackPrefs, aCounts.fallbackSystem,
aCounts.textrunConst, aCounts.textrunDestr,
aTextPerf->cumulative.textrunDestr));
}
}
#endif
void
PresShell::Destroy()
{
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
"destroy called on presshell while scripts not blocked");
// dump out cumulative text perf metrics
#ifdef PR_LOGGING
gfxTextPerfMetrics* tp;
if (mPresContext && (tp = mPresContext->GetTextPerfMetrics())) {
tp->Accumulate();
if (tp->cumulative.numChars > 0) {
LogTextPerfStats(tp, this, tp->cumulative, 0.0, eLog_totals, nullptr);
}
}
#endif
#ifdef MOZ_REFLOW_PERF
DumpReflows();
if (mReflowCountMgr) {
@ -2399,15 +2493,24 @@ PresShell::BeginLoad(nsIDocument *aDocument)
mDocumentLoading = true;
#ifdef PR_LOGGING
if (gLog && PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
gfxTextPerfMetrics *tp = nullptr;
if (mPresContext) {
tp = mPresContext->GetTextPerfMetrics();
}
bool shouldLog = gLog && PR_LOG_TEST(gLog, PR_LOG_DEBUG);
if (shouldLog || tp) {
mLoadBegin = TimeStamp::Now();
}
if (shouldLog) {
nsIURI* uri = mDocument->GetDocumentURI();
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
PR_LOG(gLog, PR_LOG_DEBUG,
("(presshell) %p begin load [%s]\n",
("(presshell) %p load begin [%s]\n",
this, spec.get()));
}
#endif
@ -2421,19 +2524,38 @@ PresShell::EndLoad(nsIDocument *aDocument)
RestoreRootScrollPosition();
mDocumentLoading = false;
}
void
PresShell::LoadComplete()
{
#ifdef PR_LOGGING
gfxTextPerfMetrics *tp = nullptr;
if (mPresContext) {
tp = mPresContext->GetTextPerfMetrics();
}
// log load
if (gLog && PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
bool shouldLog = gLog && PR_LOG_TEST(gLog, PR_LOG_DEBUG);
if (shouldLog || tp) {
TimeDuration loadTime = TimeStamp::Now() - mLoadBegin;
nsIURI* uri = mDocument->GetDocumentURI();
nsAutoCString spec;
if (uri) {
uri->GetSpec(spec);
}
PR_LOG(gLog, PR_LOG_DEBUG,
("(presshell) %p end load time-ms: %9.2f [%s]\n",
this, loadTime.ToMilliseconds(), spec.get()));
if (shouldLog) {
PR_LOG(gLog, PR_LOG_DEBUG,
("(presshell) %p load done time-ms: %9.2f [%s]\n",
this, loadTime.ToMilliseconds(), spec.get()));
}
if (tp) {
tp->Accumulate();
if (tp->cumulative.numChars > 0) {
LogTextPerfStats(tp, this, tp->cumulative, loadTime.ToMilliseconds(),
eLog_loaddone, spec.get());
}
}
}
#endif
}
@ -7877,6 +7999,14 @@ PresShell::DoReflow(nsIFrame* target, bool aInterruptible)
return true;
}
gfxTextPerfMetrics* tp = mPresContext->GetTextPerfMetrics();
TimeStamp timeStart;
if (tp) {
tp->Accumulate();
tp->reflowCount++;
timeStart = TimeStamp::Now();
}
target->SchedulePaint();
nsIFrame *parent = nsLayoutUtils::GetCrossDocParentFrame(target);
while (parent) {
@ -8032,6 +8162,18 @@ PresShell::DoReflow(nsIFrame* target, bool aInterruptible)
MaybeScheduleReflow();
}
#ifdef PR_LOGGING
// dump text perf metrics for reflows with significant text processing
if (tp) {
if (tp->current.numChars > 100) {
TimeDuration reflowTime = TimeStamp::Now() - timeStart;
LogTextPerfStats(tp, this, tp->current,
reflowTime.ToMilliseconds(), eLog_reflow, nullptr);
}
tp->Accumulate();
}
#endif
return !interrupted;
}

Просмотреть файл

@ -318,6 +318,8 @@ public:
IsLayoutFlushObserver(this);
}
virtual void LoadComplete() MOZ_OVERRIDE;
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
nsArenaMemoryStats *aArenaObjectsSize,
size_t *aPresShellSize,