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