Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: cc/rendering_stats_subscriber.cc

Issue 11198005: NOT READY FOR REVIEW - switch to a subscriber model for rendering stats (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing file. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/rendering_stats_subscriber.h ('k') | cc/single_thread_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 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 "config.h"
6
7 #include "rendering_stats_subscriber.h"
8
9 #include <cmath>
10
11 namespace {
12 // If a frame takes less than 1/70 seconds, we will assume it is an error and
13 // ignore it.
14 static const double kFrameTooFast = 1.0 / 70.0;
15 } // namespace
16
17 namespace cc {
18
19 scoped_ptr<RenderingStatsSubscriber> RenderingStatsSubscriber::create()
20 {
21 scoped_ptr<RenderingStatsSubscriber> subscriber(new RenderingStatsSubscriber);
22 return subscriber.Pass();
23 }
24
25 RenderingStatsSubscriber::RenderingStatsSubscriber()
26 : is_scrolling_(false),
27 has_scrolled_(false)
28 {}
29
30 RenderingStatsSubscriber::~RenderingStatsSubscriber() {}
31
32 void RenderingStatsSubscriber::markBeginningOfFrame(base::TimeTicks timestamp) {
33 // We ignore timestamps that occur after the scroll.
34 if (has_scrolled_ && !is_scrolling_)
35 return;
36
37 bool should_add_timestamp = time_stamp_history_.empty();
38 if (!should_add_timestamp) {
39 base::TimeDelta delta = timestamp - time_stamp_history_.back();
40 should_add_timestamp = delta.InMillisecondsF() > kFrameTooFast;
41 }
42 if (should_add_timestamp)
43 time_stamp_history_.push_back(timestamp);
44 }
45
46 void RenderingStatsSubscriber::handledScrollEvent(bool content_did_move) {
47 if (!has_scrolled_ && content_did_move) {
48 // We're starting a scroll. We'll want to measure the framerate during the
49 // scroll, so we'll discard any timestamps we've gathered so far.
50 time_stamp_history_.clear();
51 has_scrolled_ = true;
52 }
53
54 is_scrolling_ = content_did_move;
55 }
56
57 void RenderingStatsSubscriber::getFPSAndStandardDeviation(
58 double& average_fps,
59 double& standard_deviation) const {
60
61 base::TimeDelta duration =
62 time_stamp_history_.front() - time_stamp_history_.back();
63
64 double average_frame_duration = duration.InSecondsF() /
65 static_cast<double>(time_stamp_history_.size());
66
67 if (average_frame_duration > 0.0)
68 average_fps = 1.0 / average_frame_duration;
69
70 if (time_stamp_history_.size() > 2) {
71 double sum_squared_distances_to_mean = 0.0;
72 for (size_t i = 1; i < time_stamp_history_.size(); ++i) {
73 base::TimeDelta frame_duration =
74 time_stamp_history_[i] - time_stamp_history_[i - 1];
75 double signed_distance_to_mean =
76 average_fps - (1.0 / frame_duration.InSecondsF());
77 sum_squared_distances_to_mean +=
78 signed_distance_to_mean * signed_distance_to_mean;
79 }
80 standard_deviation = std::sqrt(sum_squared_distances_to_mean /
81 static_cast<double>(time_stamp_history_.size() - 2));
82 }
83 }
84
85 } // namespace cc
OLDNEW
« no previous file with comments | « cc/rendering_stats_subscriber.h ('k') | cc/single_thread_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698