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