Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / render / common / performance-monitor.h
1 #ifndef __DALI_INTERNAL_PERFORMANCE_MONITOR_H__
2 #define __DALI_INTERNAL_PERFORMANCE_MONITOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/common/map-wrapper.h>
22
23 namespace Dali
24 {
25
26 namespace Integration
27 {
28 class PlatformAbstraction;
29 }
30
31 namespace Internal
32 {
33
34 #define DEBUG_FREQUENCY 2  // how often to print out the performance statistics in seconds
35
36 #ifdef PERFORMANCE_MONITOR_ENABLED
37
38 #define PRINT_TIMERS      // comment to hide Frame rate and timing information
39 //#define PRINT_COUNTERS    // comment to hide counters
40 //#define PRINT_DRAW_CALLS  // comment to hide draw call counters
41 //#define PRINT_MATH_COUNTERS // comment to hide maths counters
42
43 #endif
44
45 class PerformanceMetric;
46 struct MetricInfo;
47
48 /**
49  * PerformanceMonitor.
50  * Used to measure the time that Dali takes to performs operations
51  * and the amount of objects it processes/ state changes.
52  * Uses macros so that there is not performance impact if nothing is being monitored
53  *
54  * To enable performance monitor you have configure dali with --enable-performance-monitor
55  *
56  * @todo create a graphical overlay to see performance on screen
57  * instead of the terminal.
58  */
59 class PerformanceMonitor
60 {
61 public:
62
63   /*
64    * The order in which they appear here, defines the order in which
65    * they are displayed on the terminal
66    */
67   enum Metric
68   {
69     FRAME_RATE,
70     NODE_COUNT,
71     NODES_DRAWN,
72     NODES_ADDED,
73     NODES_REMOVED,
74     MESSAGE_COUNT,
75     MATRIX_MULTIPLYS,
76     QUATERNION_TO_MATRIX,
77     FLOAT_POINT_MULTIPLY,
78     TEXTURE_STATE_CHANGES,
79     SHADER_STATE_CHANGES,
80     BLEND_MODE_CHANGES,
81     GL_DRAW_CALLS,
82     GL_DRAW_ELEMENTS,
83     GL_DRAW_ARRAYS,
84     TEXTURE_LOADS,
85     TEXTURE_DATA_UPLOADED,
86     VERTEX_BUFFERS_BUILT,
87     INDICIE_COUNT,
88     UPDATE,
89     RESET_PROPERTIES,
90     PROCESS_MESSAGES,
91     ANIMATE_NODES,
92     ANIMATORS_APPLIED,
93     APPLY_CONSTRAINTS,
94     CONSTRAINTS_APPLIED,
95     CONSTRAINTS_SKIPPED,
96     UPDATE_NODES,
97     PREPARE_RENDERABLES,
98     PROCESS_RENDER_TASKS,
99     DRAW_NODES,
100     UPDATE_DYNAMICS
101   };
102
103   /**
104    * Called once if Core is built with --enable-performance-monitor
105    * @param[in] platfrom Used for querying the current time
106    */
107   static void Init( Integration::PlatformAbstraction& platform );
108
109   void FrameTick();
110   void Increase(Metric metricId,unsigned int value);
111   void StartTimer(Metric metricId);
112   void EndTimer(Metric metricId);
113   void Set(Metric metricId, unsigned int Value);
114   void Set(Metric metricId, float Value);
115   static PerformanceMonitor *Get();
116
117 private:
118
119   /**
120    * Private constructor
121    * @param[in] platfrom Used for querying the current time
122    */
123   PerformanceMonitor( Integration::PlatformAbstraction& platform );
124
125 private:
126
127   Integration::PlatformAbstraction& mPlatform;
128
129   const MetricInfo &GetMetricInfo(Metric metricId);
130   PerformanceMetric *Add(Metric metricId);
131   PerformanceMetric *GetMetric(Metric metricId);
132
133   typedef std::map<int, PerformanceMetric *> mLookupTypeType;
134   mLookupTypeType mMetrics;           ///< list of metrics
135   unsigned int mStartSeconds;         ///< frame-time of the first tick
136   unsigned int mSeconds;              ///< last second the data was printed
137 };
138
139 #ifdef PERFORMANCE_MONITOR_ENABLED
140 #define PERFORMANCE_MONITOR_INIT(x) PerformanceMonitor::Init(x);
141 #else
142 #define PERFORMANCE_MONITOR_INIT(x)
143 #endif
144
145 #ifdef PRINT_TIMERS
146 #define PERF_MONITOR_START(x)  PerformanceMonitor::Get()->StartTimer(x)
147 #define PERF_MONITOR_END(x)    PerformanceMonitor::Get()->EndTimer(x)
148 #else
149 #define PERF_MONITOR_START(x)
150 #define PERF_MONITOR_END(x)
151 #endif
152
153 #ifdef PRINT_COUNTERS
154 #define SET(x,y)  PerformanceMonitor::Get()->Set(x,y)
155 #define INCREASE_COUNTER(x) PerformanceMonitor::Get()->Increase(x,1);
156 #define INCREASE_BY(x,y) PerformanceMonitor::Get()->Increase(x,y);
157 #else
158 #define SET(x,y)
159 #define INCREASE_COUNTER(x)
160 #define INCREASE_BY(x,y)
161 #endif
162
163 #ifdef PRINT_MATH_COUNTERS
164 // for vectors/matrices
165 #define MATH_INCREASE_COUNTER(x)  PerformanceMonitor::Get()->Increase(x,1);
166 #define MATH_INCREASE_BY(x,y) PerformanceMonitor::Get()->Increase(x,y);
167 #else
168 #define MATH_INCREASE_COUNTER(x)
169 #define MATH_INCREASE_BY(x,y)
170 #endif
171
172 #ifdef PRINT_DRAW_CALLS
173 #define DRAW_ARRAY_RECORD(x)                                               \
174 PerformanceMonitor::Get()->Increase(PerformanceMonitor::GL_DRAW_ARRAYS,1); \
175 PerformanceMonitor::Get()->Increase(PerformanceMonitor::INDICIE_COUNT,x)
176
177 #define DRAW_ELEMENT_RECORD(x)                                               \
178 PerformanceMonitor::Get()->Increase(PerformanceMonitor::GL_DRAW_ELEMENTS,1); \
179 PerformanceMonitor::Get()->Increase(PerformanceMonitor::INDICIE_COUNT,x)
180 #else
181 #define DRAW_ARRAY_RECORD(x)
182 #define DRAW_ELEMENT_RECORD(x)
183 #endif
184
185 #if defined(PRINT_TIMERS ) || defined(PRINT_COUNTERS) || defined(PRINT_DRAW_CALLS)
186 #define PERF_MONITOR_NEXT_FRAME()  PerformanceMonitor::Get()->FrameTick()
187 #else
188 #define PERF_MONITOR_NEXT_FRAME()
189 #endif
190
191 } // namespace Internal
192
193 } // namespace Dali
194
195 #endif // __DALI_INTERNAL_PERFORMANCE_MONITOR_H_