forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_to_first_present_recorder.cc
66 lines (52 loc) · 1.99 KB
/
time_to_first_present_recorder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/metrics/time_to_first_present_recorder.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/presentation_feedback.h"
namespace ash {
TimeToFirstPresentRecorder::TimeToFirstPresentRecorder(aura::Window* window) {
aura::WindowTreeHost* window_tree_host = window->GetHost();
DCHECK(window_tree_host);
window_tree_host->compositor()->RequestPresentationTimeForNextFrame(
base::BindOnce(&TimeToFirstPresentRecorder::DidPresentCompositorFrame,
base::Unretained(this)));
}
TimeToFirstPresentRecorder::~TimeToFirstPresentRecorder() = default;
void TimeToFirstPresentRecorder::Bind(
mojom::ProcessCreationTimeRecorderRequest request) {
// Process createion time should only be set once.
if (binding_.is_bound() || !process_creation_time_.is_null())
return;
binding_.Bind(std::move(request));
}
void TimeToFirstPresentRecorder::SetMainProcessCreationTime(
base::TimeTicks start_time) {
if (!process_creation_time_.is_null())
return;
process_creation_time_ = start_time;
LogTime();
// Process creation time should be set only once.
binding_.Close();
}
void TimeToFirstPresentRecorder::LogTime() {
if (present_time_.is_null() || process_creation_time_.is_null())
return;
UMA_HISTOGRAM_TIMES("Ash.ProcessCreationToFirstPresent",
time_to_first_present());
if (log_callback_)
std::move(log_callback_).Run();
}
void TimeToFirstPresentRecorder::DidPresentCompositorFrame(
const gfx::PresentationFeedback& feedback) {
DCHECK(present_time_.is_null()); // This should only be called once.
present_time_ = feedback.timestamp;
LogTime();
}
} // namespace ash