Commit 4f0c590a authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Trace AllowBlocking and AllowIO primitives

This CL is adding trace events for the known issues that
can caused a waitable event or Disk IO on the IO-Thread.
The goal of this change is to allow to track jank and
identify the related bugs by using the slow-reports.

Currently, the ScopedBlockingCall shows a trace event
for the raw primitive but it is time consuming to get back
to the source of the bug. By adding a trace event on the
ScopedAllow*, it is easy to figure out the cause of the
blocking call.

Bug: 1047794
Change-Id: I05734d7344f9eca0307be3af08431fdc5dccf439
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031440
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741464}
parent f593e7b0
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
#include "base/debug/stack_trace.h" #include "base/debug/stack_trace.h"
...@@ -98,16 +100,6 @@ ScopedDisallowBlocking::~ScopedDisallowBlocking() { ...@@ -98,16 +100,6 @@ ScopedDisallowBlocking::~ScopedDisallowBlocking() {
g_blocking_disallowed.Get().Set(was_disallowed_); g_blocking_disallowed.Get().Set(was_disallowed_);
} }
ScopedAllowBlocking::ScopedAllowBlocking()
: was_disallowed_(g_blocking_disallowed.Get().Get()) {
g_blocking_disallowed.Get().Set(false);
}
ScopedAllowBlocking::~ScopedAllowBlocking() {
DCHECK(!g_blocking_disallowed.Get().Get());
g_blocking_disallowed.Get().Set(was_disallowed_);
}
void DisallowBaseSyncPrimitives() { void DisallowBaseSyncPrimitives() {
g_base_sync_primitives_disallowed.Get().Set(true); g_base_sync_primitives_disallowed.Get().Set(true);
} }
...@@ -126,18 +118,6 @@ ScopedAllowBaseSyncPrimitives::~ScopedAllowBaseSyncPrimitives() { ...@@ -126,18 +118,6 @@ ScopedAllowBaseSyncPrimitives::~ScopedAllowBaseSyncPrimitives() {
g_base_sync_primitives_disallowed.Get().Set(was_disallowed_); g_base_sync_primitives_disallowed.Get().Set(was_disallowed_);
} }
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope::
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope()
: was_disallowed_(g_base_sync_primitives_disallowed.Get().Get()) {
g_base_sync_primitives_disallowed.Get().Set(false);
}
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope::
~ScopedAllowBaseSyncPrimitivesOutsideBlockingScope() {
DCHECK(!g_base_sync_primitives_disallowed.Get().Get());
g_base_sync_primitives_disallowed.Get().Set(was_disallowed_);
}
ScopedAllowBaseSyncPrimitivesForTesting:: ScopedAllowBaseSyncPrimitivesForTesting::
ScopedAllowBaseSyncPrimitivesForTesting() ScopedAllowBaseSyncPrimitivesForTesting()
: was_disallowed_(g_base_sync_primitives_disallowed.Get().Get()) { : was_disallowed_(g_base_sync_primitives_disallowed.Get().Get()) {
...@@ -208,13 +188,6 @@ void DisallowUnresponsiveTasks() { ...@@ -208,13 +188,6 @@ void DisallowUnresponsiveTasks() {
g_cpu_intensive_work_disallowed.Get().Set(true); g_cpu_intensive_work_disallowed.Get().Set(true);
} }
ThreadRestrictions::ScopedAllowIO::ScopedAllowIO()
: was_allowed_(SetIOAllowed(true)) {}
ThreadRestrictions::ScopedAllowIO::~ScopedAllowIO() {
SetIOAllowed(was_allowed_);
}
// static // static
bool ThreadRestrictions::SetIOAllowed(bool allowed) { bool ThreadRestrictions::SetIOAllowed(bool allowed) {
bool previous_disallowed = g_blocking_disallowed.Get().Get(); bool previous_disallowed = g_blocking_disallowed.Get().Get();
...@@ -256,3 +229,73 @@ bool ThreadRestrictions::SetWaitAllowed(bool allowed) { ...@@ -256,3 +229,73 @@ bool ThreadRestrictions::SetWaitAllowed(bool allowed) {
} // namespace base } // namespace base
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
namespace base {
ScopedAllowBlocking::ScopedAllowBlocking(const Location& from_here)
#if DCHECK_IS_ON()
: was_disallowed_(g_blocking_disallowed.Get().Get())
#endif
{
TRACE_EVENT_BEGIN2("base", "ScopedAllowBlocking", "file_name",
from_here.file_name(), "function_name",
from_here.function_name());
#if DCHECK_IS_ON()
g_blocking_disallowed.Get().Set(false);
#endif
}
ScopedAllowBlocking::~ScopedAllowBlocking() {
TRACE_EVENT_END0("base", "ScopedAllowBlocking");
#if DCHECK_IS_ON()
DCHECK(!g_blocking_disallowed.Get().Get());
g_blocking_disallowed.Get().Set(was_disallowed_);
#endif
}
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope::
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope(const Location& from_here)
#if DCHECK_IS_ON()
: was_disallowed_(g_base_sync_primitives_disallowed.Get().Get())
#endif
{
TRACE_EVENT_BEGIN2(
"base", "ScopedAllowBaseSyncPrimitivesOutsideBlockingScope", "file_name",
from_here.file_name(), "function_name", from_here.function_name());
#if DCHECK_IS_ON()
g_base_sync_primitives_disallowed.Get().Set(false);
#endif
}
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope::
~ScopedAllowBaseSyncPrimitivesOutsideBlockingScope() {
TRACE_EVENT_END0("base", "ScopedAllowBaseSyncPrimitivesOutsideBlockingScope");
#if DCHECK_IS_ON()
DCHECK(!g_base_sync_primitives_disallowed.Get().Get());
g_base_sync_primitives_disallowed.Get().Set(was_disallowed_);
#endif
}
ThreadRestrictions::ScopedAllowIO::ScopedAllowIO(const Location& from_here)
#if DCHECK_IS_ON()
: was_allowed_(SetIOAllowed(true))
#endif
{
TRACE_EVENT_BEGIN2("base", "ScopedAllowIO", "file_name",
from_here.file_name(), "function_name",
from_here.function_name());
}
ThreadRestrictions::ScopedAllowIO::~ScopedAllowIO() {
TRACE_EVENT_END0("base", "ScopedAllowIO");
#if DCHECK_IS_ON()
SetIOAllowed(was_allowed_);
#endif
}
} // namespace base
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -375,8 +376,8 @@ class BASE_EXPORT ScopedAllowBlocking { ...@@ -375,8 +376,8 @@ class BASE_EXPORT ScopedAllowBlocking {
friend class content::RenderProcessHostImpl; friend class content::RenderProcessHostImpl;
friend class weblayer::WebLayerPathProvider; friend class weblayer::WebLayerPathProvider;
ScopedAllowBlocking() EMPTY_BODY_IF_DCHECK_IS_OFF; ScopedAllowBlocking(const Location& from_here = Location::Current());
~ScopedAllowBlocking() EMPTY_BODY_IF_DCHECK_IS_OFF; ~ScopedAllowBlocking();
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
const bool was_disallowed_; const bool was_disallowed_;
...@@ -527,10 +528,10 @@ class BASE_EXPORT ScopedAllowBaseSyncPrimitivesOutsideBlockingScope { ...@@ -527,10 +528,10 @@ class BASE_EXPORT ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {
friend class service_manager::ServiceProcessLauncher; friend class service_manager::ServiceProcessLauncher;
friend class ui::WindowResizeHelperMac; // http://crbug.com/902829 friend class ui::WindowResizeHelperMac; // http://crbug.com/902829
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope() ScopedAllowBaseSyncPrimitivesOutsideBlockingScope(
EMPTY_BODY_IF_DCHECK_IS_OFF; const Location& from_here = Location::Current());
~ScopedAllowBaseSyncPrimitivesOutsideBlockingScope()
EMPTY_BODY_IF_DCHECK_IS_OFF; ~ScopedAllowBaseSyncPrimitivesOutsideBlockingScope();
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
const bool was_disallowed_; const bool was_disallowed_;
...@@ -597,8 +598,8 @@ class BASE_EXPORT ThreadRestrictions { ...@@ -597,8 +598,8 @@ class BASE_EXPORT ThreadRestrictions {
// DEPRECATED. Use ScopedAllowBlocking(ForTesting). // DEPRECATED. Use ScopedAllowBlocking(ForTesting).
class BASE_EXPORT ScopedAllowIO { class BASE_EXPORT ScopedAllowIO {
public: public:
ScopedAllowIO() EMPTY_BODY_IF_DCHECK_IS_OFF; ScopedAllowIO(const Location& from_here = Location::Current());
~ScopedAllowIO() EMPTY_BODY_IF_DCHECK_IS_OFF; ~ScopedAllowIO();
private: private:
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
......
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