Dali 3D User Interface Engine
stat-context-manager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 // CLASS HEADER
19 #include "stat-context-manager.h"
20 
21 // EXTERNAL INCLUDES
23 
24 namespace Dali
25 {
26 
27 namespace Internal
28 {
29 
30 namespace Adaptor
31 {
32 
33 namespace
34 {
35 const char* const UPDATE_CONTEXT_NAME = "Update";
36 const char* const RENDER_CONTEXT_NAME = "Render";
37 const char* const EVENT_CONTEXT_NAME = "Event";
38 const unsigned int DEFAULT_LOG_FREQUENCY = 2;
39 }
40 
42 : mLogInterface( logInterface ),
43  mNextContextId( 0 ),
44  mStatisticsLogBitmask(0),
45  mLogFrequency( DEFAULT_LOG_FREQUENCY )
46 {
47 
48  mStatContexts.Reserve(4); // intially reserve enough for 3 internal + 1 custom
49 
50  // Add defaults
54 
55 }
56 
58 {
59  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
60  {
61  StatContext* context = *it;
62  delete context;
63  }
65 }
68 {
69  unsigned int contextId = mNextContextId++;
70 
71  DALI_ASSERT_DEBUG( NULL == GetContext( contextId ) );
72 
73  // logging enabled by default
74  StatContext* statContext = new StatContext( contextId, name, type, mLogFrequency , mLogInterface );
75 
76  // check to see if custom markers are enabled
78  {
79  statContext->EnableLogging( false );
80  }
81 
82  mStatContexts.PushBack( statContext );
83 
84  return contextId;
85 }
86 
88 {
89  // log to the stat contexts, can be called from multiple threads so we
90  // protect the data
92  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
93  {
94  StatContext* context = *it;
95  context->ProcessInternalMarker( marker );
96  }
97 }
98 
100 {
101  // log to the stat contexts, can be called from multiple threads so we
102  // protect the data
104  StatContext* context = GetContext( contextId );
105  if( context )
106  {
107  context->ProcessCustomMarker( marker );
108  }
109 }
110 
112 {
113  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
114  {
115  StatContext* context = *it;
116 
117  if( context->GetId() == contextId )
118  {
119  delete context;
120  mStatContexts.Erase( it );
121  return;
122  }
123  }
124 }
125 
126 
128 {
129  StatContext* context = GetContext( contextId );
130  if( context )
131  {
132  context->EnableLogging( enable );
133  }
134 }
135 
136 void StatContextManager::SetLoggingLevel( unsigned int statisticsLogOptions, unsigned int logFrequency)
137 {
138  mStatisticsLogBitmask = statisticsLogOptions;
139 
141  {
142  mStatisticsLogBitmask = 0xFFFFFFFF; // enable everything
143  }
144 
145  mLogFrequency = logFrequency;
146 
147  // currently uses DALI_LOG_PERFORMANCE_STATS_FREQ environment variable to determine to log frequency
148  // if it's not set it will be zero
149  if( mLogFrequency == 0 )
150  {
152  }
154  EnableLogging( mStatisticsLogBitmask & PerformanceInterface::LOG_UPDATE_RENDER, mRenderStats );
156 
157  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
158  {
159  StatContext* context = *it;
160  context->SetLogFrequency( mLogFrequency );
161  }
162 }
163 
164 void StatContextManager::SetLoggingFrequency( unsigned int logFrequency,
166 {
167  StatContext* context = GetContext( contextId );
168  if( context )
169  {
170  if( logFrequency == 0 )
171  {
172  logFrequency = DEFAULT_LOG_FREQUENCY;
173  }
174  context->SetLogFrequency( logFrequency );
175  }
176 }
178 {
179  StatContext* context = GetContext(contextId);
180  if( context )
181  {
182  return context->GetName();
183  }
184  return "context not found";
185 }
186 
188 {
189  StatContext* context = GetContext(contextId);
190  if( context )
191  {
192  return context->GetMarkerDescription( type );
193  }
194  return "context not found";
195 }
196 
197 
199 {
200  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
201  {
202  StatContext* context = *it;
203 
204  if( context->GetId() == contextId )
205  {
206  return context;
207  }
208  }
209 
210  return NULL;
211 }
212 
213 
214 } // namespace Internal
215 
216 } // namespace Adaptor
217 
218 } // namespace Dali
219 
220 
Dali Docs Home
Read more about Dali