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 #ifndef CC_DEBUG_RENDERING_STATS_INSTRUMENTATION_H_
      6 #define CC_DEBUG_RENDERING_STATS_INSTRUMENTATION_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/synchronization/lock.h"
     10 #include "cc/debug/rendering_stats.h"
     11 
     12 namespace cc {
     13 
     14 // RenderingStatsInstrumentation is shared among threads and manages conditional
     15 // recording of rendering stats into a private RenderingStats instance.
     16 class CC_EXPORT RenderingStatsInstrumentation {
     17  public:
     18   static scoped_ptr<RenderingStatsInstrumentation> Create();
     19   virtual ~RenderingStatsInstrumentation();
     20 
     21   // Return copy of current main thread rendering stats.
     22   RenderingStats::MainThreadRenderingStats main_thread_rendering_stats();
     23 
     24   // Return copy of current impl thread rendering stats.
     25   RenderingStats::ImplThreadRenderingStats impl_thread_rendering_stats();
     26 
     27   // Return the accumulated, combined rendering stats.
     28   RenderingStats GetRenderingStats();
     29 
     30   // Add current main thread rendering stats to accumulator and
     31   // clear current stats.
     32   void AccumulateAndClearMainThreadStats();
     33 
     34   // Add current impl thread rendering stats to accumulator and
     35   // clear current stats.
     36   void AccumulateAndClearImplThreadStats();
     37 
     38   // Read and write access to the record_rendering_stats_ flag is not locked to
     39   // improve performance. The flag is commonly turned off and hardly changes
     40   // it's value during runtime.
     41   bool record_rendering_stats() const { return record_rendering_stats_; }
     42   void set_record_rendering_stats(bool record_rendering_stats) {
     43     if (record_rendering_stats_ != record_rendering_stats)
     44       record_rendering_stats_ = record_rendering_stats;
     45   }
     46 
     47   base::TimeTicks StartRecording() const;
     48   base::TimeDelta EndRecording(base::TimeTicks start_time) const;
     49 
     50   void IncrementFrameCount(int64 count, bool main_thread);
     51   void AddPaint(base::TimeDelta duration, int64 pixels);
     52   void AddRecord(base::TimeDelta duration, int64 pixels);
     53   void AddRaster(base::TimeDelta duration, int64 pixels);
     54   void AddAnalysis(base::TimeDelta duration, int64 pixels);
     55   void AddVisibleContentArea(int64 area);
     56   void AddApproximatedVisibleContentArea(int64 area);
     57   void AddDrawDuration(base::TimeDelta draw_duration,
     58                        base::TimeDelta draw_duration_estimate);
     59   void AddBeginMainFrameToCommitDuration(
     60       base::TimeDelta begin_main_frame_to_commit_duration,
     61       base::TimeDelta begin_main_frame_to_commit_duration_estimate);
     62   void AddCommitToActivateDuration(
     63       base::TimeDelta commit_to_activate_duration,
     64       base::TimeDelta commit_to_activate_duration_estimate);
     65 
     66  protected:
     67   RenderingStatsInstrumentation();
     68 
     69  private:
     70   RenderingStats::MainThreadRenderingStats main_thread_rendering_stats_;
     71   RenderingStats::MainThreadRenderingStats main_thread_rendering_stats_accu_;
     72   RenderingStats::ImplThreadRenderingStats impl_thread_rendering_stats_;
     73   RenderingStats::ImplThreadRenderingStats impl_thread_rendering_stats_accu_;
     74 
     75   bool record_rendering_stats_;
     76 
     77   base::Lock lock_;
     78 
     79   DISALLOW_COPY_AND_ASSIGN(RenderingStatsInstrumentation);
     80 };
     81 
     82 }  // namespace cc
     83 
     84 #endif  // CC_DEBUG_RENDERING_STATS_INSTRUMENTATION_H_
     85