Commit 0b71f602 authored by Peter Kvitek's avatar Peter Kvitek Committed by Commit Bot

Added CaptureSnapshotDuration metric to Performance.getMetrics.

This metric tracks time spent in DOMSnapshot::captureSnapshot calls.

Drive by: subtracted v8 compilation duration from tasks duration
when calculating other tasks duration. This ensures correct stacking
known activities.

Change-Id: I79c6926d516c02717b68ea426e3e99a7d9fd665e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062691
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742888}
parent fce89d8a
...@@ -252,17 +252,18 @@ void WebDevToolsAgentImpl::AttachSession(DevToolsSession* session, ...@@ -252,17 +252,18 @@ void WebDevToolsAgentImpl::AttachSession(DevToolsSession* session,
session->V8Session()); session->V8Session());
session->Append(dom_debugger_agent); session->Append(dom_debugger_agent);
InspectorPerformanceAgent* performance_agent =
MakeGarbageCollected<InspectorPerformanceAgent>(inspected_frames);
session->Append(performance_agent);
session->Append(MakeGarbageCollected<InspectorDOMSnapshotAgent>( session->Append(MakeGarbageCollected<InspectorDOMSnapshotAgent>(
inspected_frames, dom_debugger_agent)); inspected_frames, dom_debugger_agent, performance_agent));
session->Append(MakeGarbageCollected<InspectorAnimationAgent>( session->Append(MakeGarbageCollected<InspectorAnimationAgent>(
inspected_frames, css_agent, session->V8Session())); inspected_frames, css_agent, session->V8Session()));
session->Append(MakeGarbageCollected<InspectorMemoryAgent>(inspected_frames)); session->Append(MakeGarbageCollected<InspectorMemoryAgent>(inspected_frames));
session->Append(
MakeGarbageCollected<InspectorPerformanceAgent>(inspected_frames));
session->Append( session->Append(
MakeGarbageCollected<InspectorApplicationCacheAgent>(inspected_frames)); MakeGarbageCollected<InspectorApplicationCacheAgent>(inspected_frames));
......
...@@ -125,9 +125,11 @@ PhysicalRect InspectorDOMSnapshotAgent::TextFragmentRectInDocument( ...@@ -125,9 +125,11 @@ PhysicalRect InspectorDOMSnapshotAgent::TextFragmentRectInDocument(
InspectorDOMSnapshotAgent::InspectorDOMSnapshotAgent( InspectorDOMSnapshotAgent::InspectorDOMSnapshotAgent(
InspectedFrames* inspected_frames, InspectedFrames* inspected_frames,
InspectorDOMDebuggerAgent* dom_debugger_agent) InspectorDOMDebuggerAgent* dom_debugger_agent,
InspectorPerformanceAgent* performance_agent)
: inspected_frames_(inspected_frames), : inspected_frames_(inspected_frames),
dom_debugger_agent_(dom_debugger_agent), dom_debugger_agent_(dom_debugger_agent),
performance_agent_(performance_agent),
enabled_(&agent_state_, /*default_value=*/false) {} enabled_(&agent_state_, /*default_value=*/false) {}
InspectorDOMSnapshotAgent::~InspectorDOMSnapshotAgent() = default; InspectorDOMSnapshotAgent::~InspectorDOMSnapshotAgent() = default;
...@@ -226,6 +228,17 @@ protocol::Response InspectorDOMSnapshotAgent::captureSnapshot( ...@@ -226,6 +228,17 @@ protocol::Response InspectorDOMSnapshotAgent::captureSnapshot(
std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DocumentSnapshot>>* std::unique_ptr<protocol::Array<protocol::DOMSnapshot::DocumentSnapshot>>*
documents, documents,
std::unique_ptr<protocol::Array<String>>* strings) { std::unique_ptr<protocol::Array<String>>* strings) {
struct ScopedPerformanceReporter {
explicit ScopedPerformanceReporter(
InspectorPerformanceAgent* performance_agent)
: performance_agent(performance_agent) {
performance_agent->WillCaptureSnapshot();
}
~ScopedPerformanceReporter() { performance_agent->DidCaptureSnapshot(); }
InspectorPerformanceAgent* performance_agent;
STACK_ALLOCATED();
} scoped_performance_reporter(performance_agent_);
// This function may kick the layout, but external clients may call this // This function may kick the layout, but external clients may call this
// function outside of the layout phase. // function outside of the layout phase.
FontCachePurgePreventer fontCachePurgePreventer; FontCachePurgePreventer fontCachePurgePreventer;
...@@ -721,6 +734,7 @@ void InspectorDOMSnapshotAgent::VisitPaintLayer( ...@@ -721,6 +734,7 @@ void InspectorDOMSnapshotAgent::VisitPaintLayer(
void InspectorDOMSnapshotAgent::Trace(Visitor* visitor) { void InspectorDOMSnapshotAgent::Trace(Visitor* visitor) {
visitor->Trace(inspected_frames_); visitor->Trace(inspected_frames_);
visitor->Trace(dom_debugger_agent_); visitor->Trace(dom_debugger_agent_);
visitor->Trace(performance_agent_);
visitor->Trace(document_order_map_); visitor->Trace(document_order_map_);
InspectorBaseAgent::Trace(visitor); InspectorBaseAgent::Trace(visitor);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/css/css_property_names.h" #include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h" #include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/inspector/inspector_base_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_base_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_performance_agent.h"
#include "third_party/blink/renderer/core/inspector/protocol/DOMSnapshot.h" #include "third_party/blink/renderer/core/inspector/protocol/DOMSnapshot.h"
#include "third_party/blink/renderer/core/layout/layout_text.h" #include "third_party/blink/renderer/core/layout/layout_text.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h"
...@@ -26,7 +27,9 @@ class PaintLayer; ...@@ -26,7 +27,9 @@ class PaintLayer;
class CORE_EXPORT InspectorDOMSnapshotAgent final class CORE_EXPORT InspectorDOMSnapshotAgent final
: public InspectorBaseAgent<protocol::DOMSnapshot::Metainfo> { : public InspectorBaseAgent<protocol::DOMSnapshot::Metainfo> {
public: public:
InspectorDOMSnapshotAgent(InspectedFrames*, InspectorDOMDebuggerAgent*); InspectorDOMSnapshotAgent(InspectedFrames*,
InspectorDOMDebuggerAgent*,
InspectorPerformanceAgent*);
~InspectorDOMSnapshotAgent() override; ~InspectorDOMSnapshotAgent() override;
void Trace(Visitor*) override; void Trace(Visitor*) override;
...@@ -128,6 +131,7 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final ...@@ -128,6 +131,7 @@ class CORE_EXPORT InspectorDOMSnapshotAgent final
DocumentOrderMap document_order_map_; DocumentOrderMap document_order_map_;
Member<InspectedFrames> inspected_frames_; Member<InspectedFrames> inspected_frames_;
Member<InspectorDOMDebuggerAgent> dom_debugger_agent_; Member<InspectorDOMDebuggerAgent> dom_debugger_agent_;
Member<InspectorPerformanceAgent> performance_agent_;
InspectorAgentState::Boolean enabled_; InspectorAgentState::Boolean enabled_;
DISALLOW_COPY_AND_ASSIGN(InspectorDOMSnapshotAgent); DISALLOW_COPY_AND_ASSIGN(InspectorDOMSnapshotAgent);
}; };
......
...@@ -57,6 +57,7 @@ void InspectorPerformanceAgent::InnerEnable() { ...@@ -57,6 +57,7 @@ void InspectorPerformanceAgent::InnerEnable() {
task_start_ticks_ = base::TimeTicks(); task_start_ticks_ = base::TimeTicks();
script_start_ticks_ = base::TimeTicks(); script_start_ticks_ = base::TimeTicks();
v8compile_start_ticks_ = base::TimeTicks(); v8compile_start_ticks_ = base::TimeTicks();
capture_snapshot_start_ticks_ = base::TimeTicks();
thread_time_origin_ = GetThreadTimeNow(); thread_time_origin_ = GetThreadTimeNow();
} }
...@@ -153,6 +154,8 @@ Response InspectorPerformanceAgent::getMetrics( ...@@ -153,6 +154,8 @@ Response InspectorPerformanceAgent::getMetrics(
AppendMetric(result.get(), "LayoutDuration", layout_duration_.InSecondsF()); AppendMetric(result.get(), "LayoutDuration", layout_duration_.InSecondsF());
AppendMetric(result.get(), "RecalcStyleDuration", AppendMetric(result.get(), "RecalcStyleDuration",
recalc_style_duration_.InSecondsF()); recalc_style_duration_.InSecondsF());
AppendMetric(result.get(), "CaptureSnapshotDuration",
capture_snapshot_duration_.InSecondsF());
base::TimeDelta script_duration = script_duration_; base::TimeDelta script_duration = script_duration_;
if (!script_start_ticks_.is_null()) if (!script_start_ticks_.is_null())
...@@ -173,7 +176,8 @@ Response InspectorPerformanceAgent::getMetrics( ...@@ -173,7 +176,8 @@ Response InspectorPerformanceAgent::getMetrics(
// Compute task time not accounted for by other metrics. // Compute task time not accounted for by other metrics.
base::TimeDelta other_tasks_duration = base::TimeDelta other_tasks_duration =
task_duration - task_duration -
(script_duration + recalc_style_duration_ + layout_duration_); (script_duration + v8compile_duration + recalc_style_duration_ +
layout_duration_ + capture_snapshot_duration_);
AppendMetric(result.get(), "TaskOtherDuration", AppendMetric(result.get(), "TaskOtherDuration",
other_tasks_duration.InSecondsF()); other_tasks_duration.InSecondsF());
...@@ -309,6 +313,18 @@ void InspectorPerformanceAgent::DidProcessTask(base::TimeTicks start_time, ...@@ -309,6 +313,18 @@ void InspectorPerformanceAgent::DidProcessTask(base::TimeTicks start_time,
task_start_ticks_ = base::TimeTicks(); task_start_ticks_ = base::TimeTicks();
} }
void InspectorPerformanceAgent::WillCaptureSnapshot() {
capture_snapshot_start_ticks_ = GetTimeTicksNow();
}
void InspectorPerformanceAgent::DidCaptureSnapshot() {
if (!capture_snapshot_start_ticks_.is_null()) {
capture_snapshot_duration_ +=
GetTimeTicksNow() - capture_snapshot_start_ticks_;
}
capture_snapshot_start_ticks_ = base::TimeTicks();
}
void InspectorPerformanceAgent::Trace(Visitor* visitor) { void InspectorPerformanceAgent::Trace(Visitor* visitor) {
visitor->Trace(inspected_frames_); visitor->Trace(inspected_frames_);
InspectorBaseAgent<protocol::Performance::Metainfo>::Trace(visitor); InspectorBaseAgent<protocol::Performance::Metainfo>::Trace(visitor);
......
...@@ -62,6 +62,10 @@ class CORE_EXPORT InspectorPerformanceAgent final ...@@ -62,6 +62,10 @@ class CORE_EXPORT InspectorPerformanceAgent final
void DidProcessTask(base::TimeTicks start_time, void DidProcessTask(base::TimeTicks start_time,
base::TimeTicks end_time) override; base::TimeTicks end_time) override;
// Called from DOMSnapshotAgent
void WillCaptureSnapshot();
void DidCaptureSnapshot();
private: private:
void ScriptStarts(); void ScriptStarts();
void ScriptEnds(); void ScriptEnds();
...@@ -80,6 +84,8 @@ class CORE_EXPORT InspectorPerformanceAgent final ...@@ -80,6 +84,8 @@ class CORE_EXPORT InspectorPerformanceAgent final
base::TimeTicks task_start_ticks_; base::TimeTicks task_start_ticks_;
base::TimeDelta v8compile_duration_; base::TimeDelta v8compile_duration_;
base::TimeTicks v8compile_start_ticks_; base::TimeTicks v8compile_start_ticks_;
base::TimeDelta capture_snapshot_duration_;
base::TimeTicks capture_snapshot_start_ticks_;
base::TimeTicks thread_time_origin_; base::TimeTicks thread_time_origin_;
uint64_t layout_count_ = 0; uint64_t layout_count_ = 0;
uint64_t recalc_style_count_ = 0; uint64_t recalc_style_count_ = 0;
......
...@@ -4,6 +4,7 @@ Tests stability of performance metrics list. ...@@ -4,6 +4,7 @@ Tests stability of performance metrics list.
Metrics reported: Metrics reported:
AdSubframes AdSubframes
AudioHandlers AudioHandlers
CaptureSnapshotDuration
ContextLifecycleStateObservers ContextLifecycleStateObservers
DetachedScriptStates DetachedScriptStates
Documents Documents
......
...@@ -22,6 +22,7 @@ title: test1 ...@@ -22,6 +22,7 @@ title: test1
RecalcStyleCount RecalcStyleCount
LayoutDuration LayoutDuration
RecalcStyleDuration RecalcStyleDuration
CaptureSnapshotDuration
ScriptDuration ScriptDuration
V8CompileDuration V8CompileDuration
TaskDuration TaskDuration
...@@ -55,6 +56,7 @@ title: test1 ...@@ -55,6 +56,7 @@ title: test1
RecalcStyleCount RecalcStyleCount
LayoutDuration LayoutDuration
RecalcStyleDuration RecalcStyleDuration
CaptureSnapshotDuration
ScriptDuration ScriptDuration
V8CompileDuration V8CompileDuration
TaskDuration TaskDuration
...@@ -88,6 +90,7 @@ title: ...@@ -88,6 +90,7 @@ title:
RecalcStyleCount RecalcStyleCount
LayoutDuration LayoutDuration
RecalcStyleDuration RecalcStyleDuration
CaptureSnapshotDuration
ScriptDuration ScriptDuration
V8CompileDuration V8CompileDuration
TaskDuration TaskDuration
......
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