| Index: third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
|
| diff --git a/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp b/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
|
| index a8990cd56f8e0573455df2abc88bbf4acb951306..4721fbc8ce4c771be9274d2e657f3a2f27a07396 100644
|
| --- a/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
|
| +++ b/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
|
| @@ -7,6 +7,7 @@
|
| #include "bindings/core/v8/ScheduledAction.h"
|
| #include "bindings/core/v8/ScriptEventListener.h"
|
| #include "bindings/core/v8/SourceLocation.h"
|
| +#include "core/InstrumentingAgents.h"
|
| #include "core/dom/Document.h"
|
| #include "core/dom/ExecutionContext.h"
|
| #include "core/events/EventListener.h"
|
| @@ -61,78 +62,6 @@ PerformanceMonitor::HandlerCall::~HandlerCall() {
|
| }
|
|
|
| // static
|
| -void PerformanceMonitor::willExecuteScript(ExecutionContext* context) {
|
| - PerformanceMonitor* performanceMonitor = PerformanceMonitor::monitor(context);
|
| - if (performanceMonitor)
|
| - performanceMonitor->alwaysWillExecuteScript(context);
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::didExecuteScript(ExecutionContext* context) {
|
| - PerformanceMonitor* performanceMonitor = PerformanceMonitor::monitor(context);
|
| - if (performanceMonitor)
|
| - performanceMonitor->alwaysDidExecuteScript();
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::willCallFunction(ExecutionContext* context) {
|
| - PerformanceMonitor* performanceMonitor = PerformanceMonitor::monitor(context);
|
| - if (performanceMonitor)
|
| - performanceMonitor->alwaysWillCallFunction(context);
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::didCallFunction(ExecutionContext* context,
|
| - v8::Local<v8::Function> function) {
|
| - PerformanceMonitor* performanceMonitor = PerformanceMonitor::monitor(context);
|
| - if (performanceMonitor)
|
| - performanceMonitor->alwaysDidCallFunction(context, function);
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::willUpdateLayout(Document* document) {
|
| - PerformanceMonitor* performanceMonitor =
|
| - PerformanceMonitor::instrumentingMonitor(document);
|
| - if (performanceMonitor)
|
| - performanceMonitor->willUpdateLayout();
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::didUpdateLayout(Document* document) {
|
| - PerformanceMonitor* performanceMonitor =
|
| - PerformanceMonitor::instrumentingMonitor(document);
|
| - if (performanceMonitor)
|
| - performanceMonitor->didUpdateLayout();
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::willRecalculateStyle(Document* document) {
|
| - PerformanceMonitor* performanceMonitor =
|
| - PerformanceMonitor::instrumentingMonitor(document);
|
| - if (performanceMonitor)
|
| - performanceMonitor->willRecalculateStyle();
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::didRecalculateStyle(Document* document) {
|
| - PerformanceMonitor* performanceMonitor =
|
| - PerformanceMonitor::instrumentingMonitor(document);
|
| - if (performanceMonitor)
|
| - performanceMonitor->didRecalculateStyle();
|
| -}
|
| -
|
| -// static
|
| -void PerformanceMonitor::documentWriteFetchScript(Document* document) {
|
| - PerformanceMonitor* performanceMonitor =
|
| - PerformanceMonitor::instrumentingMonitor(document);
|
| - if (!performanceMonitor)
|
| - return;
|
| - String text = "Parser was blocked due to document.write(<script>)";
|
| - performanceMonitor->innerReportGenericViolation(document, kBlockedParser,
|
| - text, 0, nullptr);
|
| -}
|
| -
|
| -// static
|
| double PerformanceMonitor::threshold(ExecutionContext* context,
|
| Violation violation) {
|
| PerformanceMonitor* monitor =
|
| @@ -177,10 +106,11 @@ PerformanceMonitor::PerformanceMonitor(LocalFrame* localRoot)
|
| : m_localRoot(localRoot) {
|
| std::fill(std::begin(m_thresholds), std::end(m_thresholds), 0);
|
| Platform::current()->currentThread()->addTaskTimeObserver(this);
|
| + m_localRoot->instrumentingAgents()->addPerformanceMonitor(this);
|
| }
|
|
|
| PerformanceMonitor::~PerformanceMonitor() {
|
| - shutdown();
|
| + DCHECK(!m_localRoot);
|
| }
|
|
|
| void PerformanceMonitor::subscribe(Violation violation,
|
| @@ -203,9 +133,13 @@ void PerformanceMonitor::unsubscribeAll(Client* client) {
|
| }
|
|
|
| void PerformanceMonitor::shutdown() {
|
| + if (!m_localRoot)
|
| + return;
|
| m_subscriptions.clear();
|
| updateInstrumentation();
|
| Platform::current()->currentThread()->removeTaskTimeObserver(this);
|
| + m_localRoot->instrumentingAgents()->removePerformanceMonitor(this);
|
| + m_localRoot = nullptr;
|
| }
|
|
|
| void PerformanceMonitor::updateInstrumentation() {
|
| @@ -225,7 +159,7 @@ void PerformanceMonitor::updateInstrumentation() {
|
| static_cast<int>(kAfterLast);
|
| }
|
|
|
| -void PerformanceMonitor::alwaysWillExecuteScript(ExecutionContext* context) {
|
| +void PerformanceMonitor::willExecuteScript(ExecutionContext* context) {
|
| // Heuristic for minimal frame context attribution: note the frame context
|
| // for each script execution. When a long task is encountered,
|
| // if there is only one frame context involved, then report it.
|
| @@ -240,22 +174,21 @@ void PerformanceMonitor::alwaysWillExecuteScript(ExecutionContext* context) {
|
| m_taskHasMultipleContexts = true;
|
| }
|
|
|
| -void PerformanceMonitor::alwaysDidExecuteScript() {
|
| +void PerformanceMonitor::didExecuteScript() {
|
| --m_scriptDepth;
|
| }
|
|
|
| -void PerformanceMonitor::alwaysWillCallFunction(ExecutionContext* context) {
|
| - alwaysWillExecuteScript(context);
|
| +void PerformanceMonitor::willCallFunction(ExecutionContext* context) {
|
| + willExecuteScript(context);
|
| if (!m_enabled)
|
| return;
|
| if (m_scriptDepth == 1 && m_thresholds[m_handlerType])
|
| m_scriptStartTime = WTF::monotonicallyIncreasingTime();
|
| }
|
|
|
| -void PerformanceMonitor::alwaysDidCallFunction(
|
| - ExecutionContext* context,
|
| - v8::Local<v8::Function> function) {
|
| - alwaysDidExecuteScript();
|
| +void PerformanceMonitor::didCallFunction(ExecutionContext* context,
|
| + v8::Local<v8::Function> function) {
|
| + didExecuteScript();
|
| if (!m_enabled)
|
| return;
|
| if (m_scriptDepth)
|
| @@ -277,12 +210,16 @@ void PerformanceMonitor::alwaysDidCallFunction(
|
| }
|
|
|
| void PerformanceMonitor::willUpdateLayout() {
|
| + if (!m_enabled)
|
| + return;
|
| if (m_thresholds[kLongLayout] && m_scriptDepth && !m_layoutDepth)
|
| m_layoutStartTime = WTF::monotonicallyIncreasingTime();
|
| ++m_layoutDepth;
|
| }
|
|
|
| void PerformanceMonitor::didUpdateLayout() {
|
| + if (!m_enabled)
|
| + return;
|
| --m_layoutDepth;
|
| if (m_thresholds[kLongLayout] && m_scriptDepth && !m_layoutDepth) {
|
| m_perTaskStyleAndLayoutTime +=
|
| @@ -290,18 +227,30 @@ void PerformanceMonitor::didUpdateLayout() {
|
| }
|
| }
|
|
|
| -void PerformanceMonitor::willRecalculateStyle() {
|
| +void PerformanceMonitor::willRecalculateStyle(Document*) {
|
| + if (!m_enabled)
|
| + return;
|
| +
|
| if (m_thresholds[kLongLayout] && m_scriptDepth)
|
| m_styleStartTime = WTF::monotonicallyIncreasingTime();
|
| }
|
|
|
| void PerformanceMonitor::didRecalculateStyle() {
|
| + if (!m_enabled)
|
| + return;
|
| if (m_thresholds[kLongLayout] && m_scriptDepth) {
|
| m_perTaskStyleAndLayoutTime +=
|
| WTF::monotonicallyIncreasingTime() - m_styleStartTime;
|
| }
|
| }
|
|
|
| +void PerformanceMonitor::documentWriteFetchScript(Document* document) {
|
| + if (!m_enabled)
|
| + return;
|
| + String text = "Parser was blocked due to document.write(<script>)";
|
| + innerReportGenericViolation(document, kBlockedParser, text, 0, nullptr);
|
| +}
|
| +
|
| void PerformanceMonitor::willProcessTask(scheduler::TaskQueue*,
|
| double startTime) {
|
| // Reset m_taskExecutionContext. We don't clear this in didProcessTask
|
|
|