2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "stat-context-manager.h"
22 #include <dali/integration-api/debug.h>
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;
41 StatContextManager::StatContextManager( StatContextLogInterface& logInterface )
42 : mLogInterface( logInterface ),
44 mStatisticsLogBitmask(0),
45 mLogFrequency( DEFAULT_LOG_FREQUENCY )
48 mStatContexts.Reserve(4); // intially reserve enough for 3 internal + 1 custom
51 mUpdateStats = AddContext( UPDATE_CONTEXT_NAME, PerformanceMarker::UPDATE );
52 mRenderStats = AddContext( RENDER_CONTEXT_NAME, PerformanceMarker::RENDER );
53 mEventStats = AddContext( EVENT_CONTEXT_NAME, PerformanceMarker::EVENT_PROCESS );
57 StatContextManager::~StatContextManager()
59 for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
61 StatContext* context = *it;
64 mStatContexts.Clear();
66 PerformanceInterface::ContextId StatContextManager::AddContext( const char* const name,
67 PerformanceMarker::MarkerFilter type )
69 unsigned int contextId = mNextContextId++;
71 DALI_ASSERT_DEBUG( NULL == GetContext( contextId ) );
73 // logging enabled by default
74 StatContext* statContext = new StatContext( contextId, name, type, mLogFrequency , mLogInterface );
76 // check to see if custom markers are enabled
77 if( ! ( mStatisticsLogBitmask & PerformanceInterface::LOG_CUSTOM_MARKERS ) )
79 statContext->EnableLogging( false );
82 mStatContexts.PushBack( statContext );
87 void StatContextManager::AddInternalMarker( const PerformanceMarker& marker )
89 // log to the stat contexts, can be called from multiple threads so we
91 for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
93 StatContext* context = *it;
94 context->ProcessInternalMarker( marker );
98 void StatContextManager::AddCustomMarker( const PerformanceMarker& marker, PerformanceInterface::ContextId contextId )
100 // log to the stat contexts, can be called from multiple threads so we
102 StatContext* context = GetContext( contextId );
105 context->ProcessCustomMarker( marker );
109 void StatContextManager::RemoveContext(PerformanceInterface::ContextId contextId )
111 for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
113 StatContext* context = *it;
115 if( context->GetId() == contextId )
118 mStatContexts.Erase( it );
125 void StatContextManager::EnableLogging( bool enable, PerformanceInterface::ContextId contextId )
127 StatContext* context = GetContext( contextId );
130 context->EnableLogging( enable );
134 void StatContextManager::SetLoggingLevel( unsigned int statisticsLogOptions, unsigned int logFrequency)
136 mStatisticsLogBitmask = statisticsLogOptions;
138 if( mStatisticsLogBitmask == PerformanceInterface::LOG_EVERYTHING )
140 mStatisticsLogBitmask = 0xFFFFFFFF; // enable everything
143 mLogFrequency = logFrequency;
145 // currently uses DALI_LOG_PERFORMANCE_STATS_FREQ environment variable to determine to log frequency
146 // if it's not set it will be zero
147 if( mLogFrequency == 0 )
149 mLogFrequency = DEFAULT_LOG_FREQUENCY;
151 EnableLogging( mStatisticsLogBitmask & PerformanceInterface::LOG_UPDATE_RENDER, mUpdateStats );
152 EnableLogging( mStatisticsLogBitmask & PerformanceInterface::LOG_UPDATE_RENDER, mRenderStats );
153 EnableLogging( mStatisticsLogBitmask & PerformanceInterface::LOG_EVENT_PROCESS, mEventStats );
155 for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
157 StatContext* context = *it;
158 context->SetLogFrequency( mLogFrequency );
162 void StatContextManager::SetLoggingFrequency( unsigned int logFrequency,
163 PerformanceInterface::ContextId contextId )
165 StatContext* context = GetContext( contextId );
168 if( logFrequency == 0 )
170 logFrequency = DEFAULT_LOG_FREQUENCY;
172 context->SetLogFrequency( logFrequency );
175 const char* const StatContextManager::GetContextName(PerformanceInterface::ContextId contextId) const
177 StatContext* context = GetContext(contextId);
180 return context->GetName();
182 return "context not found";
185 const char* const StatContextManager::GetMarkerDescription( PerformanceInterface::MarkerType type, PerformanceInterface::ContextId contextId ) const
187 StatContext* context = GetContext(contextId);
190 return context->GetMarkerDescription( type );
192 return "context not found";
196 StatContext* StatContextManager::GetContext( PerformanceInterface::ContextId contextId ) const
198 for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
200 StatContext* context = *it;
202 if( context->GetId() == contextId )
212 } // namespace Internal
214 } // namespace Adaptor