1 #ifndef __DALI_INTERNAL_ADAPTOR_PERFORMANCE_SERVER_H__
2 #define __DALI_INTERNAL_ADAPTOR_PERFORMANCE_SERVER_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 <base/performance-logging/frame-time-stats.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <base/interfaces/adaptor-internal-services.h>
25 #include <base/performance-logging/performance-marker.h>
28 #include <boost/thread/mutex.hpp>
39 class EnvironmentOptions;
42 * Concrete implementation of performance interface.
43 * Adaptor classes should never include this file, they
44 * just need to include the abstract class performance-interface.h
46 class PerformanceServer : public PerformanceInterface
52 * @param adaptorServices adaptor internal services
53 * @param environmentOptions environment options
55 PerformanceServer( AdaptorInternalServices& adaptorServices,
56 const EnvironmentOptions& environmentOptions );
61 virtual ~PerformanceServer();
64 * @copydoc PerformanceLogger::AddContext()
66 virtual ContextId AddContext( const char* name );
69 * @copydoc PerformanceLogger::RemoveContext()
71 virtual void RemoveContext( ContextId contextId );
74 * @copydoc PerformanceInterface::AddMarker()
76 virtual void AddMarker( MarkerType markerType );
79 * @copydoc PerformanceLogger::AddMarker()
81 virtual void AddMarker( MarkerType markerType, ContextId contextId );
84 * @copydoc PerformanceInterface::SetLogging()
86 virtual void SetLogging( unsigned int level, unsigned int logFrequency );
89 * @copydoc PerformanceLogger::SetLoggingFrequency()
91 virtual void SetLoggingFrequency( unsigned int logFrequency, ContextId contextId );
94 * @copydoc PerformanceLogger::EnableLogging()
96 virtual void EnableLogging( bool enable, ContextId contextId );
101 * Class to hold a stat context
108 * Default constructor
115 * @param[in] id The ID to give the context
116 * @param[in] contextName Name of the context to print in console
118 StatContext( unsigned int id, const char* contextName );
123 * @return Return the ID
125 unsigned int GetId() const;
128 * Return the context name
130 * @return Return the context name
132 const char* GetName() const;
135 * Log the given marker
137 * @param[in] marker The marker to log
139 void LogMarker( const PerformanceMarker& marker );
142 * Set the frequency for logging
144 * @param[in] frequencyMicroseconds The frequency to set
146 void SetLogFrequency( unsigned int frequencyMicroseconds );
149 * Enable/disable logging
151 * @param[in] enableLogging Flag to spePerformancecify enabling/disabling
153 void EnableLogging( bool enableLogging );
158 * Helper to print to console
163 * Accumulate timer from markers
169 typedef Dali::Vector< PerformanceMarker > MarkerVector;
171 FrameTimeStats mStats; ///< Frame time stats to accumulate
172 MarkerVector mMarkers; ///< vector of markers
173 boost::mutex mDataMutex; ///< mutex
175 const char* mName; ///< Name of the context
177 unsigned int mId; ///< The ID of the context
179 unsigned int mLogFrequencyMicroseconds; ///< if logging is enabled, what frequency to log out at in micro-seconds
180 bool mLog; ///< Whether to print the log for this context or not
186 void AddMarkerToLog( const PerformanceMarker& marker, ContextId contextId );
189 * Retrieve a stat context by ID
191 * @param[in] contextId The ID of the context to retrieve
192 * @return Return the stat context if it exists or null
194 StatContext* GetContext( ContextId contextId );
197 * Return a string representation of the marker type
199 * @param[in] type The marker type
200 * @return Return the name of the given marker
202 const char* GetMarkerName( MarkerType type ) const;
206 typedef Dali::Vector< StatContext* > StatContexts;
208 // The list of stat contexts
209 StatContexts mStatContexts;
211 Integration::PlatformAbstraction& mPlatformAbstraction; ///< platform abstraction
212 const EnvironmentOptions& mEnvironmentOptions; ///< environment options
213 KernelTraceInterface& mKernelTrace; ///< kernel trace interface
215 unsigned int mLogLevel; ///< log level
216 unsigned int mNextContextId; ///< The next valid context ID
219 ContextId mUpdateStats; ///< update time statistics
220 ContextId mRenderStats; ///< render time statistics
221 ContextId mEventStats; ///< event time statistics
223 bool mLoggingEnabled:1; ///< whether logging update / render to a log is enabled
224 bool mLogFunctionInstalled:1; ///< whether the log function is installed
228 } // namespace Internal
230 } // namespace Adaptor