Commit 6e4c9be1 authored by Yichen Zhou's avatar Yichen Zhou Committed by Commit Bot

ash: Record latency for tab dragging in clamshell

Add histograms for tab dragging in clamshell mode.

Bug: 1032766
Change-Id: I33b9a39598ff06aa2c343a86e5e2effa79523d46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2199501
Commit-Queue: Yichen Zhou <yichenz@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769943}
parent 1871d676
...@@ -75,6 +75,15 @@ constexpr int kMinOnscreenSize = 20; ...@@ -75,6 +75,15 @@ constexpr int kMinOnscreenSize = 20;
// snapped window before the window restores. // snapped window before the window restores.
constexpr int kResizeRestoreDragThresholdDp = 5; constexpr int kResizeRestoreDragThresholdDp = 5;
// The UMA histogram that records presentation time for tab dragging between
// windows in clamshell mode.
constexpr char kTabDraggingInClamshellModeHistogram[] =
"Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.ClamshellMode";
constexpr char kTabDraggingInClamshellModeMaxLatencyHistogram[] =
"Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.MaxLatency."
"ClamshellMode";
// Current instance for use by the WorkspaceWindowResizerTest. // Current instance for use by the WorkspaceWindowResizerTest.
WorkspaceWindowResizer* instance = nullptr; WorkspaceWindowResizer* instance = nullptr;
...@@ -548,6 +557,20 @@ void WorkspaceWindowResizer::Drag(const gfx::PointF& location_in_parent, ...@@ -548,6 +557,20 @@ void WorkspaceWindowResizer::Drag(const gfx::PointF& location_in_parent,
SnapType::kMaximize; SnapType::kMaximize;
} }
UpdateSnapPhantomWindow(location_in_screen, bounds); UpdateSnapPhantomWindow(location_in_screen, bounds);
if (tab_dragging_recorder_) {
// The recorder only works with a single ui::Compositor. ui::Compositor is
// per display so the recorder does not work correctly across different
// displays. Thus, we give up tab dragging latency data collection if the
// drag touches a different display, i.e. not inside the current parent's
// bounds.
if (!gfx::Rect(GetTarget()->parent()->bounds().size())
.Contains(gfx::ToRoundedPoint(location_in_parent))) {
tab_dragging_recorder_.reset();
return;
}
tab_dragging_recorder_->RequestNext();
}
} }
void WorkspaceWindowResizer::CompleteDrag() { void WorkspaceWindowResizer::CompleteDrag() {
...@@ -618,10 +641,10 @@ void WorkspaceWindowResizer::CompleteDrag() { ...@@ -618,10 +641,10 @@ void WorkspaceWindowResizer::CompleteDrag() {
return; return;
} }
// Keep the window snapped if the user resizes the window such that the // Keep the window snapped if the user resizes the window such that the
// window has valid bounds for a snapped window. Always unsnap the window // window has valid bounds for a snapped window. Always unsnap the window
// if the user dragged the window via the caption area because doing this // if the user dragged the window via the caption area because doing this
// is slightly less confusing. // is slightly less confusing.
if (window_state()->IsSnapped()) { if (window_state()->IsSnapped()) {
if (details().window_component == HTCAPTION || if (details().window_component == HTCAPTION ||
!AreBoundsValidSnappedBounds(window_state()->GetStateType(), !AreBoundsValidSnappedBounds(window_state()->GetStateType(),
...@@ -788,6 +811,13 @@ WorkspaceWindowResizer::WorkspaceWindowResizer( ...@@ -788,6 +811,13 @@ WorkspaceWindowResizer::WorkspaceWindowResizer(
window_state->OnDragStarted(details().window_component); window_state->OnDragStarted(details().window_component);
StartDragForAttachedWindows(); StartDragForAttachedWindows();
if (window_util::IsDraggingTabs(window_state->window())) {
tab_dragging_recorder_ = CreatePresentationTimeHistogramRecorder(
GetTarget()->layer()->GetCompositor(),
kTabDraggingInClamshellModeHistogram,
kTabDraggingInClamshellModeMaxLatencyHistogram);
}
} }
void WorkspaceWindowResizer::LayoutAttachedWindows(gfx::Rect* bounds) { void WorkspaceWindowResizer::LayoutAttachedWindows(gfx::Rect* bounds) {
......
...@@ -217,6 +217,9 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { ...@@ -217,6 +217,9 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
// be set to the bounds of the window when the drag was started. // be set to the bounds of the window when the drag was started.
gfx::Rect pre_drag_window_bounds_; gfx::Rect pre_drag_window_bounds_;
// Presentation time recorder for tab dragging in clamshell mode.
std::unique_ptr<PresentationTimeRecorder> tab_dragging_recorder_;
// Used to determine if this has been deleted during a drag such as when a tab // Used to determine if this has been deleted during a drag such as when a tab
// gets dragged into another browser window. // gets dragged into another browser window.
base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_{this}; base::WeakPtrFactory<WorkspaceWindowResizer> weak_ptr_factory_{this};
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/wm/workspace/workspace_window_resizer.h" #include "ash/wm/workspace/workspace_window_resizer.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
...@@ -2088,4 +2089,52 @@ TEST_F(MultiDisplayWorkspaceWindowResizerTest, Magnetism) { ...@@ -2088,4 +2089,52 @@ TEST_F(MultiDisplayWorkspaceWindowResizerTest, Magnetism) {
EXPECT_EQ(gfx::Rect(1150, 10, 100, 100), win1->GetBoundsInScreen()); EXPECT_EQ(gfx::Rect(1150, 10, 100, 100), win1->GetBoundsInScreen());
} }
// Make sure metrics is recorded during tab dragging.
TEST_F(WorkspaceWindowResizerTest, TabDraggingHistogram) {
UpdateDisplay("800x600,800x600");
ASSERT_EQ(2, display::Screen::GetScreen()->GetNumDisplays());
struct {
bool is_dragging_tab;
gfx::PointF drag_to_point;
int expected_latency_count;
int expected_max_latency_count;
} kTestCases[] = {// A tab dragging should generate a histogram.
{/*is_dragging_tab*/ true, gfx::PointF(200, 200), 1, 1},
// A window dragging should not generate a histogram.
{/*is_dragging_tab*/ false, gfx::PointF(200, 200), 0, 0},
// A tab dragging should not generate a histogram when
// the drag touches a different display.
{/*is_dragging_tab*/ true, gfx::PointF(850, 200), 0, 0}};
for (const auto& test : kTestCases) {
SCOPED_TRACE(testing::Message()
<< "is_dragging_tab=" << test.is_dragging_tab);
base::HistogramTester histogram_tester;
window_->SetBounds(gfx::Rect(100, 100, 100, 100));
window_->SetProperty(ash::kIsDraggingTabsKey, test.is_dragging_tab);
std::unique_ptr<WindowResizer> resizer =
CreateWindowResizer(window_.get(), gfx::PointF(), HTCAPTION,
::wm::WINDOW_MOVE_SOURCE_MOUSE);
ASSERT_TRUE(resizer.get());
resizer->Drag(test.drag_to_point, 0);
EXPECT_TRUE(
ui::WaitForNextFrameToBePresented(window_->GetHost()->compositor()));
resizer->CompleteDrag();
resizer.reset(nullptr);
histogram_tester.ExpectTotalCount(
"Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.ClamshellMode",
test.expected_latency_count);
histogram_tester.ExpectTotalCount(
"Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.MaxLatency."
"ClamshellMode",
test.expected_max_latency_count);
}
}
} // namespace ash } // namespace ash
...@@ -10927,6 +10927,28 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -10927,6 +10927,28 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram
name="Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.ClamshellMode"
units="ms" expires_after="2021-02-03">
<owner>yichenz@chromium.org</owner>
<owner>chromeos-wmp@google.com</owner>
<summary>
Presentation time in ms when a tab is dragged in clamshell mode. Each time
the tab is dragged within a display, the time it takes to present the new
frame on screen is recorded.
</summary>
</histogram>
<histogram
name="Ash.WorkspaceWindowResizer.TabDragging.PresentationTime.MaxLatency.ClamshellMode"
units="ms" expires_after="2021-02-03">
<owner>yichenz@chromium.org</owner>
<owner>chromeos-wmp@google.com</owner>
<summary>
Maximum presentation time recorded during the tab dragging session.
</summary>
</histogram>
<histogram name="Assistant.ButtonClickCount" enum="AssistantButtonId" <histogram name="Assistant.ButtonClickCount" enum="AssistantButtonId"
expires_after="2020-10-25"> expires_after="2020-10-25">
<owner>xiaohuic@chromium.org</owner> <owner>xiaohuic@chromium.org</owner>
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