2 * Copyright (c) 2018 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 <dali/integration-api/trace.h>
34 thread_local LogContextFunction gThreadLocalLogContextFunction = nullptr;
36 void InstallLogContextFunction( const LogContextFunction& logContextFunction )
38 gThreadLocalLogContextFunction = logContextFunction;
41 void LogContext( bool start, const char* tag )
43 if ( !gThreadLocalLogContextFunction )
47 gThreadLocalLogContextFunction( start, tag );
52 typedef std::list<Filter*> FilterList;
53 typedef std::list<Filter*>::iterator FilterIter;
57 static FilterList* GetActiveFilters()
59 static FilterList* activeFilters = new FilterList;
64 Filter* Filter::New( bool trace, const char * environmentVariableName )
66 char * environmentVariableValue = getenv( environmentVariableName );
67 if ( environmentVariableValue )
69 char envTraceString( 0 );
70 sscanf( environmentVariableValue, "%c", &envTraceString );
72 // Just use 'f' and 't' as it's faster than doing full string comparisons
73 if ( envTraceString == 't' )
77 else if ( envTraceString == 'f' )
83 Filter* filter = new Filter( trace );
84 GetActiveFilters()->push_back( filter );
89 * Enable trace on all filters.
91 void Filter::EnableGlobalTrace()
93 for( FilterIter iter = GetActiveFilters()->begin(); iter != GetActiveFilters()->end(); iter++ )
95 (*iter)->EnableTrace();
100 * Disable trace on all filters.
102 void Filter::DisableGlobalTrace()
104 for( FilterIter iter = GetActiveFilters()->begin(); iter != GetActiveFilters()->end(); iter++ )
106 (*iter)->DisableTrace();
113 void Filter::BeginTrace( const char* tagName )
115 Dali::Integration::Trace::LogContext( true, tagName );
121 void Filter::EndTrace( const char* tagName )
123 Dali::Integration::Trace::LogContext( false, tagName );
129 Tracer::Tracer( Filter* filter, const char* tag )
133 if( mFilter && mFilter->IsTraceEnabled() )
135 mFilter->BeginTrace( mTag );
144 if( mFilter && mFilter->IsTraceEnabled() )
146 mFilter->EndTrace( mTag );
150 #endif //TRACE_ENABLED