2 * Copyright (c) 2020 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>
31 thread_local LogContextFunction gThreadLocalLogContextFunction = nullptr;
33 void InstallLogContextFunction(const LogContextFunction& logContextFunction)
35 gThreadLocalLogContextFunction = logContextFunction;
38 void LogContext(bool start, const char* tag)
40 if(!gThreadLocalLogContextFunction)
44 gThreadLocalLogContextFunction(start, tag);
49 typedef std::list<Filter*> FilterList;
50 typedef std::list<Filter*>::iterator FilterIter;
54 static FilterList* GetActiveFilters()
56 static FilterList* activeFilters = new FilterList;
61 Filter* Filter::New(bool trace, const char* environmentVariableName)
63 char* environmentVariableValue = getenv(environmentVariableName);
64 if(environmentVariableValue)
66 char envTraceString(0);
67 sscanf(environmentVariableValue, "%c", &envTraceString);
69 // Just use 'f' and 't' as it's faster than doing full string comparisons
70 if(envTraceString == 't')
74 else if(envTraceString == 'f')
80 Filter* filter = new Filter(trace);
81 GetActiveFilters()->push_back(filter);
86 * Enable trace on all filters.
88 void Filter::EnableGlobalTrace()
90 for(FilterIter iter = GetActiveFilters()->begin(); iter != GetActiveFilters()->end(); iter++)
92 (*iter)->EnableTrace();
97 * Disable trace on all filters.
99 void Filter::DisableGlobalTrace()
101 for(FilterIter iter = GetActiveFilters()->begin(); iter != GetActiveFilters()->end(); iter++)
103 (*iter)->DisableTrace();
110 void Filter::BeginTrace(const char* tagName)
112 Dali::Integration::Trace::LogContext(true, tagName);
118 void Filter::EndTrace(const char* tagName)
120 Dali::Integration::Trace::LogContext(false, tagName);
126 Tracer::Tracer(Filter* filter, const char* tag)
130 if(mFilter && mFilter->IsTraceEnabled())
132 mFilter->BeginTrace(mTag);
141 if(mFilter && mFilter->IsTraceEnabled())
143 mFilter->EndTrace(mTag);
147 #endif //TRACE_ENABLED
151 } // namespace Integration