Commit badb83e8 authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

BackForwardCache: Add first-paint timer after bfcache restore to WebPerformance

This CL adds methods to WebPerformance to record the latest timing when
the page is restored from the back-forward cache and the latest timing
of first-paint event after restoring.

This CL is a preparation to record first-paint event for back-forward
cache at PageLoadMetricsObserver.

Bug: 1014174
Change-Id: Ie0bd0e1cbfc070867a75b2574f05ad0797934875
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210181
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771487}
parent e1dd4ebc
......@@ -68,6 +68,7 @@ class WebPerformance {
BLINK_EXPORT double InputForNavigationStart() const;
BLINK_EXPORT double NavigationStart() const;
BLINK_EXPORT base::TimeTicks NavigationStartAsMonotonicTime() const;
BLINK_EXPORT double LastBackForwardCacheRestoreNavigationStart() const;
BLINK_EXPORT double UnloadEventEnd() const;
BLINK_EXPORT double RedirectStart() const;
BLINK_EXPORT double RedirectEnd() const;
......@@ -88,6 +89,7 @@ class WebPerformance {
BLINK_EXPORT double LoadEventStart() const;
BLINK_EXPORT double LoadEventEnd() const;
BLINK_EXPORT double FirstPaint() const;
BLINK_EXPORT double FirstPaintAfterBackForwardCacheRestore() const;
BLINK_EXPORT double FirstImagePaint() const;
BLINK_EXPORT double FirstContentfulPaint() const;
BLINK_EXPORT base::TimeTicks FirstContentfulPaintAsMonotonicTime() const;
......
......@@ -69,6 +69,11 @@ base::TimeTicks WebPerformance::NavigationStartAsMonotonicTime() const {
return private_->timing()->NavigationStartAsMonotonicTime();
}
double WebPerformance::LastBackForwardCacheRestoreNavigationStart() const {
return MillisecondsToSeconds(
private_->timing()->LastBackForwardCacheRestoreNavigationStart());
}
double WebPerformance::InputForNavigationStart() const {
return MillisecondsToSeconds(private_->timing()->inputStart());
}
......@@ -154,6 +159,11 @@ double WebPerformance::FirstPaint() const {
return MillisecondsToSeconds(private_->timing()->FirstPaint());
}
double WebPerformance::FirstPaintAfterBackForwardCacheRestore() const {
return MillisecondsToSeconds(
private_->timing()->FirstPaintAfterBackForwardCacheRestore());
}
double WebPerformance::FirstImagePaint() const {
return MillisecondsToSeconds(private_->timing()->FirstImagePaint());
}
......
......@@ -140,6 +140,7 @@
#include "third_party/blink/renderer/core/paint/compositing/paint_layer_compositor.h"
#include "third_party/blink/renderer/core/paint/first_meaningful_paint_detector.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/paint/paint_timing.h"
#include "third_party/blink/renderer/core/paint/paint_timing_detector.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme.h"
......@@ -3372,6 +3373,17 @@ void WebViewImpl::RestorePageFromBackForwardCache(
if (!local_frame)
continue;
local_frame->RemoveBackForwardCacheEviction();
if (local_frame->View()) {
Document* document = local_frame->GetDocument();
if (document)
PaintTiming::From(*document).OnRestoredFromBackForwardCache();
DocumentLoader* loader = local_frame->Loader().GetDocumentLoader();
if (loader) {
loader->GetTiming().MarkLastBackForwardCacheRestoreNavigationStart(
navigation_start);
}
}
}
// Resume the page.
......
......@@ -138,6 +138,12 @@ void DocumentLoadTiming::SetNavigationStart(base::TimeTicks navigation_start) {
NotifyDocumentTimingChanged();
}
void DocumentLoadTiming::MarkLastBackForwardCacheRestoreNavigationStart(
base::TimeTicks navigation_start) {
last_bfcache_restore_navigation_start_ = navigation_start;
NotifyDocumentTimingChanged();
}
void DocumentLoadTiming::SetInputStart(base::TimeTicks input_start) {
input_start_ = input_start;
NotifyDocumentTimingChanged();
......
......@@ -53,6 +53,7 @@ class CORE_EXPORT DocumentLoadTiming final {
void MarkNavigationStart();
void SetNavigationStart(base::TimeTicks);
void MarkLastBackForwardCacheRestoreNavigationStart(base::TimeTicks);
void SetInputStart(base::TimeTicks);
......@@ -81,6 +82,9 @@ class CORE_EXPORT DocumentLoadTiming final {
base::TimeTicks InputStart() const { return input_start_; }
base::TimeTicks NavigationStart() const { return navigation_start_; }
base::TimeTicks LastBackForwardCacheRestoreNavigationStart() const {
return last_bfcache_restore_navigation_start_;
}
base::TimeTicks UnloadEventStart() const { return unload_event_start_; }
base::TimeTicks UnloadEventEnd() const { return unload_event_end_; }
base::TimeTicks RedirectStart() const { return redirect_start_; }
......@@ -115,6 +119,7 @@ class CORE_EXPORT DocumentLoadTiming final {
base::TimeDelta reference_wall_time_;
base::TimeTicks input_start_;
base::TimeTicks navigation_start_;
base::TimeTicks last_bfcache_restore_navigation_start_;
base::TimeTicks unload_event_start_;
base::TimeTicks unload_event_end_;
base::TimeTicks redirect_start_;
......
......@@ -11,6 +11,7 @@ namespace blink {
// SwapPromise swap times for.
enum class PaintEvent {
kFirstPaint,
kFirstPaintAfterBackForwardCacheRestore,
kFirstContentfulPaint,
kProvisionalFirstMeaningfulPaint,
kFirstImagePaint,
......
......@@ -55,7 +55,7 @@ PaintTiming& PaintTiming::From(Document& document) {
}
void PaintTiming::MarkFirstPaint() {
// Test that m_firstPaint is non-zero here, as well as in setFirstPaint, so
// Test that |first_paint_| is non-zero here, as well as in setFirstPaint, so
// we avoid invoking monotonicallyIncreasingTime() on every call to
// markFirstPaint().
if (!first_paint_.is_null())
......@@ -64,7 +64,7 @@ void PaintTiming::MarkFirstPaint() {
}
void PaintTiming::MarkFirstContentfulPaint() {
// Test that m_firstContentfulPaint is non-zero here, as well as in
// Test that |first_contentful_paint_| is non-zero here, as well as in
// setFirstContentfulPaint, so we avoid invoking
// monotonicallyIncreasingTime() on every call to
// markFirstContentfulPaint().
......@@ -204,6 +204,9 @@ void PaintTiming::ReportSwapTime(PaintEvent event,
case PaintEvent::kFirstPaint:
SetFirstPaintSwap(timestamp);
return;
case PaintEvent::kFirstPaintAfterBackForwardCacheRestore:
SetFirstPaintAfterBackForwardCacheRestoreSwap(timestamp);
return;
case PaintEvent::kFirstContentfulPaint:
SetFirstContentfulPaintSwap(timestamp);
return;
......@@ -261,6 +264,12 @@ void PaintTiming::SetFirstImagePaintSwap(base::TimeTicks stamp) {
NotifyPaintTimingChanged();
}
void PaintTiming::SetFirstPaintAfterBackForwardCacheRestoreSwap(
base::TimeTicks stamp) {
first_paint_after_back_forward_cache_restore_swap_ = stamp;
NotifyPaintTimingChanged();
}
void PaintTiming::ReportSwapResultHistogram(WebSwapResult result) {
DEFINE_STATIC_LOCAL(
EnumerationHistogram, did_swap_histogram,
......@@ -269,4 +278,9 @@ void PaintTiming::ReportSwapResultHistogram(WebSwapResult result) {
did_swap_histogram.Count(static_cast<uint32_t>(result));
}
void PaintTiming::OnRestoredFromBackForwardCache() {
first_paint_after_back_forward_cache_restore_swap_ = base::TimeTicks();
RegisterNotifySwapTime(PaintEvent::kFirstPaintAfterBackForwardCacheRestore);
}
} // namespace blink
......@@ -69,6 +69,10 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected<PaintTiming>,
// current document.
base::TimeTicks FirstPaint() const { return first_paint_swap_; }
base::TimeTicks FirstPaintAfterBackForwardCacheRestore() const {
return first_paint_after_back_forward_cache_restore_swap_;
}
// FirstContentfulPaint returns the first time that 'contentful' content was
// painted. For instance, the first time that text or image content was
// painted.
......@@ -105,6 +109,8 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected<PaintTiming>,
// The caller owns the |clock| which must outlive the PaintTiming.
void SetTickClockForTesting(const base::TickClock* clock);
void OnRestoredFromBackForwardCache();
void Trace(Visitor*) const override;
private:
......@@ -132,6 +138,8 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected<PaintTiming>,
void SetFirstContentfulPaintSwap(base::TimeTicks stamp);
void SetFirstImagePaintSwap(base::TimeTicks stamp);
void SetFirstPaintAfterBackForwardCacheRestoreSwap(base::TimeTicks stamp);
void RegisterNotifySwapTime(PaintEvent);
base::TimeTicks FirstPaintRendered() const { return first_paint_; }
......@@ -145,6 +153,7 @@ class CORE_EXPORT PaintTiming final : public GarbageCollected<PaintTiming>,
// confirm the deltas and discrepancies look reasonable.
base::TimeTicks first_paint_;
base::TimeTicks first_paint_swap_;
base::TimeTicks first_paint_after_back_forward_cache_restore_swap_;
base::TimeTicks first_image_paint_;
base::TimeTicks first_image_paint_swap_;
base::TimeTicks first_contentful_paint_;
......
......@@ -321,6 +321,15 @@ base::TimeTicks PerformanceTiming::NavigationStartAsMonotonicTime() const {
return timing->NavigationStart();
}
uint64_t PerformanceTiming::LastBackForwardCacheRestoreNavigationStart() const {
DocumentLoadTiming* timing = GetDocumentLoadTiming();
if (!timing)
return 0;
return MonotonicTimeToIntegerMilliseconds(
timing->LastBackForwardCacheRestoreNavigationStart());
}
uint64_t PerformanceTiming::FirstPaint() const {
const PaintTiming* timing = GetPaintTiming();
if (!timing)
......@@ -329,6 +338,15 @@ uint64_t PerformanceTiming::FirstPaint() const {
return MonotonicTimeToIntegerMilliseconds(timing->FirstPaint());
}
uint64_t PerformanceTiming::FirstPaintAfterBackForwardCacheRestore() const {
const PaintTiming* timing = GetPaintTiming();
if (!timing)
return 0;
return MonotonicTimeToIntegerMilliseconds(
timing->FirstPaintAfterBackForwardCacheRestore());
}
uint64_t PerformanceTiming::FirstImagePaint() const {
const PaintTiming* timing = GetPaintTiming();
if (!timing)
......
......@@ -92,8 +92,14 @@ class CORE_EXPORT PerformanceTiming final : public ScriptWrappable,
// fetchStart. Intended to be used for correlation with other events internal
// to blink. Not to be exposed to JavaScript.
base::TimeTicks NavigationStartAsMonotonicTime() const;
// The latest navigation start time after the page is restored from
// back-forward cache.
uint64_t LastBackForwardCacheRestoreNavigationStart() const;
// The time the first paint operation was performed.
uint64_t FirstPaint() const;
// The time the first paint operation was performed after the latest time when
// the page was restored from the back-forward cache.
uint64_t FirstPaintAfterBackForwardCacheRestore() const;
// The time the first paint operation for image was performed.
uint64_t FirstImagePaint() const;
// The time of the first 'contentful' paint. A contentful paint is a paint
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment