Commit ccf2bd29 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

tab-switching: Report some additional latency times.

When switching tabs, report the time it takes for the browser to send
the request to the renderer to become visible.

BUG=858944

Change-Id: Id11569162c433a66f61a4fd8dc8ef8c8b2f70327
Reviewed-on: https://chromium-review.googlesource.com/1136217Reviewed-by: default avatarRobert Kaplow (slow) <rkaplow@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575025}
parent 04f2f559
......@@ -29,6 +29,9 @@
#include "components/feature_engagement/buildflags.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_observer.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -59,6 +62,49 @@ bool ShouldForgetOpenersForTransition(ui::PageTransition transition) {
ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
}
// This tracks (and reports via UMA and tracing) how long it takes before a
// RenderWidgetHost is requested to become visible.
class RenderWidgetHostVisibilityTracker
: public content::RenderWidgetHostObserver {
public:
explicit RenderWidgetHostVisibilityTracker(content::RenderWidgetHost* host)
: host_(host) {
if (!host_ || host_->GetView()->IsShowing())
return;
host_->AddObserver(this);
TRACE_EVENT_ASYNC_BEGIN0("ui,latency", "TabSwitchVisibilityRequest", this);
}
~RenderWidgetHostVisibilityTracker() override {
if (host_)
host_->RemoveObserver(this);
}
private:
// content::RenderWidgetHostObserver:
void RenderWidgetHostVisibilityChanged(content::RenderWidgetHost* host,
bool became_visible) override {
DCHECK_EQ(host_, host);
DCHECK(became_visible);
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Browser.Tabs.SelectionToVisibilityRequestTime", timer_.Elapsed(),
base::TimeDelta::FromMicroseconds(1), base::TimeDelta::FromSeconds(3),
50);
TRACE_EVENT_ASYNC_END0("ui,latency", "TabSwitchVisibilityRequest", this);
}
void RenderWidgetHostDestroyed(content::RenderWidgetHost* host) override {
DCHECK_EQ(host_, host);
host_->RemoveObserver(this);
host_ = nullptr;
}
content::RenderWidgetHost* host_ = nullptr;
base::ElapsedTimer timer_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityTracker);
};
} // namespace
///////////////////////////////////////////////////////////////////////////////
......@@ -1397,6 +1443,13 @@ void TabStripModel::NotifyIfActiveTabChanged(WebContents* old_contents,
if (old_contents == new_contents)
return;
content::RenderWidgetHost* track_host = nullptr;
if (notify_types == Notify::kUserGesture &&
new_contents->GetRenderWidgetHostView()) {
track_host = new_contents->GetRenderWidgetHostView()->GetRenderWidgetHost();
}
RenderWidgetHostVisibilityTracker tracker(track_host);
int reason = notify_types == Notify::kUserGesture
? TabStripModelObserver::CHANGE_REASON_USER_GESTURE
: TabStripModelObserver::CHANGE_REASON_NONE;
......
......@@ -9950,6 +9950,20 @@ uploading your change for review.
<summary>Maximal amount of memory allocated by decoder.</summary>
</histogram>
<histogram name="Browser.Tabs.SelectionToVisibilityRequestTime"
units="microseconds">
<owner>sadrul@chromium.org</owner>
<owner>sky@chromium.org</owner>
<summary>
The time it takes for the browser to request a tab to be visible. Note that
this only measures the time from the browser deciding to make the tab
visible (after a click, or keyboard-shortcut to switch tabs), until the tab
is requested to become visible. The time it takes to actually make the tab
visible and show on screen is measured in a separate metric, in
RWH_TabSwitchPaintDuration.
</summary>
</histogram>
<histogram name="BrowserActions.NumTabCreatedInBackground" units="tabNum">
<owner>ltian@chromium.org</owner>
<summary>
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