1 #ifndef DALI_INTEGRATION_TRACE_H
2 #define DALI_INTEGRATION_TRACE_H
5 * Copyright (c) 2020 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>
34 * Used by tracing macros to log a context message
35 * @param start a bool to indicate start (true) or end (false) of the tracing / logging
36 * @param tag a unique event tag name
38 DALI_CORE_API void LogContext(bool start, const char* tag);
41 * typedef for the LogContextFunction function.
43 using LogContextFunction = void (*)(bool, const char*);
46 * A LogContextFunction function has to be installed for every thread that wants to use tracing.
47 * This should be done by the adaptor.
48 * The LogContextFunction function can be different for each thread.
49 * @param LogContextFunction the Log Context function to install
51 DALI_CORE_API void InstallLogContextFunction(const LogContextFunction& logContextFunction);
53 /********************************************************************************
55 ********************************************************************************/
60 * The Filter object is used by the DALI_TRACE_BEGIN macro and others to determine if the tracing
61 * should take place, and routes the tracing via the platform abstraction's LogMessage.
63 * It provides the ability to turn tracing on or off.
66 class DALI_CORE_API Filter
70 * Test if trace is enabled for this filter.
71 * @return true if trace is enabled;
73 inline bool IsTraceEnabled()
79 * Enable tracing on this filter.
81 inline void EnableTrace()
87 * Disable tracing on this filter.
89 inline void DisableTrace()
91 mTraceEnabled = false;
95 * Create a new filter whose trace can be modified through the use of an environment variable.
97 * @param[in] trace The default trace level. If true, function tracing is on.
98 * @param[in] environmentVariableName The environment variable name used in order to change the trace.
100 * @info To modify trace at runtime, you should define your filter as shown below:
103 * Trace::Filter* filter = Trace::Filter::New( false, "TRACE_ENV" );
106 * And to use it when running an executable:
108 * TRACE_ENV=1 dali-demo // Trace ON
109 * TRACE_ENV=0 dali-demo // Trace OFF
112 static Filter* New(bool trace, const char* environmentVariableName);
116 * @param[in] tagName - a unique event tag name.
118 void BeginTrace(const char* tagName);
122 * @param[in] tagName - a unique event tag name.
124 void EndTrace(const char* tagName);
127 * Enable trace on all filters.
129 static void EnableGlobalTrace();
132 * Disable trace on all filters.
134 static void DisableGlobalTrace();
139 * @param[in] trace - whether this filter allows tracing.
142 : mTraceEnabled(trace)
150 /********************************************************************************
152 ********************************************************************************/
155 * These macros allow the instrumentation of methods.
159 * The Tracer object is used by the DALI_TRACE_SCOPE and DALI_TRACE_FUNCTION macros
160 * and uses filter object which in tun routes the tracing via the platform abstraction's LogMessage.
163 class DALI_CORE_API Tracer final
166 Tracer(Filter* filter, const char* tag);
175 * For initialization of trace filter, please use DALI_INIT_TRACE_FILTER macro i.e. DALI_INIT_TRACE_FILTER( gFilter, "TRACE_COMBINED", true );
176 * To start tracing, please use DALI_TRACE_BEGIN macro i.e. DALI_TRACE_BEGIN( gFilter, "RENDERING" );
177 * To end tracing, please use DALI_TRACE_END macro i.e. DALI_TRACE_END( gFilter, "RENDERING" );
178 * For scoped tracing, please use DALI_TRACE_SCOPE macro i.e. DALI_TRACE_SCOPE( gFilter, "RENDERING" );
179 * For function tracing, please use DALI_TRACE_FUNCTION macro i.e. DALI_TRACE_FUNCTION( gFilter );
183 * Initialization of trace filter
186 #define DALI_INIT_TRACE_FILTER(name, environmentVariableName, enable) \
189 Dali::Integration::Trace::Filter* name = Dali::Integration::Trace::Filter::New(enable, #environmentVariableName); \
195 #define DALI_TRACE_BEGIN(filter, tag) \
196 if(filter && filter->IsTraceEnabled()) \
198 filter->BeginTrace(tag); \
204 #define DALI_TRACE_END(filter, tag) \
205 if(filter && filter->IsTraceEnabled()) \
207 filter->EndTrace(tag); \
211 * Used for function tracing. It logs tracing of the fuction from start to end.
213 #define DALI_TRACE_FUNCTION(filter) \
214 Dali::Integration::Trace::Tracer logTraceFunction(filter, ASSERT_LOCATION);
217 * Used for scope tracing. It logs tracing around a scope.
219 #define DALI_TRACE_SCOPE(filter, tag) \
220 Dali::Integration::Trace::Tracer logTracerScope(filter, tag);
222 #else // TRACE_ENABLED
224 #define DALI_INIT_TRACE_FILTER(name, tag, enable)
225 #define DALI_TRACE_BEGIN(filter, tag)
226 #define DALI_TRACE_END(filter, tag)
227 #define DALI_TRACE_FUNCTION(filter)
228 #define DALI_TRACE_SCOPE(filter, tag)
234 } // namespace Integration
238 #endif // DALI_INTEGRATION_TRACE_H