Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp

Issue 2490563002: Revert of DevTools: add the logging aspect into the PerformanceMonitor (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c4a82e0b65731d7e7e01be7def8b0fd8760070be..9258d86ae622bf30f9648d6dc66e2de8909da747 100644
--- a/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
+++ b/third_party/WebKit/Source/core/frame/PerformanceMonitor.cpp
@@ -4,30 +4,21 @@
#include "core/frame/PerformanceMonitor.h"
-#include "bindings/core/v8/SourceLocation.h"
#include "core/InstrumentingAgents.h"
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/Frame.h"
-#include "core/frame/FrameConsole.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h"
-#include "core/inspector/ConsoleMessage.h"
#include "core/timing/DOMWindowPerformance.h"
#include "core/timing/Performance.h"
#include "public/platform/Platform.h"
-#include "wtf/CurrentTime.h"
namespace blink {
namespace {
static const double kLongTaskThresholdMillis = 50.0;
-static const double kLongTaskWarningThresholdMillis = 150.0;
-
-static const double kSyncLayoutThresholdMillis = 30.0;
-static const double kSyncLayoutWarningThresholdMillis = 60.0;
-
static const char kUnknownAttribution[] = "unknown";
static const char kAmbugiousAttribution[] = "multiple-contexts";
static const char kSameOriginAttribution[] = "same-origin";
@@ -50,7 +41,7 @@
LocalFrame* frame = performance->frame();
PerformanceMonitor* monitor = frame->performanceMonitor();
monitor->m_webPerformanceObservers.add(performance);
- monitor->updateInstrumentation();
+ monitor->enable();
}
// static
@@ -62,82 +53,8 @@
}
PerformanceMonitor* monitor = frame->performanceMonitor();
monitor->m_webPerformanceObservers.remove(performance);
- monitor->updateInstrumentation();
-}
-
-// static
-void PerformanceMonitor::willExecuteScript(ExecutionContext* context) {
- PerformanceMonitor* performanceMonitor =
- PerformanceMonitor::instrumentingMonitor(context);
- if (performanceMonitor)
- performanceMonitor->innerWillExecuteScript(context);
-}
-
-// static
-void PerformanceMonitor::didExecuteScript(ExecutionContext* context) {
- PerformanceMonitor* performanceMonitor =
- PerformanceMonitor::instrumentingMonitor(context);
- if (performanceMonitor)
- performanceMonitor->didExecuteScript();
-}
-
-// 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
-bool PerformanceMonitor::enabled(ExecutionContext* context) {
- return PerformanceMonitor::instrumentingMonitor(context);
-}
-
-// static
-void PerformanceMonitor::logViolation(MessageLevel level,
- ExecutionContext* context,
- const String& messageText) {
- PerformanceMonitor* performanceMonitor =
- PerformanceMonitor::instrumentingMonitor(context);
- if (performanceMonitor)
- performanceMonitor->logViolation(level, messageText);
-}
-
-// static
-void PerformanceMonitor::logViolation(
- MessageLevel level,
- ExecutionContext* context,
- const String& messageText,
- std::unique_ptr<SourceLocation> location) {
- PerformanceMonitor* performanceMonitor =
- PerformanceMonitor::instrumentingMonitor(context);
- if (performanceMonitor)
- performanceMonitor->logViolation(level, messageText, std::move(location));
+ if (!monitor->m_webPerformanceObservers.size())
+ monitor->disable();
}
// static
@@ -152,33 +69,38 @@
return monitor->m_enabled ? monitor : nullptr;
}
+// static
+void PerformanceMonitor::willExecuteScript(ExecutionContext* context) {
+ PerformanceMonitor* performanceMonitor =
+ PerformanceMonitor::instrumentingMonitor(context);
+ if (performanceMonitor)
+ performanceMonitor->innerWillExecuteScript(context);
+}
+
PerformanceMonitor::PerformanceMonitor(LocalFrame* localRoot)
: m_localRoot(localRoot) {}
PerformanceMonitor::~PerformanceMonitor() {}
-void PerformanceMonitor::setLoggingEnabled(bool enabled) {
- m_loggingEnabled = enabled;
- updateInstrumentation();
+void PerformanceMonitor::enable() {
+ if (m_enabled)
+ return;
+ m_enabled = true;
+ UseCounter::count(m_localRoot, UseCounter::LongTaskObserver);
+ Platform::current()->currentThread()->addTaskTimeObserver(this);
+ Platform::current()->currentThread()->addTaskObserver(this);
}
-void PerformanceMonitor::updateInstrumentation() {
- bool shouldEnable = m_loggingEnabled || m_webPerformanceObservers.size();
- if (shouldEnable == m_enabled)
+void PerformanceMonitor::disable() {
+ if (!m_enabled)
return;
- if (shouldEnable) {
- UseCounter::count(m_localRoot, UseCounter::LongTaskObserver);
- Platform::current()->currentThread()->addTaskTimeObserver(this);
- Platform::current()->currentThread()->addTaskObserver(this);
- } else {
- Platform::current()->currentThread()->removeTaskTimeObserver(this);
- Platform::current()->currentThread()->removeTaskObserver(this);
- }
- m_enabled = shouldEnable;
+ m_enabled = false;
+ DCHECK(!m_webPerformanceObservers.size());
+ Platform::current()->currentThread()->removeTaskTimeObserver(this);
+ Platform::current()->currentThread()->removeTaskObserver(this);
}
void PerformanceMonitor::innerWillExecuteScript(ExecutionContext* context) {
- m_isExecutingScript = true;
// 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.
@@ -186,64 +108,23 @@
// NOTE: This heuristic is imperfect and will be improved in V2 API.
// In V2, timing of script execution along with style & layout updates will be
// accounted for detailed and more accurate attribution.
- if (context->isDocument() && toDocument(context)->frame())
+ if (context->isDocument() && toDocument(context)->frame()) {
m_frameContexts.add(toDocument(context)->frame());
-}
-
-void PerformanceMonitor::didExecuteScript() {
- m_isExecutingScript = false;
-}
-
-void PerformanceMonitor::willUpdateLayout() {
- if (m_isExecutingScript)
- m_layoutStartTime = WTF::monotonicallyIncreasingTime();
-}
-
-void PerformanceMonitor::didUpdateLayout() {
- if (m_isExecutingScript) {
- m_perTaskStyleAndLayoutTime +=
- WTF::monotonicallyIncreasingTime() - m_layoutStartTime;
- }
-}
-
-void PerformanceMonitor::willRecalculateStyle() {
- if (m_isExecutingScript)
- m_styleStartTime = WTF::monotonicallyIncreasingTime();
-}
-
-void PerformanceMonitor::didRecalculateStyle() {
- if (m_isExecutingScript) {
- m_perTaskStyleAndLayoutTime +=
- WTF::monotonicallyIncreasingTime() - m_styleStartTime;
}
}
void PerformanceMonitor::willProcessTask() {
- m_perTaskStyleAndLayoutTime = 0;
// Reset m_frameContexts. We don't clear this in didProcessTask
// as it is needed in ReportTaskTime which occurs after didProcessTask.
m_frameContexts.clear();
}
-void PerformanceMonitor::didProcessTask() {
- if (m_perTaskStyleAndLayoutTime * 1000 < kSyncLayoutThresholdMillis)
- return;
-
- if (m_loggingEnabled) {
- logViolation(
- m_perTaskStyleAndLayoutTime * 1000 < kSyncLayoutWarningThresholdMillis
- ? InfoMessageLevel
- : WarningMessageLevel,
- String::format("Forced reflow while executing JavaScript took %ldms.",
- lround(m_perTaskStyleAndLayoutTime * 1000)));
- }
-}
+void PerformanceMonitor::didProcessTask() {}
void PerformanceMonitor::ReportTaskTime(scheduler::TaskQueue*,
double startTime,
double endTime) {
- double taskTimeMs = (endTime - startTime) * 1000;
- if (taskTimeMs < kLongTaskThresholdMillis)
+ if (((endTime - startTime) * 1000) <= kLongTaskThresholdMillis)
return;
for (Performance* performance : m_webPerformanceObservers) {
@@ -254,29 +135,6 @@
performance->addLongTaskTiming(startTime, endTime, attribution.first,
attribution.second);
}
- if (m_loggingEnabled) {
- logViolation(taskTimeMs < kLongTaskWarningThresholdMillis
- ? InfoMessageLevel
- : WarningMessageLevel,
- String::format("Long running JavaScript task took %ldms.",
- lround(taskTimeMs)));
- }
-}
-
-void PerformanceMonitor::logViolation(MessageLevel level,
- const String& messageText) {
- ConsoleMessage* message =
- ConsoleMessage::create(ViolationMessageSource, level, messageText);
- m_localRoot->console().addMessage(message);
-}
-
-void PerformanceMonitor::logViolation(
- MessageLevel level,
- const String& messageText,
- std::unique_ptr<SourceLocation> location) {
- ConsoleMessage* message = ConsoleMessage::create(
- ViolationMessageSource, level, messageText, std::move(location));
- m_localRoot->console().addMessage(message);
}
/**
« no previous file with comments | « third_party/WebKit/Source/core/frame/PerformanceMonitor.h ('k') | third_party/WebKit/Source/core/frame/Settings.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698