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