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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/map-wrapper.h>
29 class PlatformAbstraction;
35 #define DEBUG_FREQUENCY 2 // how often to print out the performance statistics in seconds
37 #ifdef PERFORMANCE_MONITOR_ENABLED
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
46 class PerformanceMetric;
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
55 * To enable performance monitor you have configure dali with --enable-performance-monitor
57 * @todo create a graphical overlay to see performance on screen
58 * instead of the terminal.
60 class PerformanceMonitor
65 * The order in which they appear here, defines the order in which
66 * they are displayed on the terminal
79 TEXTURE_STATE_CHANGES,
86 TEXTURE_DATA_UPLOADED,
105 * Called once if Core is built with --enable-performance-monitor
106 * @param[in] platfrom Used for querying the current time
108 static void Init( Integration::PlatformAbstraction& platform );
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();
121 * Private constructor
122 * @param[in] platfrom Used for querying the current time
124 PerformanceMonitor( Integration::PlatformAbstraction& platform );
128 Integration::PlatformAbstraction& mPlatform;
130 const MetricInfo &GetMetricInfo(Metric metricId);
131 PerformanceMetric *Add(Metric metricId);
132 PerformanceMetric *GetMetric(Metric metricId);
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
140 #ifdef PERFORMANCE_MONITOR_ENABLED
141 #define PERFORMANCE_MONITOR_INIT(x) PerformanceMonitor::Init(x);
143 #define PERFORMANCE_MONITOR_INIT(x)
147 #define PERF_MONITOR_START(x) PerformanceMonitor::Get()->StartTimer(x)
148 #define PERF_MONITOR_END(x) PerformanceMonitor::Get()->EndTimer(x)
150 #define PERF_MONITOR_START(x)
151 #define PERF_MONITOR_END(x)
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);
160 #define INCREASE_COUNTER(x)
161 #define INCREASE_BY(x,y)
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);
169 #define MATH_INCREASE_COUNTER(x)
170 #define MATH_INCREASE_BY(x,y)
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)
178 #define DRAW_ELEMENT_RECORD(x) \
179 PerformanceMonitor::Get()->Increase(PerformanceMonitor::GL_DRAW_ELEMENTS,1); \
180 PerformanceMonitor::Get()->Increase(PerformanceMonitor::INDICIE_COUNT,x)
182 #define DRAW_ARRAY_RECORD(x)
183 #define DRAW_ELEMENT_RECORD(x)
186 #if defined(PRINT_TIMERS ) || defined(PRINT_COUNTERS) || defined(PRINT_DRAW_CALLS)
187 #define PERF_MONITOR_NEXT_FRAME() PerformanceMonitor::Get()->FrameTick()
189 #define PERF_MONITOR_NEXT_FRAME()
192 } // namespace Internal
196 #endif // __DALI_INTERNAL_PERFORMANCE_MONITOR_H_