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