1 #ifndef __DALI_INTERNAL_PERFORMANCE_MONITOR_H__
2 #define __DALI_INTERNAL_PERFORMANCE_MONITOR_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 #include <dali/public-api/common/map-wrapper.h>
28 class PlatformAbstraction;
34 #define DEBUG_FREQUENCY 2 // how often to print out the performance statistics in seconds
36 #ifdef PERFORMANCE_MONITOR_ENABLED
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
45 class PerformanceMetric;
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
54 * To enable performance monitor you have configure dali with --enable-performance-monitor
56 * @todo create a graphical overlay to see performance on screen
57 * instead of the terminal.
59 class PerformanceMonitor
64 * The order in which they appear here, defines the order in which
65 * they are displayed on the terminal
78 TEXTURE_STATE_CHANGES,
85 TEXTURE_DATA_UPLOADED,
104 * Called once if Core is built with --enable-performance-monitor
105 * @param[in] platfrom Used for querying the current time
107 static void Init( Integration::PlatformAbstraction& platform );
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();
120 * Private constructor
121 * @param[in] platfrom Used for querying the current time
123 PerformanceMonitor( Integration::PlatformAbstraction& platform );
127 Integration::PlatformAbstraction& mPlatform;
129 const MetricInfo &GetMetricInfo(Metric metricId);
130 PerformanceMetric *Add(Metric metricId);
131 PerformanceMetric *GetMetric(Metric metricId);
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
139 #ifdef PERFORMANCE_MONITOR_ENABLED
140 #define PERFORMANCE_MONITOR_INIT(x) PerformanceMonitor::Init(x);
142 #define PERFORMANCE_MONITOR_INIT(x)
146 #define PERF_MONITOR_START(x) PerformanceMonitor::Get()->StartTimer(x)
147 #define PERF_MONITOR_END(x) PerformanceMonitor::Get()->EndTimer(x)
149 #define PERF_MONITOR_START(x)
150 #define PERF_MONITOR_END(x)
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);
159 #define INCREASE_COUNTER(x)
160 #define INCREASE_BY(x,y)
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);
168 #define MATH_INCREASE_COUNTER(x)
169 #define MATH_INCREASE_BY(x,y)
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)
177 #define DRAW_ELEMENT_RECORD(x) \
178 PerformanceMonitor::Get()->Increase(PerformanceMonitor::GL_DRAW_ELEMENTS,1); \
179 PerformanceMonitor::Get()->Increase(PerformanceMonitor::INDICIE_COUNT,x)
181 #define DRAW_ARRAY_RECORD(x)
182 #define DRAW_ELEMENT_RECORD(x)
185 #if defined(PRINT_TIMERS ) || defined(PRINT_COUNTERS) || defined(PRINT_DRAW_CALLS)
186 #define PERF_MONITOR_NEXT_FRAME() PerformanceMonitor::Get()->FrameTick()
188 #define PERF_MONITOR_NEXT_FRAME()
191 } // namespace Internal
195 #endif // __DALI_INTERNAL_PERFORMANCE_MONITOR_H_