Commit 47ab064e authored by Joao Victor Almeida's avatar Joao Victor Almeida Committed by Commit Bot

Split AddLatencyInFrame into 2 methods.

AverageLagTracker::AddLatencyInFrame is already logically splited
(most part of its body is inside an if/else body) into 2 cases:
ScrollBegin and ScrollUpdate. This CL aims to create a method
for each case so AddLatencyInFrame is leaner and simpler to read.

Also, as this class in being refactored at
https://chromium-review.googlesource.com/c/chromium/src/+/2189633
this simple refactor will reduce the amount of noise created by
CL #2189633.


Bug: 1079024, 1079028
Change-Id: I7c9d2567ac3a875ca4c03b33d77a7a169bbb6375
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216707Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: default avatarDaniel Libby <dlibby@microsoft.com>
Commit-Queue: João Victor Almeida de Aguiar <joalmei@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#774708}
parent 16d7a33f
......@@ -26,78 +26,10 @@ void AverageLagTracker::AddLatencyInFrame(
return;
if (scroll_name == "ScrollBegin") {
// Flush all unfinished frames.
while (!frame_lag_infos_.empty()) {
frame_lag_infos_.front().lag_area += LagForUnfinishedFrame(
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagForUnfinishedFrame(
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
// Record UMA when it's the last item in queue.
CalculateAndReportAverageLagUma(frame_lag_infos_.size() == 1);
}
// |accumulated_lag_| should be cleared/reset.
DCHECK(accumulated_lag_ == 0);
// Create ScrollBegin report, with report time equals to gpu swap time.
LagAreaInFrame first_frame(gpu_swap_begin_timestamp);
frame_lag_infos_.push_back(first_frame);
// Reset fields.
last_reported_time_ = event_timestamp;
last_finished_frame_time_ = event_timestamp;
last_event_accumulated_delta_ = 0;
last_rendered_accumulated_delta_ = 0;
is_begin_ = true;
AddScrollBeginInFrame(gpu_swap_begin_timestamp, event_timestamp);
} else if (scroll_name == "ScrollUpdate" &&
!last_event_timestamp_.is_null()) {
// Only accept events in nondecreasing order.
if ((event_timestamp - last_event_timestamp_).InMilliseconds() < 0)
return;
// Pop all frames where frame_time <= event_timestamp.
while (!frame_lag_infos_.empty() &&
frame_lag_infos_.front().frame_time <= event_timestamp) {
base::TimeTicks front_time =
std::max(last_event_timestamp_, last_finished_frame_time_);
base::TimeTicks back_time = frame_lag_infos_.front().frame_time;
frame_lag_infos_.front().lag_area +=
LagBetween(front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagBetween(
front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
CalculateAndReportAverageLagUma();
}
// Initialize a new LagAreaInFrame when current_frame_time > frame_time.
if (frame_lag_infos_.empty() ||
gpu_swap_begin_timestamp > frame_lag_infos_.back().frame_time) {
LagAreaInFrame new_frame(gpu_swap_begin_timestamp,
last_rendered_accumulated_delta_,
last_event_accumulated_delta_);
frame_lag_infos_.push_back(new_frame);
}
// last_frame_time <= event_timestamp < frame_time
if (!frame_lag_infos_.empty()) {
// The front element in queue (if any) must satisfy frame_time >
// event_timestamp, otherwise it would be popped in the while loop.
DCHECK(last_finished_frame_time_ <= event_timestamp &&
event_timestamp <= frame_lag_infos_.front().frame_time);
base::TimeTicks front_time =
std::max(last_finished_frame_time_, last_event_timestamp_);
base::TimeTicks back_time = event_timestamp;
frame_lag_infos_.front().lag_area +=
LagBetween(front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagBetween(
front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
}
AddScrollUpdateInFrame(latency, gpu_swap_begin_timestamp, event_timestamp);
}
last_event_timestamp_ = event_timestamp;
......@@ -105,6 +37,87 @@ void AverageLagTracker::AddLatencyInFrame(
last_rendered_accumulated_delta_ += latency.predicted_scroll_update_delta();
}
void AverageLagTracker::AddScrollBeginInFrame(
base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks event_timestamp) {
// Flush all unfinished frames.
while (!frame_lag_infos_.empty()) {
frame_lag_infos_.front().lag_area += LagForUnfinishedFrame(
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagForUnfinishedFrame(
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
// Record UMA when it's the last item in queue.
CalculateAndReportAverageLagUma(frame_lag_infos_.size() == 1);
}
// |accumulated_lag_| should be cleared/reset.
DCHECK(accumulated_lag_ == 0);
// Create ScrollBegin report, with report time equals to gpu swap time.
LagAreaInFrame first_frame(gpu_swap_begin_timestamp);
frame_lag_infos_.push_back(first_frame);
// Reset fields.
last_reported_time_ = event_timestamp;
last_finished_frame_time_ = event_timestamp;
last_event_accumulated_delta_ = 0;
last_rendered_accumulated_delta_ = 0;
is_begin_ = true;
}
void AverageLagTracker::AddScrollUpdateInFrame(
const LatencyInfo& latency,
base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks event_timestamp) {
// Only accept events in nondecreasing order.
if ((event_timestamp - last_event_timestamp_).InMilliseconds() < 0)
return;
// Pop all frames where frame_time <= event_timestamp.
while (!frame_lag_infos_.empty() &&
frame_lag_infos_.front().frame_time <= event_timestamp) {
base::TimeTicks front_time =
std::max(last_event_timestamp_, last_finished_frame_time_);
base::TimeTicks back_time = frame_lag_infos_.front().frame_time;
frame_lag_infos_.front().lag_area +=
LagBetween(front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagBetween(
front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
CalculateAndReportAverageLagUma();
}
// Initialize a new LagAreaInFrame when current_frame_time > frame_time.
if (frame_lag_infos_.empty() ||
gpu_swap_begin_timestamp > frame_lag_infos_.back().frame_time) {
LagAreaInFrame new_frame(gpu_swap_begin_timestamp,
last_rendered_accumulated_delta_,
last_event_accumulated_delta_);
frame_lag_infos_.push_back(new_frame);
}
// last_frame_time <= event_timestamp < frame_time
if (!frame_lag_infos_.empty()) {
// The front element in queue (if any) must satisfy frame_time >
// event_timestamp, otherwise it would be popped in the while loop.
DCHECK(last_finished_frame_time_ <= event_timestamp &&
event_timestamp <= frame_lag_infos_.front().frame_time);
base::TimeTicks front_time =
std::max(last_finished_frame_time_, last_event_timestamp_);
base::TimeTicks back_time = event_timestamp;
frame_lag_infos_.front().lag_area +=
LagBetween(front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta);
frame_lag_infos_.front().lag_area_no_prediction += LagBetween(
front_time, back_time, latency, event_timestamp,
frame_lag_infos_.front().rendered_accumulated_delta_no_prediction);
}
}
float AverageLagTracker::LagBetween(base::TimeTicks front_time,
base::TimeTicks back_time,
const LatencyInfo& latency,
......
......@@ -50,6 +50,12 @@ class AverageLagTracker {
float lag_area_no_prediction;
} LagAreaInFrame;
void AddScrollBeginInFrame(base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks event_timestamp);
void AddScrollUpdateInFrame(const LatencyInfo& latency,
base::TimeTicks gpu_swap_begin_timestamp,
base::TimeTicks event_timestamp);
// Calculate lag in 1 seconds intervals and report UMA.
void CalculateAndReportAverageLagUma(bool send_anyway = false);
......
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