Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / debug / rendering_stats_instrumentation.h
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 current main thread rendering stats.
22   const MainThreadRenderingStats& main_thread_rendering_stats() {
23     return main_stats_;
24   }
25   // Return current impl thread rendering stats.
26   const ImplThreadRenderingStats& impl_thread_rendering_stats() {
27     return impl_stats_;
28   }
29   // Return the accumulated, combined rendering stats.
30   RenderingStats GetRenderingStats();
31
32   // Add current main thread rendering stats to accumulator and
33   // clear current stats.
34   void AccumulateAndClearMainThreadStats();
35   // Add current impl thread rendering stats to accumulator and
36   // clear current stats.
37   void AccumulateAndClearImplThreadStats();
38
39   // Read and write access to the record_rendering_stats_ flag is not locked to
40   // improve performance. The flag is commonly turned off and hardly changes
41   // it's value during runtime.
42   bool record_rendering_stats() const { return record_rendering_stats_; }
43   void set_record_rendering_stats(bool record_rendering_stats) {
44     if (record_rendering_stats_ != record_rendering_stats)
45       record_rendering_stats_ = record_rendering_stats;
46   }
47
48   base::TimeTicks StartRecording() const;
49   base::TimeDelta EndRecording(base::TimeTicks start_time) const;
50
51   void IncrementFrameCount(int64 count, bool main_thread);
52   void AddPaint(base::TimeDelta duration, int64 pixels);
53   void AddRecord(base::TimeDelta duration, int64 pixels);
54   void AddRaster(base::TimeDelta duration, int64 pixels);
55   void AddAnalysis(base::TimeDelta duration, int64 pixels);
56   void AddVisibleContentArea(int64 area);
57   void AddApproximatedVisibleContentArea(int64 area);
58
59  protected:
60   RenderingStatsInstrumentation();
61
62  private:
63   // TODO(ernstm): rename to *_thread_rendering_stats_*
64   MainThreadRenderingStats main_stats_;
65   MainThreadRenderingStats main_stats_accu_;
66   ImplThreadRenderingStats impl_stats_;
67   ImplThreadRenderingStats impl_stats_accu_;
68
69   bool record_rendering_stats_;
70
71   base::Lock lock_;
72
73   DISALLOW_COPY_AND_ASSIGN(RenderingStatsInstrumentation);
74 };
75
76 }  // namespace cc
77
78 #endif  // CC_DEBUG_RENDERING_STATS_INSTRUMENTATION_H_