| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/debug/frame_timing_tracker.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <limits> | |
| 11 | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "base/metrics/histogram.h" | |
| 14 #include "cc/trees/layer_tree_host_impl.h" | |
| 15 #include "cc/trees/proxy.h" | |
| 16 | |
| 17 namespace cc { | |
| 18 namespace { | |
| 19 int kSendTimingIntervalMS = 200; | |
| 20 } | |
| 21 | |
| 22 FrameTimingTracker::CompositeTimingEvent::CompositeTimingEvent( | |
| 23 int _frame_id, | |
| 24 base::TimeTicks _timestamp) | |
| 25 : frame_id(_frame_id), timestamp(_timestamp) { | |
| 26 } | |
| 27 | |
| 28 FrameTimingTracker::CompositeTimingEvent::~CompositeTimingEvent() { | |
| 29 } | |
| 30 | |
| 31 FrameTimingTracker::MainFrameTimingEvent::MainFrameTimingEvent( | |
| 32 int frame_id, | |
| 33 base::TimeTicks timestamp, | |
| 34 base::TimeTicks end_time) | |
| 35 : frame_id(frame_id), timestamp(timestamp), end_time(end_time) { | |
| 36 } | |
| 37 | |
| 38 FrameTimingTracker::MainFrameTimingEvent::~MainFrameTimingEvent() { | |
| 39 } | |
| 40 | |
| 41 // static | |
| 42 std::unique_ptr<FrameTimingTracker> FrameTimingTracker::Create( | |
| 43 LayerTreeHostImpl* layer_tree_host_impl) { | |
| 44 return base::WrapUnique(new FrameTimingTracker(layer_tree_host_impl)); | |
| 45 } | |
| 46 | |
| 47 FrameTimingTracker::FrameTimingTracker(LayerTreeHostImpl* layer_tree_host_impl) | |
| 48 : layer_tree_host_impl_(layer_tree_host_impl), | |
| 49 post_events_notifier_( | |
| 50 layer_tree_host_impl_->GetTaskRunner(), | |
| 51 base::Bind(&FrameTimingTracker::PostEvents, base::Unretained(this)), | |
| 52 base::TimeDelta::FromMilliseconds(kSendTimingIntervalMS)) {} | |
| 53 | |
| 54 FrameTimingTracker::~FrameTimingTracker() { | |
| 55 } | |
| 56 | |
| 57 void FrameTimingTracker::SaveTimeStamps( | |
| 58 base::TimeTicks timestamp, | |
| 59 const std::vector<FrameAndRectIds>& frame_ids) { | |
| 60 if (!composite_events_) | |
| 61 composite_events_.reset(new CompositeTimingSet); | |
| 62 for (const auto& pair : frame_ids) { | |
| 63 (*composite_events_)[pair.second].push_back( | |
| 64 CompositeTimingEvent(pair.first, timestamp)); | |
| 65 } | |
| 66 if (!post_events_notifier_.HasPendingNotification()) | |
| 67 post_events_notifier_.Schedule(); | |
| 68 } | |
| 69 | |
| 70 void FrameTimingTracker::SaveMainFrameTimeStamps( | |
| 71 const std::vector<int64_t>& request_ids, | |
| 72 base::TimeTicks main_frame_time, | |
| 73 base::TimeTicks end_time, | |
| 74 int source_frame_number) { | |
| 75 if (!main_frame_events_) | |
| 76 main_frame_events_.reset(new MainFrameTimingSet); | |
| 77 for (const auto& request : request_ids) { | |
| 78 std::vector<MainFrameTimingEvent>& events = (*main_frame_events_)[request]; | |
| 79 events.push_back( | |
| 80 MainFrameTimingEvent(source_frame_number, main_frame_time, end_time)); | |
| 81 } | |
| 82 if (!post_events_notifier_.HasPendingNotification()) | |
| 83 post_events_notifier_.Schedule(); | |
| 84 } | |
| 85 | |
| 86 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> | |
| 87 FrameTimingTracker::GroupCompositeCountsByRectId() { | |
| 88 if (!composite_events_) | |
| 89 return base::WrapUnique(new CompositeTimingSet); | |
| 90 for (auto& infos : *composite_events_) { | |
| 91 std::sort( | |
| 92 infos.second.begin(), infos.second.end(), | |
| 93 [](const CompositeTimingEvent& lhs, const CompositeTimingEvent& rhs) { | |
| 94 return lhs.timestamp < rhs.timestamp; | |
| 95 }); | |
| 96 } | |
| 97 return std::move(composite_events_); | |
| 98 } | |
| 99 | |
| 100 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> | |
| 101 FrameTimingTracker::GroupMainFrameCountsByRectId() { | |
| 102 if (!main_frame_events_) | |
| 103 return base::WrapUnique(new MainFrameTimingSet); | |
| 104 for (auto& infos : *main_frame_events_) { | |
| 105 std::sort( | |
| 106 infos.second.begin(), infos.second.end(), | |
| 107 [](const MainFrameTimingEvent& lhs, const MainFrameTimingEvent& rhs) { | |
| 108 return lhs.timestamp < rhs.timestamp; | |
| 109 }); | |
| 110 } | |
| 111 return std::move(main_frame_events_); | |
| 112 } | |
| 113 | |
| 114 void FrameTimingTracker::PostEvents() { | |
| 115 layer_tree_host_impl_->PostFrameTimingEvents(GroupCompositeCountsByRectId(), | |
| 116 GroupMainFrameCountsByRectId()); | |
| 117 } | |
| 118 | |
| 119 } // namespace cc | |
| OLD | NEW |