[dali_1.2.60] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / integration-api / debug.cpp
index 8d4d60f..11b5c35 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -25,6 +25,7 @@
 #include <cstdlib>
 #include <sstream>
 #include <iomanip>
+#include <ctime>
 
 // INTERNAL INCLUDES
 #include <dali/public-api/common/constants.h>
 namespace Dali
 {
 
+#ifdef DEBUG_ENABLED
+
+// Fake globals for gdb typedefs
+Dali::DebugPropertyValueArray gValueArray;
+Dali::DebugPropertyValueMap   gValueMap;
+
+#endif
+
+
 namespace // unnamed namespace
 {
 
+const uint64_t NANOSECONDS_PER_SECOND = 1e+9;
+
 /**
  * Generic function to print out any 2-Dimensional array
  * @param[in] data pointer to the source data stored as float[rows][cols]
@@ -82,7 +94,7 @@ namespace Integration
 namespace Log
 {
 
-__thread LogFunction gthreadLocalLogFunction = NULL;
+thread_local LogFunction gthreadLocalLogFunction = NULL;
 
 /* Forward declarations */
 std::string FormatToString(const char *format, ...);
@@ -129,7 +141,6 @@ Filter* Filter::gNode       = NULL;
 Filter* Filter::gElement    = NULL;
 Filter* Filter::gActor      = Filter::New(Debug::Concise, false, "LOG_ACTOR");
 Filter* Filter::gShader     = Filter::New(Debug::Concise, false, "LOG_SHADER");
-Filter* Filter::gDynamics   = Filter::New(Debug::Concise, false, "LOG_DYNAMICS");
 
 Filter::FilterList* Filter::GetActiveFilters()
 {
@@ -199,13 +210,21 @@ void Filter::Log(LogLevel level, const char* format, ...)
     va_list arg;
     va_start(arg, format);
 
-    char *buffer = NULL;
-    int numChars = asprintf(&buffer, "%-*c %s", mNesting, ':', format);
-    if(numChars >= 0) // No error
+    if( mTraceEnabled )
     {
-      std::string message = ArgListToString(buffer, arg);
-      LogMessage(DebugInfo, message.c_str());
-      free(buffer);
+      char *buffer = NULL;
+      int numChars = asprintf( &buffer, "    %-*c %s", mNesting, ':', format );
+      if( numChars >= 0 ) // No error
+      {
+        std::string message = ArgListToString( buffer, arg );
+        LogMessage( DebugInfo, message.c_str() );
+        free( buffer );
+      }
+    }
+    else
+    {
+      std::string message = ArgListToString( format, arg );
+      LogMessage( DebugInfo, message.c_str() );
     }
     va_end(arg);
   }
@@ -299,11 +318,11 @@ std::string QuaternionToString(const Quaternion& q, size_t precision, size_t ind
   std::ostringstream oss;
 
   Vector3 axis;
-  float angle;
+  Radian angle;
   q.ToAxisAngle(axis, angle);
 
   oss << std::setw(indent+3) << std::setfill(' ') << std::setprecision(precision) << std::right;
-  oss << "<A:" << std::setw(precision+4) << angle * 180.0 / Math::PI << ", " << Vector3ToString(axis, precision, 0) << ">";
+  oss << "<A:" << std::setw(precision+4) << Degree( angle ).degree << ", " << Vector3ToString(axis, precision, 0) << ">";
 
   return oss.str();
 }
@@ -318,6 +337,15 @@ std::string MatrixToString(const Matrix& m, size_t precision, size_t indent)
   return Array2DToString(m.AsFloat(), 4, 4, precision, indent);
 }
 
+void GetNanoseconds( uint64_t& timeInNanoseconds )
+{
+  timespec timeSpec;
+  clock_gettime( CLOCK_MONOTONIC, &timeSpec );
+
+  // Convert all values to uint64_t to match our return type
+  timeInNanoseconds = ( static_cast< uint64_t >( timeSpec.tv_sec ) * NANOSECONDS_PER_SECOND ) + static_cast< uint64_t >( timeSpec.tv_nsec );
+}
+
 } // namespace Log
 
 } // namespace Integration