3f41f979d97392005c868a4f8a1cd52b82dd93ce
[platform/core/uifw/dali-adaptor.git] / adaptors / base / interfaces / performance-interface.h
1 #ifndef __DALI_INTERNAL_BASE_PERFORMANCE_INTERFACE_H__
2 #define __DALI_INTERNAL_BASE_PERFORMANCE_INTERFACE_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 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 namespace Adaptor
28 {
29
30 /**
31  * Abstract Performance Interface.
32  * Used by the Adaptor to store performance metrics.
33  *
34  */
35 class PerformanceInterface
36 {
37 public:
38
39   typedef unsigned short ContextId;   ///< Type to represent a context ID
40
41   /**
42    * bitmask of statistics logging options.
43    * Used for output data like min/max/average time spent in event, update,render and custom tasks.
44    * E.g.
45    * Event, min 0.04 ms, max 5.27 ms, total (0.1 secs), avg 0.28 ms, std dev 0.73 ms
46    * Update, min 0.29 ms, max 0.91 ms, total (0.5 secs), avg 0.68 ms, std dev 0.15 ms
47    * Render, min 0.33 ms, max 0.97 ms, total (0.6 secs), avg 0.73 ms, std dev 0.17 ms
48    * TableViewInit, min 76.55 ms, max 76.55 ms, total (0.1 secs), avg 76.55 ms, std dev 0.00 ms
49    */
50   enum StatisticsLogOptions
51   {
52     DISABLED             = 0,
53     LOG_EVERYTHING       = 1 << 0, ///< Bit 0 (1), log all statistics to the DALi log
54     LOG_UPDATE_RENDER    = 1 << 1, ///< Bit 1 (2), log update and render statistics to the DALi log
55     LOG_EVENT_PROCESS    = 1 << 2, ///< Bit 2 (4), log event task statistics to the DALi log
56     LOG_CUSTOM_MARKERS   = 1 << 3, ///< Bit 3 (8), log custom marker statistics to the DALi log
57   };
58
59   /**
60    * bitmask of time stamp output options
61    * Used for logging out time stamped markers for detailed analysis (see MarkerType, for the markers logged)
62    * Typical output would look like:
63    *   379.059025 (seconds), V_SYNC
64    *   379.059066 (seconds), UPDATE_START
65    *   379.059747 (seconds), UPDATE_END
66    *   379.059820 (seconds), RENDER_START
67    *   379.060708 (seconds), RENDER_END
68    *   379.075795 (seconds), V_SYNC
69    *   379.076444 (seconds), MY_CUSTOM_MARKER_START  ( customer marker using PerformanceLogger public API).
70    *   379.077353 (seconds), MY_CUSTOM_MARKER_END  ( customer marker using PerformanceLogger public API).
71    */
72   enum TimeStampOutput
73   {
74     NO_TIME_STAMP_OUTPUT         = 0,
75     OUTPUT_DALI_LOG              = 1 << 0, ///< Bit 1 (1), log markers to DALi log
76     OUTPUT_KERNEL_TRACE          = 1 << 1, ///< Bit 2 (2), log makers to kernel trace
77     OUTPUT_SYSTEM_TRACE          = 1 << 2, ///< Bit 3 (4), log markers to system trace
78     OUTPUT_NETWORK               = 1 << 3, ///< Bit 4 (8), log markers to network client
79   };
80
81   /**
82    * enum for difference performance markers.
83    * Please modify the name lookup table in performance-interface.cpp
84    * file if adding new markers (the order must match one to one).
85    */
86   enum MarkerType
87   {
88     VSYNC     = 0,        ///< V-Sync
89     UPDATE_START ,        ///< Update start
90     UPDATE_END   ,        ///< Update end
91     RENDER_START ,        ///< Render start
92     RENDER_END   ,        ///< Render end
93     SWAP_START   ,        ///< SwapBuffers Start
94     SWAP_END     ,        ///< SwapBuffers End
95     PROCESS_EVENTS_START, ///< Process events start (e.g. touch event)
96     PROCESS_EVENTS_END,   ///< Process events end
97     PAUSED       ,        ///< Pause start
98     RESUME       ,        ///< Resume start
99     START        ,        ///< The start of custom tracking
100     END                   ///< The end of custom tracking
101   };
102
103   /**
104    * Constructor.
105    */
106   PerformanceInterface() {}
107
108   /**
109    * Virtual destructor
110    */
111   virtual ~PerformanceInterface() {};
112
113   /**
114    * @brief Add a new context with a given name
115    *
116    * @param[in] name The name of the context
117    * @return Return the unique id for this context
118    */
119   virtual ContextId AddContext( const char* name ) = 0;
120
121   /**
122    * @brief Remove a context from use
123    *
124    * @param[in] contextId The ID of the context to remove
125    */
126   virtual void RemoveContext( ContextId contextId ) = 0;
127
128   /**
129    * @brief Add a performance marker
130    * This function can be called from ANY THREAD.
131    * The default context 0 Event/Update/Render is assumed.
132    * @param[in] markerType performance marker type
133    */
134   virtual void AddMarker( MarkerType markerType ) = 0;
135
136   /**
137    * @brief Add a performance marker for a used defined context
138    * This function can be called from ANY THREAD.
139    * @param[in] markerType performance marker type
140    * @param[in] contextId The context of the marker. This must be one generated by AddContext.
141    */
142   virtual void AddMarker( MarkerType markerType, ContextId contextId ) = 0;
143
144   /**
145    * @brief Set the logging level and frequency
146    * @param[in] StatisticsLogOptions  0 = disabled, >0 bitmask of StatisticsLogOptions
147    * @param[in] timeStampOutput 0 = disabled, > 0 bitmask of TimeStampOutput options.
148    * @param[in] logFrequency how often to log out in seconds
149    */
150   virtual void SetLogging( unsigned int statisticsLogOptions, unsigned int timeStampOutput, unsigned int logFrequency) = 0;
151
152   /**
153    * @brief Set the logging frequency for an individual context
154    *
155    * @param[in] logFrequency how often to log out in seconds
156    */
157   virtual void SetLoggingFrequency( unsigned int logFrequency, ContextId contextId ) = 0;
158
159   /**
160    * @brief Set logging on or off for a particular context
161    *
162    * @param[in] enable Enable logging or not
163    * @param[in] contextId The id of the context to log. This must be one generated by AddContext.
164    */
165   virtual void EnableLogging( bool enable, ContextId contextId ) = 0;
166
167 private:
168
169   // Undefined copy constructor.
170   PerformanceInterface( const PerformanceInterface& );
171
172   // Undefined assignment operator.
173   PerformanceInterface& operator=( const PerformanceInterface& );
174
175 };
176
177 } // namespace Internal
178
179 } // namespace Adaptor
180
181 } // namespace Dali
182
183 #endif