Trace use scope macro instead of begin-end
[platform/core/uifw/dali-adaptor.git] / dali / internal / trace / tizen / trace-manager-impl-tizen.cpp
index 9095bcf..3c8ea30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
+// CLASS HEADER
+#include <dali/internal/trace/tizen/trace-manager-impl-tizen.h>
+
 // EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
 #include <ttrace.h>
-#include <dali/internal/trace/tizen/trace-manager-impl-tizen.h>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
 
 namespace Dali
 {
-
 namespace Internal
 {
-
 namespace Adaptor
 {
+namespace
+{
+const char* DALI_TRACE_ENABLE_PRINT_LOG_ENV = "DALI_TRACE_ENABLE_PRINT_LOG";
+const char* EMPTY_TAG                       = "(null)";
+static bool gTraceManagerEnablePrintLog     = false;
 
-TraceManagerTizen::TraceManagerTizen( PerformanceInterface* performanceInterface )
-: TraceManager( performanceInterface )
+} // namespace
+
+TraceManagerTizen::TraceManagerTizen(PerformanceInterface* performanceInterface)
+: TraceManager(performanceInterface)
 {
+  const char* enablePrintLog = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_TRACE_ENABLE_PRINT_LOG_ENV);
+  if(enablePrintLog && std::atoi(enablePrintLog) != 0)
+  {
+    gTraceManagerEnablePrintLog = true;
+  }
 }
 
 Dali::Integration::Trace::LogContextFunction TraceManagerTizen::GetLogContextFunction()
@@ -40,15 +54,25 @@ Dali::Integration::Trace::LogContextFunction TraceManagerTizen::GetLogContextFun
   return LogContext;
 }
 
-void TraceManagerTizen::LogContext( bool start, const char* tag )
+void TraceManagerTizen::LogContext(bool start, const char* tag)
 {
-  if( start )
+  if(start)
   {
-    traceBegin( TTRACE_TAG_GRAPHICS, tag );
+    traceBegin(TTRACE_TAG_GRAPHICS, tag ? tag : EMPTY_TAG);
+
+    if(gTraceManagerEnablePrintLog)
+    {
+      DALI_LOG_DEBUG_INFO("BEGIN: %s\n", tag ? tag : EMPTY_TAG);
+    }
   }
   else
   {
-    traceEnd( TTRACE_TAG_GRAPHICS );
+    traceEnd(TTRACE_TAG_GRAPHICS);
+
+    if(gTraceManagerEnablePrintLog)
+    {
+      DALI_LOG_DEBUG_INFO("END: %s\n", tag ? tag : EMPTY_TAG);
+    }
   }
 }