OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/scheduler/begin_frame_tracker.h" |
| 6 |
| 7 namespace cc { |
| 8 |
| 9 BeginFrameTracker::BeginFrameTracker(const tracked_objects::Location& location) |
| 10 : location_(location), |
| 11 location_string_(location.ToString()), |
| 12 current_updated_at_(), |
| 13 current_args_(), |
| 14 current_finished_at_(base::TimeTicks::FromInternalValue(-1)) { |
| 15 } |
| 16 |
| 17 BeginFrameTracker::~BeginFrameTracker() { |
| 18 } |
| 19 |
| 20 void BeginFrameTracker::Start(BeginFrameArgs new_args) { |
| 21 // Trace the frame time being passed between BeginFrameTrackers. |
| 22 TRACE_EVENT_FLOW_STEP0( |
| 23 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", |
| 24 new_args.frame_time.ToInternalValue(), location_string_); |
| 25 |
| 26 // Trace this specific begin frame tracker Start/Finish times. |
| 27 TRACE_EVENT_ASYNC_BEGIN2( |
| 28 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 29 location_string_.c_str(), new_args.frame_time.ToInternalValue(), |
| 30 "new args", new_args.AsValue(), "current args", current_args_.AsValue()); |
| 31 |
| 32 // Check the new BeginFrameArgs are valid and monotonically increasing. |
| 33 DCHECK(new_args.IsValid()); |
| 34 DCHECK_LE(current_args_.frame_time, new_args.frame_time); |
| 35 |
| 36 DCHECK(HasFinished()) |
| 37 << "Tried to start a new frame before finishing an existing frame."; |
| 38 current_updated_at_ = base::TimeTicks::NowFromSystemTraceTime(); |
| 39 current_args_ = new_args; |
| 40 current_finished_at_ = base::TimeTicks(); |
| 41 |
| 42 // TODO(mithro): Add UMA tracking of delta between current_updated_at_ time |
| 43 // and the new_args.frame_time argument. This will give us how long after a |
| 44 // BeginFrameArgs message was created before we started processing it. |
| 45 } |
| 46 |
| 47 const BeginFrameArgs& BeginFrameTracker::Current() const { |
| 48 DCHECK(!HasFinished()) |
| 49 << "Tried to use BeginFrameArgs after marking the frame finished."; |
| 50 DCHECK(current_args_.IsValid()) |
| 51 << "Tried to use BeginFrameArgs before starting a frame!"; |
| 52 return current_args_; |
| 53 } |
| 54 |
| 55 void BeginFrameTracker::Finish() { |
| 56 DCHECK(!HasFinished()) << "Tried to finish an already finished frame"; |
| 57 current_finished_at_ = base::TimeTicks::NowFromSystemTraceTime(); |
| 58 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 59 location_string_.c_str(), |
| 60 current_args_.frame_time.ToInternalValue()); |
| 61 } |
| 62 |
| 63 const BeginFrameArgs& BeginFrameTracker::Last() const { |
| 64 DCHECK(current_args_.IsValid()) |
| 65 << "Tried to use last BeginFrameArgs before starting a frame!"; |
| 66 DCHECK(HasFinished()) |
| 67 << "Tried to use last BeginFrameArgs before the frame is finished."; |
| 68 return current_args_; |
| 69 } |
| 70 |
| 71 base::TimeDelta BeginFrameTracker::Interval() const { |
| 72 base::TimeDelta interval = current_args_.interval; |
| 73 // Normal interval will be ~16ms, 200Hz (5ms) screens are the fastest |
| 74 // easily available so anything less than that is likely an error. |
| 75 if (interval < base::TimeDelta::FromMilliseconds(1)) { |
| 76 interval = BeginFrameArgs::DefaultInterval(); |
| 77 } |
| 78 return interval; |
| 79 } |
| 80 |
| 81 void BeginFrameTracker::AsValueInto( |
| 82 base::TimeTicks now, |
| 83 base::trace_event::TracedValue* state) const { |
| 84 state->SetInteger("updated_at_us", current_updated_at_.ToInternalValue()); |
| 85 state->SetInteger("finished_at_us", current_finished_at_.ToInternalValue()); |
| 86 if (HasFinished()) { |
| 87 state->SetString("state", "FINISHED"); |
| 88 state->BeginDictionary("current_args_"); |
| 89 } else { |
| 90 state->SetString("state", "USING"); |
| 91 state->BeginDictionary("last_args_"); |
| 92 } |
| 93 current_args_.AsValueInto(state); |
| 94 state->EndDictionary(); |
| 95 |
| 96 base::TimeTicks frame_time = current_args_.frame_time; |
| 97 base::TimeTicks deadline = current_args_.deadline; |
| 98 base::TimeDelta interval = current_args_.interval; |
| 99 state->BeginDictionary("major_timestamps_in_ms"); |
| 100 state->SetDouble("0_interval", interval.InMillisecondsF()); |
| 101 state->SetDouble("1_now_to_deadline", (deadline - now).InMillisecondsF()); |
| 102 state->SetDouble("2_frame_time_to_now", (now - frame_time).InMillisecondsF()); |
| 103 state->SetDouble("3_frame_time_to_deadline", |
| 104 (deadline - frame_time).InMillisecondsF()); |
| 105 state->SetDouble("4_now", (now - base::TimeTicks()).InMillisecondsF()); |
| 106 state->SetDouble("5_frame_time", |
| 107 (frame_time - base::TimeTicks()).InMillisecondsF()); |
| 108 state->SetDouble("6_deadline", |
| 109 (deadline - base::TimeTicks()).InMillisecondsF()); |
| 110 state->EndDictionary(); |
| 111 } |
| 112 |
| 113 const BeginFrameArgs& BeginFrameTracker::DangerousMethodCurrentOrLast() const { |
| 114 if (!HasFinished()) { |
| 115 return Current(); |
| 116 } else { |
| 117 return Last(); |
| 118 } |
| 119 } |
| 120 |
| 121 } // namespace cc |
OLD | NEW |