Commit 3eb6e6ce authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

[DL]: Add async traces to indicate when the lock is acquired and in what state.

This patch adds some trace information to Display locking to allow
keeping track of display lock state in traces.

R=chrishtr@chromium.org, rakina@chromium.org

Bug: 882663
Change-Id: I1e67370ab06b6eebda6efed0e8e3870cdc4bfc2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504163Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarRakina Zata Amni <rakina@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638159}
parent e7301fc2
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/core/display_lock/display_lock_context.h" #include "third_party/blink/renderer/core/display_lock/display_lock_context.h"
#include <string>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_options.h" #include "third_party/blink/renderer/core/display_lock/display_lock_options.h"
#include "third_party/blink/renderer/core/display_lock/strict_yielding_display_lock_budget.h" #include "third_party/blink/renderer/core/display_lock/strict_yielding_display_lock_budget.h"
...@@ -37,6 +39,24 @@ const char* kElementIsDisconnected = "Element is disconnected."; ...@@ -37,6 +39,24 @@ const char* kElementIsDisconnected = "Element is disconnected.";
const char* kLockCommitted = "Lock commit was requested."; const char* kLockCommitted = "Lock commit was requested.";
} // namespace rejection_names } // namespace rejection_names
// Helper function to convert a display locking state to a string. Used in
// traces.
std::string StateToString(DisplayLockContext::State state) {
switch (state) {
case DisplayLockContext::kLocked:
return "kLocked";
case DisplayLockContext::kUpdating:
return "kUpdating";
case DisplayLockContext::kCommitting:
return "kCommitting";
case DisplayLockContext::kUnlocked:
return "kUnlocked";
case DisplayLockContext::kPendingAcquire:
return "kPendingAcquire";
}
return "";
}
// Helper function that returns an immediately rejected promise. // Helper function that returns an immediately rejected promise.
ScriptPromise GetRejectedPromise(ScriptState* script_state, ScriptPromise GetRejectedPromise(ScriptState* script_state,
const char* rejection_reason) { const char* rejection_reason) {
...@@ -120,6 +140,7 @@ bool DisplayLockContext::HasPendingActivity() const { ...@@ -120,6 +140,7 @@ bool DisplayLockContext::HasPendingActivity() const {
ScriptPromise DisplayLockContext::acquire(ScriptState* script_state, ScriptPromise DisplayLockContext::acquire(ScriptState* script_state,
DisplayLockOptions* options) { DisplayLockOptions* options) {
TRACE_EVENT0("blink", "DisplayLockContext::acquire()");
double timeout_ms = (options && options->hasTimeout()) double timeout_ms = (options && options->hasTimeout())
? options->timeout() ? options->timeout()
: kDefaultLockTimeoutMs; : kDefaultLockTimeoutMs;
...@@ -167,6 +188,7 @@ ScriptPromise DisplayLockContext::acquire(ScriptState* script_state, ...@@ -167,6 +188,7 @@ ScriptPromise DisplayLockContext::acquire(ScriptState* script_state,
} }
ScriptPromise DisplayLockContext::update(ScriptState* script_state) { ScriptPromise DisplayLockContext::update(ScriptState* script_state) {
TRACE_EVENT0("blink", "DisplayLockContext::update()");
// Reject if we're unlocked or disconnected. // Reject if we're unlocked or disconnected.
if (state_ == kUnlocked || state_ == kPendingAcquire || if (state_ == kUnlocked || state_ == kPendingAcquire ||
!element_->isConnected()) { !element_->isConnected()) {
...@@ -187,6 +209,7 @@ ScriptPromise DisplayLockContext::update(ScriptState* script_state) { ...@@ -187,6 +209,7 @@ ScriptPromise DisplayLockContext::update(ScriptState* script_state) {
} }
ScriptPromise DisplayLockContext::commit(ScriptState* script_state) { ScriptPromise DisplayLockContext::commit(ScriptState* script_state) {
TRACE_EVENT0("blink", "DisplayLockContext::commit()");
// Resolve if we're already unlocked. // Resolve if we're already unlocked.
if (state_ == kUnlocked) if (state_ == kUnlocked)
return GetResolvedPromise(script_state); return GetResolvedPromise(script_state);
...@@ -214,6 +237,8 @@ ScriptPromise DisplayLockContext::commit(ScriptState* script_state) { ...@@ -214,6 +237,8 @@ ScriptPromise DisplayLockContext::commit(ScriptState* script_state) {
} }
ScriptPromise DisplayLockContext::updateAndCommit(ScriptState* script_state) { ScriptPromise DisplayLockContext::updateAndCommit(ScriptState* script_state) {
TRACE_EVENT0("blink", "DisplayLockContext::updateAndCommit()");
// Resolve if we're already unlocked. // Resolve if we're already unlocked.
if (state_ == kUnlocked) if (state_ == kUnlocked)
return GetResolvedPromise(script_state); return GetResolvedPromise(script_state);
...@@ -802,10 +827,20 @@ operator=(State new_state) { ...@@ -802,10 +827,20 @@ operator=(State new_state) {
if (new_state == state_) if (new_state == state_)
return *this; return *this;
if (state_ == kUnlocked) {
TRACE_EVENT_ASYNC_BEGIN0("blink", "LockedDisplayLock", this);
} else if (new_state == kUnlocked) {
TRACE_EVENT_ASYNC_END0("blink", "LockedDisplayLock", this);
}
bool was_activatable = context_->IsActivatable(); bool was_activatable = context_->IsActivatable();
bool was_locked = context_->IsLocked(); bool was_locked = context_->IsLocked();
state_ = new_state; state_ = new_state;
if (state_ != kUnlocked) {
TRACE_EVENT_ASYNC_STEP_INTO0("blink", "LockedDisplayLock", this,
StateToString(state_));
}
if (!context_->document_) if (!context_->document_)
return *this; return *this;
......
...@@ -50,6 +50,15 @@ class CORE_EXPORT DisplayLockContext final ...@@ -50,6 +50,15 @@ class CORE_EXPORT DisplayLockContext final
kDefault = kYieldBetweenLifecyclePhases kDefault = kYieldBetweenLifecyclePhases
}; };
// The current state of the lock. Note that the order of these matters.
enum State {
kLocked,
kUpdating,
kCommitting,
kUnlocked,
kPendingAcquire,
};
// See GetScopedPendingFrameRect() for description. // See GetScopedPendingFrameRect() for description.
class ScopedPendingFrameRect { class ScopedPendingFrameRect {
STACK_ALLOCATED(); STACK_ALLOCATED();
...@@ -162,15 +171,6 @@ class CORE_EXPORT DisplayLockContext final ...@@ -162,15 +171,6 @@ class CORE_EXPORT DisplayLockContext final
friend class DisplayLockSuspendedHandle; friend class DisplayLockSuspendedHandle;
friend class DisplayLockBudget; friend class DisplayLockBudget;
// The current state of the lock. Note that the order of these matters.
enum State {
kLocked,
kUpdating,
kCommitting,
kUnlocked,
kPendingAcquire,
};
class StateChangeHelper { class StateChangeHelper {
DISALLOW_NEW(); DISALLOW_NEW();
......
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