Commit 8464ef03 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Activate tracing categories early for slow-reports

This CL is making sure tracing categories are
activated as soon as the request for start tracing
is done. Background tracing (Slow-reports) is
sending a request to TraceLog which delegate it
to the tracing service. Starting tracing is not
synchronous. The categories are activated after
the tracing is started.

This CL is manually turning on the categories by
calling SetEnabled on TraceLog.

A manual trigger for session is added. This trigger
is reactive which means tracing won't be activated
on a normal usage of chrome. It will only be
activated during session restore (depending on the
background tracing configuration).


R=chrisha@chromium.org, oysteine@chromium.org

This CL can locally be tested with:

  out\build\chrome.exe --enable-background-tracing=c:\src\chromium\tracing-config.json --trace-upload-url=http://localhost:8080

==== trace-config.json ====
{
  "scenario_name": "Browser",
  "mode": "REACTIVE_TRACING_MODE",
  "configs": [
    {
      "rule": "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL",
      "trigger_name": "session-restore-config",
      "category": "BENCHMARK_NAVIGATION",
      "trigger_delay": 5
    }
  ]
}


Change-Id: Ic9131440db98d260e1979f6cc7dc94cfc1a9c4fb
Reviewed-on: https://chromium-review.googlesource.com/c/1334548
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609345}
parent cb318362
......@@ -18,6 +18,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "components/favicon/content/content_favicon_driver.h"
#include "content/public/browser/background_tracing_manager.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
......@@ -27,6 +28,18 @@ using resource_coordinator::TabLoadTracker;
namespace {
void BackgroundTracingTrigger() {
static content::BackgroundTracingManager::TriggerHandle trigger_handle_ = -1;
if (trigger_handle_ == -1) {
trigger_handle_ =
content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
"session-restore-config");
}
content::BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
trigger_handle_,
content::BackgroundTracingManager::StartedFinalizingCallback());
}
const base::TickClock* GetDefaultTickClock() {
static base::NoDestructor<base::DefaultTickClock> default_tick_clock;
return default_tick_clock.get();
......@@ -80,6 +93,10 @@ void TabLoader::RestoreTabs(const std::vector<RestoredTab>& tabs,
if (tabs.empty())
return;
// Trigger a slow-reports and collect a session restore trace if needed.
BackgroundTracingTrigger();
TRACE_EVENT0("browser", "TabLoader::RestoreTabs");
if (!shared_tab_loader_)
shared_tab_loader_ = new TabLoader(restore_started);
......@@ -172,6 +189,7 @@ void TabLoader::SetTabLoadingEnabled(bool loading_enabled) {
void TabLoader::StartLoading(const std::vector<RestoredTab>& tabs) {
DCHECK(!tabs.empty());
ReentrancyHelper lifetime_helper(this);
TRACE_EVENT1("browser", "TabLoader::StartLoading", "tabs_count", tabs.size());
// Create a TabLoaderDelegate which will allow OS specific behavior for tab
// loading. This needs to be done before any calls to AddTab, as the delegate
......@@ -221,6 +239,7 @@ void TabLoader::OnLoadingStateChange(WebContents* contents,
LoadingState old_loading_state,
LoadingState new_loading_state) {
ReentrancyHelper lifetime_helper(this);
TRACE_EVENT0("browser", "TabLoader::OnLoadingStateChange");
// Calls into this can come from observers that are still running even if
// |is_loading_enabled_| is false.
......@@ -263,6 +282,8 @@ void TabLoader::OnStopTracking(WebContents* web_contents,
void TabLoader::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
ReentrancyHelper lifetime_helper(this);
TRACE_EVENT0("browser", "TabLoader::OnMemoryPressure");
switch (memory_pressure_level) {
case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
break;
......@@ -362,6 +383,7 @@ void TabLoader::RemoveTab(WebContents* contents) {
void TabLoader::MarkTabAsLoadInitiated(WebContents* contents) {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
TRACE_EVENT0("browser", "TabLoader::MarkTabAsLoadInitiated");
// This can only be called for a tab that is waiting to be loaded so this
// should never fail.
......@@ -379,6 +401,7 @@ void TabLoader::MarkTabAsLoadInitiated(WebContents* contents) {
void TabLoader::MarkTabAsLoading(WebContents* contents) {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
TRACE_EVENT0("browser", "TabLoader::MarkTabAsLoading");
// Calls into this can come from observers that are still running even if
// |is_loading_enabled_| is false.
......@@ -413,6 +436,7 @@ void TabLoader::MarkTabAsLoading(WebContents* contents) {
void TabLoader::MarkTabAsDeferred(content::WebContents* contents) {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
TRACE_EVENT0("browser", "TabLoader::MarkTabAsDeferred");
// This can only be called for a tab that is waiting to be loaded so this
// should never fail.
......@@ -424,6 +448,7 @@ void TabLoader::MarkTabAsDeferred(content::WebContents* contents) {
void TabLoader::MaybeLoadSomeTabs() {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
TRACE_EVENT0("browser", "TabLoader::MaybeLoadSomeTabs");
if (!is_loading_enabled_ || tabs_to_load_.empty())
return;
......@@ -437,6 +462,7 @@ void TabLoader::MaybeLoadSomeTabs() {
void TabLoader::ForceLoadTimerFired() {
ReentrancyHelper lifetime_helper(this);
TRACE_EVENT0("browser", "TabLoader::ForceLoadTimerFired");
// CheckInvariants can't be called directly as the timer is no longer
// running at this point. However, the conditions under which the timer
......@@ -468,6 +494,7 @@ void TabLoader::ForceLoadTimerFired() {
void TabLoader::StopLoadingTabs() {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
TRACE_EVENT0("browser", "TabLoader::StopLoadingTabs");
// Calls into this can come from observers that are still running even if
// |is_loading_enabled_| is false.
......@@ -508,6 +535,7 @@ content::WebContents* TabLoader::GetNextTabToLoad() {
void TabLoader::LoadNextTab(bool due_to_timeout) {
DCHECK(reentry_depth_ > 0); // This can only be called internally.
DCHECK(!tabs_to_load_.empty());
TRACE_EVENT0("browser", "TabLoader::LoadNextTab");
// This is checked before loading every single tab to ensure that responses
// to memory pressure are immediate.
......
......@@ -394,8 +394,10 @@ IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
wait_for_tracing.Run();
}
{
TRACE_EVENT1("benchmark", "whitelisted", "find_this", 1);
TRACE_EVENT1("benchmark", "not_whitelisted", "this_not_found", 1);
}
BackgroundTracingManager::GetInstance()->WhenIdle(
base::Bind(&DisableScenarioWhenIdle));
......
......@@ -513,6 +513,18 @@ void BackgroundTracingManagerImpl::StartTracing(
is_tracing_ = TracingControllerImpl::GetInstance()->StartTracing(
config, base::BindOnce(&BackgroundTracingManagerImpl::OnStartTracingDone,
base::Unretained(this), preset));
// Activate the categories immediately. StartTracing eventually does this
// itself, but asynchronously via PostTask, and in the meantime events will be
// dropped. This ensures that we start recording events for those categories
// immediately.
if (is_tracing_) {
uint8_t modes = base::trace_event::TraceLog::RECORDING_MODE;
if (!config.event_filters().empty())
modes |= base::trace_event::TraceLog::FILTERING_MODE;
base::trace_event::TraceLog::GetInstance()->SetEnabled(config, modes);
}
RecordBackgroundTracingMetric(RECORDING_ENABLED);
}
......
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