Home | History | Annotate | Download | only in debug
      1 // Copyright 2013 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/rendering_stats_instrumentation.h"
      6 
      7 namespace cc {
      8 
      9 // static
     10 scoped_ptr<RenderingStatsInstrumentation>
     11     RenderingStatsInstrumentation::Create() {
     12   return make_scoped_ptr(new RenderingStatsInstrumentation());
     13 }
     14 
     15 RenderingStatsInstrumentation::RenderingStatsInstrumentation()
     16     : record_rendering_stats_(false) {
     17 }
     18 
     19 RenderingStatsInstrumentation::~RenderingStatsInstrumentation() {}
     20 
     21 RenderingStats RenderingStatsInstrumentation::GetRenderingStats() {
     22   base::AutoLock scoped_lock(lock_);
     23   return rendering_stats_;
     24 }
     25 
     26 base::TimeTicks RenderingStatsInstrumentation::StartRecording() const {
     27   if (record_rendering_stats_)
     28     return base::TimeTicks::HighResNow();
     29   return base::TimeTicks();
     30 }
     31 
     32 base::TimeDelta RenderingStatsInstrumentation::EndRecording(
     33     base::TimeTicks start_time) const {
     34   if (!start_time.is_null())
     35     return base::TimeTicks::HighResNow() - start_time;
     36   return base::TimeDelta();
     37 }
     38 
     39 void RenderingStatsInstrumentation::IncrementAnimationFrameCount() {
     40   if (!record_rendering_stats_)
     41     return;
     42 
     43   base::AutoLock scoped_lock(lock_);
     44   rendering_stats_.animation_frame_count++;
     45 }
     46 
     47 void RenderingStatsInstrumentation::SetScreenFrameCount(int64 count) {
     48   if (!record_rendering_stats_)
     49     return;
     50 
     51   base::AutoLock scoped_lock(lock_);
     52   rendering_stats_.screen_frame_count = count;
     53 }
     54 
     55 void RenderingStatsInstrumentation::SetDroppedFrameCount(int64 count) {
     56   if (!record_rendering_stats_)
     57     return;
     58 
     59   base::AutoLock scoped_lock(lock_);
     60   rendering_stats_.dropped_frame_count = count;
     61 }
     62 
     63 void RenderingStatsInstrumentation::AddCommit(base::TimeDelta duration) {
     64   if (!record_rendering_stats_)
     65     return;
     66 
     67   base::AutoLock scoped_lock(lock_);
     68   rendering_stats_.total_commit_time += duration;
     69   rendering_stats_.total_commit_count++;
     70 }
     71 
     72 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
     73                                              int64 pixels) {
     74   if (!record_rendering_stats_)
     75     return;
     76 
     77   base::AutoLock scoped_lock(lock_);
     78   rendering_stats_.total_paint_time += duration;
     79   rendering_stats_.total_pixels_painted += pixels;
     80 }
     81 
     82 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
     83                                               int64 pixels) {
     84   if (!record_rendering_stats_)
     85     return;
     86 
     87   base::AutoLock scoped_lock(lock_);
     88   rendering_stats_.total_record_time += duration;
     89   rendering_stats_.total_pixels_recorded += pixels;
     90 }
     91 
     92 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta total_duration,
     93                                               base::TimeDelta best_duration,
     94                                               int64 pixels,
     95                                               bool is_in_pending_tree_now_bin) {
     96   if (!record_rendering_stats_)
     97     return;
     98 
     99   base::AutoLock scoped_lock(lock_);
    100   rendering_stats_.total_rasterize_time += total_duration;
    101   rendering_stats_.best_rasterize_time += best_duration;
    102   rendering_stats_.total_pixels_rasterized += pixels;
    103 
    104   if (is_in_pending_tree_now_bin) {
    105     rendering_stats_.total_rasterize_time_for_now_bins_on_pending_tree +=
    106         total_duration;
    107   }
    108 }
    109 
    110 void RenderingStatsInstrumentation::IncrementImplThreadScrolls() {
    111   if (!record_rendering_stats_)
    112     return;
    113 
    114   base::AutoLock scoped_lock(lock_);
    115   rendering_stats_.num_impl_thread_scrolls++;
    116 }
    117 
    118 void RenderingStatsInstrumentation::IncrementMainThreadScrolls() {
    119   if (!record_rendering_stats_)
    120     return;
    121 
    122   base::AutoLock scoped_lock(lock_);
    123   rendering_stats_.num_main_thread_scrolls++;
    124 }
    125 
    126 void RenderingStatsInstrumentation::AddLayersDrawn(int64 amount) {
    127   if (!record_rendering_stats_)
    128     return;
    129 
    130   base::AutoLock scoped_lock(lock_);
    131   rendering_stats_.num_layers_drawn += amount;
    132 }
    133 
    134 void RenderingStatsInstrumentation::AddMissingTiles(int64 amount) {
    135   if (!record_rendering_stats_)
    136     return;
    137 
    138   base::AutoLock scoped_lock(lock_);
    139   rendering_stats_.num_missing_tiles += amount;
    140 }
    141 
    142 void RenderingStatsInstrumentation::AddDeferredImageDecode(
    143     base::TimeDelta duration) {
    144   if (!record_rendering_stats_)
    145     return;
    146 
    147   base::AutoLock scoped_lock(lock_);
    148   rendering_stats_.total_deferred_image_decode_time += duration;
    149   rendering_stats_.total_deferred_image_decode_count++;
    150 }
    151 
    152 void RenderingStatsInstrumentation::AddImageGathering(
    153     base::TimeDelta duration) {
    154   if (!record_rendering_stats_)
    155     return;
    156 
    157   base::AutoLock scoped_lock(lock_);
    158   rendering_stats_.total_image_gathering_time += duration;
    159   rendering_stats_.total_image_gathering_count++;
    160 }
    161 
    162 void RenderingStatsInstrumentation::IncrementDeferredImageCacheHitCount() {
    163   if (!record_rendering_stats_)
    164     return;
    165 
    166   base::AutoLock scoped_lock(lock_);
    167   rendering_stats_.total_deferred_image_cache_hit_count++;
    168 }
    169 
    170 void RenderingStatsInstrumentation::AddAnalysisResult(
    171     base::TimeDelta duration,
    172     bool is_solid_color) {
    173   if (!record_rendering_stats_)
    174     return;
    175 
    176   base::AutoLock scoped_lock(lock_);
    177   rendering_stats_.total_tiles_analyzed++;
    178   rendering_stats_.total_tile_analysis_time += duration;
    179   if (is_solid_color)
    180     rendering_stats_.solid_color_tiles_analyzed++;
    181 }
    182 
    183 }  // namespace cc
    184