GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / debug / frame_timing_tracker.cc
blob50aa92be5aabed16abef231f50ba5509e8bd9842
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/debug/frame_timing_tracker.h"
7 #include <algorithm>
8 #include <limits>
10 #include "base/metrics/histogram.h"
11 #include "cc/trees/proxy.h"
13 namespace cc {
15 FrameTimingTracker::CompositeTimingEvent::CompositeTimingEvent(
16 int _frame_id,
17 base::TimeTicks _timestamp)
18 : frame_id(_frame_id), timestamp(_timestamp) {
21 FrameTimingTracker::CompositeTimingEvent::~CompositeTimingEvent() {
24 FrameTimingTracker::MainFrameTimingEvent::MainFrameTimingEvent(
25 int frame_id,
26 base::TimeTicks timestamp,
27 base::TimeTicks end_time)
28 : frame_id(frame_id), timestamp(timestamp), end_time(end_time) {
31 FrameTimingTracker::MainFrameTimingEvent::~MainFrameTimingEvent() {
34 // static
35 scoped_ptr<FrameTimingTracker> FrameTimingTracker::Create() {
36 return make_scoped_ptr(new FrameTimingTracker);
39 FrameTimingTracker::FrameTimingTracker() {
42 FrameTimingTracker::~FrameTimingTracker() {
45 void FrameTimingTracker::SaveTimeStamps(
46 base::TimeTicks timestamp,
47 const std::vector<FrameAndRectIds>& frame_ids) {
48 if (!composite_events_)
49 composite_events_.reset(new CompositeTimingSet);
50 for (const auto& pair : frame_ids) {
51 (*composite_events_)[pair.second].push_back(
52 CompositeTimingEvent(pair.first, timestamp));
56 void FrameTimingTracker::SaveMainFrameTimeStamps(
57 const std::vector<int64_t>& request_ids,
58 base::TimeTicks main_frame_time,
59 base::TimeTicks end_time,
60 int source_frame_number) {
61 if (!main_frame_events_)
62 main_frame_events_.reset(new MainFrameTimingSet);
63 for (const auto& request : request_ids) {
64 std::vector<MainFrameTimingEvent>& events = (*main_frame_events_)[request];
65 events.push_back(
66 MainFrameTimingEvent(source_frame_number, main_frame_time, end_time));
70 scoped_ptr<FrameTimingTracker::CompositeTimingSet>
71 FrameTimingTracker::GroupCompositeCountsByRectId() {
72 if (!composite_events_)
73 return make_scoped_ptr(new CompositeTimingSet);
74 for (auto& infos : *composite_events_) {
75 std::sort(
76 infos.second.begin(), infos.second.end(),
77 [](const CompositeTimingEvent& lhs, const CompositeTimingEvent& rhs) {
78 return lhs.timestamp < rhs.timestamp;
79 });
81 return composite_events_.Pass();
84 scoped_ptr<FrameTimingTracker::MainFrameTimingSet>
85 FrameTimingTracker::GroupMainFrameCountsByRectId() {
86 if (!main_frame_events_)
87 return make_scoped_ptr(new MainFrameTimingSet);
88 for (auto& infos : *main_frame_events_) {
89 std::sort(
90 infos.second.begin(), infos.second.end(),
91 [](const MainFrameTimingEvent& lhs, const MainFrameTimingEvent& rhs) {
92 return lhs.timestamp < rhs.timestamp;
93 });
95 return main_frame_events_.Pass();
98 } // namespace cc