Merge "atspi: remove undefined method" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / stat-context-manager.h
1 #ifndef DALI_INTERNAL_ADAPTOR_STAT_CONTEXT_MANAGER_H
2 #define DALI_INTERNAL_ADAPTOR_STAT_CONTEXT_MANAGER_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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/threading/mutex.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/internal/system/common/performance-interface.h>
26 #include <dali/internal/system/common/performance-marker.h>
27 #include <dali/internal/system/common/stat-context.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 /**
36  * Class to manage StatContext objects.
37  *
38  * Contains 3 built in contexts for event, update, render.
39  * The application developer can add more using the PerformanceLogger public API
40  *
41  * Example output of 4 contexts ( event, update, render and a custom one):
42  *
43  * Event, min 0.04 ms, max 5.27 ms, total (0.1 secs), avg 0.28 ms, std dev 0.73 ms
44  * Update, min 0.29 ms, max 0.91 ms, total (0.5 secs), avg 0.68 ms, std dev 0.15 ms
45  * Render, min 0.33 ms, max 0.97 ms, total (0.6 secs), avg 0.73 ms, std dev 0.17 ms
46  * MyAppTask, min 76.55 ms, max 76.55 ms, total (0.1 secs), avg 76.55 ms, std dev 0.00 ms  (CUSTOM CONTEXT)
47  *
48  */
49 class StatContextManager
50 {
51 public:
52   /**
53      * @brief Constructor
54      * @param[in] logInterface interface to log statistics to
55      */
56   StatContextManager(StatContextLogInterface& logInterface);
57
58   /**
59      * @brief destructor, not intended as a bass class
60      */
61   ~StatContextManager();
62
63   /**
64      * @brief Add a context
65      * @param[in] name Name of the context to print in console
66      * @param[in] type the type of events to filter ( e.g. event, update, render or custom)
67      * @return The ID to give the context
68      */
69   PerformanceInterface::ContextId AddContext(const char* const name, PerformanceMarker::MarkerFilter type);
70
71   /**
72      * @brief Remove a context
73      * @param[in] contextId id of the context to remove
74      */
75   void RemoveContext(PerformanceInterface::ContextId contextId);
76
77   /**
78      * @brief Add an internal marker (e.g. v-sync, update, render markers)
79      * @param[in] marker the marker to add
80      */
81   void AddInternalMarker(const PerformanceMarker& marker);
82
83   /**
84      * @brief Add a custom marker defined by the application
85      * @param[in] marker the marker to add
86      * @param[in] contextId the context the custom marker is designed for
87      */
88   void AddCustomMarker(const PerformanceMarker& marker, PerformanceInterface::ContextId contextId);
89
90   /**
91      * @brief Get the nane of a context
92      * @param[in] contextId id of the context to get the name
93      * @return context name
94      */
95   const char* GetContextName(PerformanceInterface::ContextId contextId) const;
96
97   /**
98      * @brief Get the full description of a marker for this context
99      * @param[in] type marker type, for a customer marker this will be either START or END
100      * @param[in] contextId id of the context to get the name
101      * @return marker description in relation to this context
102      */
103   const char* GetMarkerDescription(PerformanceInterface::MarkerType type, PerformanceInterface::ContextId contextId) const;
104
105   /**
106      * @brief enable / disable logging for a context
107      * @param[in] enable whether to enable logging
108      * @param[in] contextId the context to configure
109      */
110   void EnableLogging(bool enable, PerformanceInterface::ContextId contextId);
111
112   /**
113      * @brief set global logging level and frequency.
114      * @param[in] statisticsLogOptions  log options
115      * @param[in] logFrequency frequency in seconds
116      */
117   void SetLoggingLevel(unsigned int statisticsLogOptions, unsigned int logFrequency);
118
119   /**
120      * @brief Set the frequency of logging for an individual context
121      * @param[in] logFrequency log frequency in seconds
122      * @param[in] contextId the context to configure
123      */
124   void SetLoggingFrequency(unsigned int logFrequency, PerformanceInterface::ContextId contextId);
125
126 private:
127   StatContextManager(const StatContextManager&);            ///< Undefined
128   StatContextManager& operator=(const StatContextManager&); ///< Undefined
129
130   typedef Dali::Vector<StatContext*> StatContexts;
131
132   /**
133      * @brief helper
134      * @param[in] contextId the context to get
135      * @return context
136      */
137   StatContext* GetContext(PerformanceInterface::ContextId contextId) const;
138
139   Dali::Mutex              mDataMutex;    ///< mutex
140   StatContexts             mStatContexts; ///< The list of stat contexts
141   StatContextLogInterface& mLogInterface; ///< Log interface
142
143   PerformanceInterface::ContextId mNextContextId; ///< The next valid context ID
144
145   // Some defaults contexts
146   PerformanceInterface::ContextId mUpdateStats; ///< update time statistics
147   PerformanceInterface::ContextId mRenderStats; ///< render time statistics
148   PerformanceInterface::ContextId mEventStats;  ///< event time statistics
149
150   unsigned int mStatisticsLogBitmask; ///< statistics log bitmask
151   unsigned int mLogFrequency;         ///< log frequency
152 };
153
154 } // namespace Adaptor
155
156 } // namespace Internal
157
158 } // namespace Dali
159
160 #endif // DALI_INTERNAL_ADAPTOR_STAT_CONTEXT_MANAGER_H