1 #ifndef DALI_INTEGRATION_TRACE_H
2 #define DALI_INTEGRATION_TRACE_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <dali/public-api/common/dali-common.h>
37 * Used by tracing macros to log a context message
38 * @param start a bool to indicate start (true) or end (false) of the tracing / logging
39 * @param tag a unique event tag name
41 DALI_CORE_API void LogContext( bool start, const char* tag );
44 * typedef for the LogContextFunction function.
46 typedef void ( *LogContextFunction )( bool start, const char* tag );
49 * A LogContextFunction function has to be installed for every thread that wants to use tracing.
50 * This should be done by the adaptor.
51 * The LogContextFunction function can be different for each thread.
52 * @param LogContextFunction the Log Context function to install
54 DALI_CORE_API void InstallLogContextFunction( const LogContextFunction& logContextFunction );
56 /********************************************************************************
58 ********************************************************************************/
63 * The Filter object is used by the DALI_TRACE_BEGIN macro and others to determine if the tracing
64 * should take place, and routes the tracing via the platform abstraction's LogMessage.
66 * It provides the ability to turn tracing on or off.
69 class DALI_CORE_API Filter
74 * Test if trace is enabled for this filter.
75 * @return true if trace is enabled;
77 inline bool IsTraceEnabled() { return mTraceEnabled; }
80 * Enable tracing on this filter.
82 inline void EnableTrace() { mTraceEnabled = true; }
85 * Disable tracing on this filter.
87 inline void DisableTrace() { mTraceEnabled = false; }
90 * Create a new filter whose trace can be modified through the use of an environment variable.
92 * @param[in] trace The default trace level. If true, function tracing is on.
93 * @param[in] environmentVariableName The environment variable name used in order to change the trace.
95 * @info To modify trace at runtime, you should define your filter as shown below:
98 * Trace::Filter* filter = Trace::Filter::New( false, "TRACE_ENV" );
101 * And to use it when running an executable:
103 * TRACE_ENV=1 dali-demo // Trace ON
104 * TRACE_ENV=0 dali-demo // Trace OFF
107 static Filter* New( bool trace, const char * environmentVariableName );
111 * @param[in] tagName - a unique event tag name.
113 void BeginTrace( const char* tagName );
117 * @param[in] tagName - a unique event tag name.
119 void EndTrace( const char* tagName );
122 * Enable trace on all filters.
124 static void EnableGlobalTrace();
127 * Disable trace on all filters.
129 static void DisableGlobalTrace();
135 * @param[in] trace - whether this filter allows tracing.
137 Filter( bool trace ) : mTraceEnabled( trace ) {}
143 /********************************************************************************
145 ********************************************************************************/
148 * These macros allow the instrumentation of methods.
152 * The Tracer object is used by the DALI_TRACE_SCOPE and DALI_TRACE_FUNCTION macros
153 * and uses filter object which in tun routes the tracing via the platform abstraction's LogMessage.
156 class DALI_CORE_API Tracer final
159 Tracer( Filter* filter, const char* tag );
168 * For initialization of trace filter, please use DALI_INIT_TRACE_FILTER macro i.e. DALI_INIT_TRACE_FILTER( gFilter, "TRACE_COMBINED", true );
169 * To start tracing, please use DALI_TRACE_BEGIN macro i.e. DALI_TRACE_BEGIN( gFilter, "RENDERING" );
170 * To end tracing, please use DALI_TRACE_END macro i.e. DALI_TRACE_END( gFilter, "RENDERING" );
171 * For scoped tracing, please use DALI_TRACE_SCOPE macro i.e. DALI_TRACE_SCOPE( gFilter, "RENDERING" );
172 * For function tracing, please use DALI_TRACE_FUNCTION macro i.e. DALI_TRACE_FUNCTION( gFilter );
176 * Initialization of trace filter
179 #define DALI_INIT_TRACE_FILTER( name, environmentVariableName, enable ) \
182 Dali::Integration::Trace::Filter* name = Dali::Integration::Trace::Filter::New( enable, #environmentVariableName ); \
188 #define DALI_TRACE_BEGIN( filter, tag ) \
189 if( filter && filter->IsTraceEnabled() ) { filter->BeginTrace( tag ); }
194 #define DALI_TRACE_END( filter, tag ) \
195 if( filter && filter->IsTraceEnabled() ) { filter->EndTrace( tag ); }
198 * Used for function tracing. It logs tracing of the fuction from start to end.
200 #define DALI_TRACE_FUNCTION( filter ) \
201 Dali::Integration::Trace::Tracer logTraceFunction( filter, ASSERT_LOCATION );
204 * Used for scope tracing. It logs tracing around a scope.
206 #define DALI_TRACE_SCOPE( filter, tag ) \
207 Dali::Integration::Trace::Tracer logTracerScope( filter, tag );
209 #else // TRACE_ENABLED
211 #define DALI_INIT_TRACE_FILTER( name, tag, enable )
212 #define DALI_TRACE_BEGIN( filter, tag )
213 #define DALI_TRACE_END( filter, tag )
214 #define DALI_TRACE_FUNCTION( filter )
215 #define DALI_TRACE_SCOPE( filter, tag )
225 #endif // DALI_INTEGRATION_TRACE_H