Commit 71c0f5b5 authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

Reland: Add UKM Document.OutliveTimeAfterShutdown

This is basically same as https://chromium-review.googlesource.com/c/chromium/src/+/647050.
This CL tries to reland the change after rebasing.

This CL adds a new UKM Document.OutliveTimeAfterShutdown, that is
recorded when a Document object survives 5, 10, 20 or 50 garbage
collections after detached. If a document outlives such long time, the
document might be leaked. The UKM would be very useful to know where such
leaky documents exist and to fix them.

Design doc: https://docs.google.com/document/d/1fbs5smdd-pBLLMpq7u8EkyddZILtI7CZPJlo_AA1kak/edit?usp=sharing

Bug: 757374
Change-Id: I1f64d2a9260d898c386bb948dd25a1c5586f8eb7
Reviewed-on: https://chromium-review.googlesource.com/722301
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510029}
parent b870abe3
...@@ -364,6 +364,7 @@ blink_core_sources("dom") { ...@@ -364,6 +364,7 @@ blink_core_sources("dom") {
deps = [ deps = [
"//services/metrics/public/cpp:metrics_cpp", "//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
"//services/metrics/public/interfaces", "//services/metrics/public/interfaces",
] ]
} }
...@@ -261,6 +261,7 @@ ...@@ -261,6 +261,7 @@
#include "public/platform/modules/insecure_input/insecure_input_service.mojom-blink.h" #include "public/platform/modules/insecure_input/insecure_input_service.mojom-blink.h"
#include "public/platform/site_engagement.mojom-blink.h" #include "public/platform/site_engagement.mojom-blink.h"
#include "services/metrics/public/cpp/mojo_ukm_recorder.h" #include "services/metrics/public/cpp/mojo_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/interfaces/ukm_interface.mojom-shared.h" #include "services/metrics/public/interfaces/ukm_interface.mojom-shared.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
...@@ -311,6 +312,7 @@ class DocumentOutliveTimeReporter : public BlinkGCObserver { ...@@ -311,6 +312,7 @@ class DocumentOutliveTimeReporter : public BlinkGCObserver {
int outlive_time_count = GetOutliveTimeCount(); int outlive_time_count = GetOutliveTimeCount();
if (outlive_time_count == 5 || outlive_time_count == 10) { if (outlive_time_count == 5 || outlive_time_count == 10) {
const char* kUMAString = "Document.OutliveTimeAfterShutdown.GCCount"; const char* kUMAString = "Document.OutliveTimeAfterShutdown.GCCount";
if (outlive_time_count == 5) if (outlive_time_count == 5)
UMA_HISTOGRAM_ENUMERATION(kUMAString, kGCCount5, kGCCountMax); UMA_HISTOGRAM_ENUMERATION(kUMAString, kGCCount5, kGCCountMax);
else if (outlive_time_count == 10) else if (outlive_time_count == 10)
...@@ -318,6 +320,11 @@ class DocumentOutliveTimeReporter : public BlinkGCObserver { ...@@ -318,6 +320,11 @@ class DocumentOutliveTimeReporter : public BlinkGCObserver {
else else
NOTREACHED(); NOTREACHED();
} }
if (outlive_time_count == 5 || outlive_time_count == 10 ||
outlive_time_count == 20 || outlive_time_count == 50) {
document_->RecordUkmOutliveTimeAfterShutdown(outlive_time_count);
}
} }
private: private:
...@@ -3697,8 +3704,17 @@ void Document::SetURL(const KURL& url) { ...@@ -3697,8 +3704,17 @@ void Document::SetURL(const KURL& url) {
UpdateBaseURL(); UpdateBaseURL();
GetContextFeatures().UrlDidChange(this); GetContextFeatures().UrlDidChange(this);
if (ukm_recorder_) if (!ukm_recorder_ && IsInMainFrame()) {
ukm::mojom::UkmRecorderInterfacePtr interface;
frame_->GetInterfaceProvider().GetInterface(mojo::MakeRequest(&interface));
ukm_source_id_ = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder_.reset(new ukm::MojoUkmRecorder(std::move(interface)));
}
if (ukm_recorder_) {
DCHECK(IsInMainFrame());
ukm_recorder_->UpdateSourceURL(ukm_source_id_, url_); ukm_recorder_->UpdateSourceURL(ukm_source_id_, url_);
}
} }
KURL Document::ValidBaseElementURL() const { KURL Document::ValidBaseElementURL() const {
...@@ -7232,6 +7248,15 @@ void Document::RecordDeferredLoadReason(WouldLoadReason reason) { ...@@ -7232,6 +7248,15 @@ void Document::RecordDeferredLoadReason(WouldLoadReason reason) {
would_load_reason_ = reason; would_load_reason_ = reason;
} }
void Document::RecordUkmOutliveTimeAfterShutdown(int outlive_time_count) {
if (!ukm_recorder_)
return;
ukm::builders::Document_OutliveTimeAfterShutdown(ukm_source_id_)
.SetGCCount(outlive_time_count)
.Record(ukm_recorder_.get());
}
DEFINE_TRACE_WRAPPERS(Document) { DEFINE_TRACE_WRAPPERS(Document) {
// node_lists_ are traced in their corresponding NodeListsNodeData, keeping // node_lists_ are traced in their corresponding NodeListsNodeData, keeping
// them only alive for live nodes. Otherwise we would keep lists of dead // them only alive for live nodes. Otherwise we would keep lists of dead
......
...@@ -1391,6 +1391,8 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -1391,6 +1391,8 @@ class CORE_EXPORT Document : public ContainerNode,
ukm::UkmRecorder* UkmRecorder(); ukm::UkmRecorder* UkmRecorder();
int64_t UkmSourceID() const; int64_t UkmSourceID() const;
void RecordUkmOutliveTimeAfterShutdown(int outlive_time_count);
protected: protected:
Document(const DocumentInit&, DocumentClassFlags = kDefaultDocumentClass); Document(const DocumentInit&, DocumentClassFlags = kDefaultDocumentClass);
......
...@@ -390,6 +390,24 @@ be describing additional metrics about the same event. ...@@ -390,6 +390,24 @@ be describing additional metrics about the same event.
</metric> </metric>
</event> </event>
<event name="Document.OutliveTimeAfterShutdown">
<owner>hajimehoshi@chromium.org</owner>
<owner>keishi@chromium.org</owner>
<summary>
Recorded when a Document object survives certain number of garbage
collections after detached. It is expected that regular Document objects are
destroyed soon after detached, and if a document outlives longer, probably
this can be leaked.
</summary>
<metric name="GCCount">
<summary>
Measures the numbers of garbarge collection after the document is
detached. This is recorded when the number reached certain numbers like 5
or 10.
</summary>
</metric>
</event>
<event name="Event.ScrollUpdate.Touch"> <event name="Event.ScrollUpdate.Touch">
<owner>nzolghadr@chromium.org</owner> <owner>nzolghadr@chromium.org</owner>
<summary> <summary>
......
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