[dali_2.3.28] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / trace / tizen / trace-manager-impl-tizen.cpp
1 /*
2  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/trace/tizen/trace-manager-impl-tizen.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <ttrace.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/adaptor-framework/environment-variable.h>
27 #include <dali/internal/system/common/environment-variables.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace Adaptor
34 {
35 namespace
36 {
37 const char* EMPTY_TAG                   = "(null)";
38 static bool gTraceManagerEnablePrintLog = false;
39
40 } // namespace
41
42 TraceManagerTizen::TraceManagerTizen(PerformanceInterface* performanceInterface)
43 : TraceManager(performanceInterface)
44 {
45   const char* enablePrintLog = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_TRACE_ENABLE_PRINT_LOG);
46   if(enablePrintLog && std::atoi(enablePrintLog) != 0)
47   {
48     gTraceManagerEnablePrintLog = true;
49   }
50 }
51
52 Dali::Integration::Trace::LogContextFunction TraceManagerTizen::GetLogContextFunction()
53 {
54   return LogContext;
55 }
56
57 void TraceManagerTizen::LogContext(bool start, const char* tag, const char* message)
58 {
59   if(start)
60   {
61 #ifndef DALI_PROFILE_TV // Avoid HWC log printing in TV
62     traceBegin(TTRACE_TAG_GRAPHICS, tag ? tag : EMPTY_TAG);
63 #endif // DALI_PROFILE_TV
64
65     if(gTraceManagerEnablePrintLog)
66     {
67       DALI_LOG_DEBUG_INFO("BEGIN: %s%s%s\n", tag ? tag : EMPTY_TAG, message ? " " : "", message ? message : "");
68     }
69   }
70   else
71   {
72 #ifndef DALI_PROFILE_TV // Avoid HWC log printing in TV
73     traceEnd(TTRACE_TAG_GRAPHICS);
74 #endif // DALI_PROFILE_TV
75
76     if(gTraceManagerEnablePrintLog)
77     {
78       DALI_LOG_DEBUG_INFO("END: %s%s%s\n", tag ? tag : EMPTY_TAG, message ? " " : "", message ? message : "");
79     }
80   }
81 }
82
83 } // namespace Adaptor
84
85 } // namespace Internal
86
87 } // namespace Dali