Added thread safe ttrace support 28/37428/8
authorNick Holland <nick.holland@partner.samsung.com>
Thu, 26 Mar 2015 11:27:34 +0000 (11:27 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Wed, 15 Apr 2015 06:18:44 +0000 (23:18 -0700)
To enable:

DALI_PERFORMANCE_TIMESTAMP_OUTPUT=4 dali-demo

If ttrace is not part of the build environment it will fall back on using
DALi log.
Without ttrace enabled Output will look like:

INFO: DALI: AsyncBegin: UPDATE : cookie -739011608
INFO: DALI: AsyncEnd: UPDATE : cookie -739011608
INFO: DALI: Marker: V_SYNC
INFO: DALI: Marker: V_SYNC
INFO: DALI: Marker: V_SYNC
INFO: DALI: Marker: V_SYNC
INFO: DALI: AsyncBegin: PROCESS_EVENT : cookie -172927739
INFO: DALI: AsyncEnd: PROCESS_EVENT : cookie -172927739
INFO: DALI: AsyncEnd: RENDER : cookie -869100763
INFO: DALI: AsyncBegin: RENDER : cookie -869100763
INFO: DALI: Marker: V_SYNC
INFO: DALI: AsyncBegin: UPDATE : cookie -739011608
INFO: DALI: AsyncEnd: UPDATE : cookie -739011608
INFO: DALI: AsyncBegin: PROCESS_EVENT : cookie -172927739
INFO: DALI: AsyncEnd: PROCESS_EVENT : cookie -172927739

To log custom markers in an application...
PerformanceLogger logger = PerformanceLogger::New("MyMarker");

logger.AddMarker(PerformanceLogger::START_EVENT);
// do stuff
logger.AddMarker(PerformanceLogger::END_EVENT);

Documentation for this patch is included in shared markdown file:
https://review.tizen.org/gerrit/#/c/37690/

Change-Id: I17b4e99399d4bdb9001f8a9bdf5b690865722b02

15 files changed:
adaptors/base/interfaces/adaptor-internal-services.h
adaptors/base/interfaces/performance-interface.h
adaptors/base/interfaces/trace-interface.h [moved from adaptors/base/interfaces/kernel-trace-interface.h with 60% similarity]
adaptors/base/performance-logging/performance-marker.cpp
adaptors/base/performance-logging/performance-marker.h
adaptors/base/performance-logging/performance-server.cpp
adaptors/base/performance-logging/performance-server.h
adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h
adaptors/common/file.list
adaptors/common/kernel-trace.cpp
adaptors/common/kernel-trace.h
adaptors/common/system-trace.cpp [new file with mode: 0644]
adaptors/common/system-trace.h [new file with mode: 0644]
build/tizen/configure.ac

index e0915e0..109c41a 100644 (file)
@@ -29,7 +29,7 @@
 #include <base/interfaces/socket-factory-interface.h>
 #include <base/interfaces/performance-interface.h>
 #include <base/interfaces/vsync-monitor-interface.h>
-#include <base/interfaces/kernel-trace-interface.h>
+#include <base/interfaces/trace-interface.h>
 #include <render-surface.h>
 
 
@@ -104,9 +104,15 @@ public:
   virtual PerformanceInterface* GetPerformanceInterface()  = 0;
 
   /**
-   * @return kernel trace interface
+   * @return interface for logging to the kernel ( e.g. using ftrace )
    */
-  virtual KernelTraceInterface& GetKernelTraceInterface()  = 0;
+  virtual TraceInterface& GetKernelTraceInterface()  = 0;
+
+  /**
+   * @return system trace interface, e.g. for using Tizen Trace (ttrace) or Android Trace (atrace)
+   */
+  virtual TraceInterface& GetSystemTraceInterface()  = 0;
+
 
 protected:
 
index a90584f..0732d10 100644 (file)
@@ -57,7 +57,8 @@ public:
   };
 
   /**
-   * bitmask of time stamp output options
+   * bitmask of time stamp output options.
+   * E.g. DALI_PERFORMANCE_TIMESTAMP_OUTPUT = 1 dali-demo
    * Used for logging out time stamped markers for detailed analysis (see MarkerType, for the markers logged)
    * Typical output would look like:
    *   379.059025 (seconds), V_SYNC
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_BASE_KERNEL_TRACE_INTERFACE_H__
-#define __DALI_INTERNAL_BASE_KERNEL_TRACE_INTERFACE_H__
+#ifndef __DALI_INTERNAL_BASE_TRACE_INTERFACE_H__
+#define __DALI_INTERNAL_BASE_TRACE_INTERFACE_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
  *
  */
 
+// EXTERNAL INCLUDES
 #include <string>
 
+
+// INTERNAL INCLUDES
+#include <base/performance-logging/performance-marker.h>
+
 namespace Dali
 {
 
@@ -30,43 +35,44 @@ namespace Adaptor
 {
 
 /**
- * Abstract Kernel Tracing Interface.
- * Used to log trace messages to the kernel.
- * E.g. On Linux this will use ftrace
+ * Abstract Tracing Interface.
+ * Used to log trace messages.
+ * E.g. On Linux this may use ftrace
  *
  */
-class KernelTraceInterface
+class TraceInterface
 {
 
 public:
 
   /**
    * Write a trace message
+   * @param marker performance marker
    * @param traceMessage trace message
    */
-  virtual void Trace( const std::string& traceMessage ) = 0;
+  virtual void Trace( const PerformanceMarker& marker, const std::string& traceMessage ) = 0;
 
 protected:
 
   /**
    * Constructor
    */
-  KernelTraceInterface()
+  TraceInterface()
   {
   }
 
   /**
    * virtual destructor
    */
-  virtual ~KernelTraceInterface()
+  virtual ~TraceInterface()
   {
   }
 
   // Undefined copy constructor.
-  KernelTraceInterface( const KernelTraceInterface& );
+  TraceInterface( const TraceInterface& );
 
   // Undefined assignment operator.
-  KernelTraceInterface& operator=( const KernelTraceInterface& );
+  TraceInterface& operator=( const TraceInterface& );
 };
 
 } // namespace Internal
index 72b1f83..05b3258 100644 (file)
@@ -45,6 +45,9 @@ struct NamePair
 
 const NamePair MARKER_LOOKUP[] =
 {
+    // timed event names must be postfixed with with _START and _END
+    // this is to allow tracers to extract the event name by removing the _START, _END strings
+    //
     { PerformanceInterface::VSYNC       ,         "V_SYNC"               , PerformanceMarker::V_SYNC_EVENTS, PerformanceMarker::SINGLE_EVENT      },
     { PerformanceInterface::UPDATE_START ,        "UPDATE_START"         , PerformanceMarker::UPDATE,        PerformanceMarker::START_TIMED_EVENT },
     { PerformanceInterface::UPDATE_END   ,        "UPDATE_END"           , PerformanceMarker::UPDATE,        PerformanceMarker::END_TIMED_EVENT   },
@@ -84,6 +87,11 @@ PerformanceMarker::MarkerEventType PerformanceMarker::GetEventType() const
   return MARKER_LOOKUP[ mType ].eventType;
 }
 
+PerformanceMarker::MarkerFilter PerformanceMarker::GetFilterType() const
+{
+  return MARKER_LOOKUP[ mType ].group;
+}
+
 unsigned int PerformanceMarker::MicrosecondDiff( const PerformanceMarker& start,const PerformanceMarker& end )
 {
   return FrameTimeStamp::MicrosecondDiff( start.mTimeStamp, end.mTimeStamp );
index b6ac794..9651770 100644 (file)
@@ -103,6 +103,12 @@ public:
   MarkerEventType GetEventType() const;
 
   /**
+   * @return the filter type of marker
+   */
+  MarkerFilter GetFilterType() const;
+
+
+  /**
    * @return marker name
    */
   const char* const GetName( ) const;
index 8b9f9ee..1984304 100644 (file)
@@ -38,6 +38,7 @@ PerformanceServer::PerformanceServer( AdaptorInternalServices& adaptorServices,
 :mPlatformAbstraction( adaptorServices.GetPlatformAbstractionInterface() ),
  mEnvironmentOptions( environmentOptions ),
  mKernelTrace( adaptorServices.GetKernelTraceInterface() ),
+ mSystemTrace( adaptorServices.GetSystemTraceInterface() ),
  mNetworkServer( adaptorServices, environmentOptions ),
  mStatContextManager( *this ),
  mStatisticsLogBitmask( 0 ),
@@ -197,8 +198,14 @@ void PerformanceServer::LogMarker( const PerformanceMarker& marker, const char*
   // log to kernel trace
   if( mPerformanceOutputBitmask & OUTPUT_KERNEL_TRACE )
   {
-    // name will be something like UPDATE_START or UPDATE_END
-    mKernelTrace.Trace( description );
+    // description will be something like UPDATE_START or UPDATE_END
+    mKernelTrace.Trace( marker, description );
+  }
+
+  // log to system trace
+  if( mPerformanceOutputBitmask & OUTPUT_SYSTEM_TRACE )
+  {
+    mSystemTrace.Trace( marker, description );
   }
 
   // log to Dali log
index 9965270..b3b5062 100644 (file)
@@ -118,7 +118,8 @@ private:
 
   Integration::PlatformAbstraction& mPlatformAbstraction; ///< platform abstraction
   const EnvironmentOptions& mEnvironmentOptions;          ///< environment options
-  KernelTraceInterface& mKernelTrace;                     ///< kernel trace interface
+  TraceInterface& mKernelTrace;                           ///< kernel trace interface
+  TraceInterface& mSystemTrace;                           ///< system trace interface
   boost::mutex mDataMutex;                                ///< mutex
   NetworkPerformanceServer mNetworkServer;                ///< network server
   StatContextManager mStatContextManager;                 ///< Stat context manager
index 2b20264..b8eee04 100644 (file)
@@ -696,11 +696,16 @@ VSyncMonitorInterface* Adaptor::GetVSyncMonitorInterface()
   return mVSyncMonitor;
 }
 
-KernelTraceInterface& Adaptor::GetKernelTraceInterface()
+TraceInterface& Adaptor::GetKernelTraceInterface()
 {
   return mKernelTracer;
 }
 
+TraceInterface& Adaptor::GetSystemTraceInterface()
+{
+  return mSystemTracer;
+}
+
 PerformanceInterface* Adaptor::GetPerformanceInterface()
 {
   return mPerformanceInterface;
index e9fd4bf..fa29310 100644 (file)
@@ -41,6 +41,7 @@
 #include <damage-observer.h>
 #include <window-visibility-observer.h>
 #include <kernel-trace.h>
+#include <system-trace.h>
 #include <trigger-event-factory.h>
 #include <networking/socket-factory.h>
 
@@ -350,7 +351,12 @@ public:  //AdaptorInternalServices
   /**
    * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetKernelTraceInterface()
    */
-  virtual KernelTraceInterface& GetKernelTraceInterface();
+  virtual TraceInterface& GetKernelTraceInterface();
+
+  /**
+   * copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetSystemTraceInterface()
+   */
+  virtual TraceInterface& GetSystemTraceInterface();
 
 public: // Stereoscopy
 
@@ -530,6 +536,7 @@ private: // Data
   EnvironmentOptions                    mEnvironmentOptions;          ///< environment options
   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
   KernelTrace                           mKernelTracer;                ///< Kernel tracer
+  SystemTrace                           mSystemTracer;                ///< System tracer
   TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
   ObjectProfiler*                       mObjectProfiler;              ///< Tracks object lifetime for profiling
   SocketFactory                         mSocketFactory;               ///< Socket factory
index d1f07af..5cd748c 100644 (file)
@@ -13,9 +13,10 @@ adaptor_common_internal_src_files = \
   $(adaptor_common_dir)/ecore-callback-manager.cpp \
   $(adaptor_common_dir)/file-descriptor-monitor.cpp \
   $(adaptor_common_dir)/haptic-player-impl.cpp \
-  $(adaptor_common_dir)/indicator-impl.cpp  \
-  $(adaptor_common_dir)/indicator-buffer.cpp  \
-  $(adaptor_common_dir)/kernel-trace.cpp  \
+  $(adaptor_common_dir)/indicator-impl.cpp \
+  $(adaptor_common_dir)/indicator-buffer.cpp \
+  $(adaptor_common_dir)/kernel-trace.cpp \
+  $(adaptor_common_dir)/system-trace.cpp \
   $(adaptor_common_dir)/lifecycle-controller-impl.cpp \
   $(adaptor_common_dir)/locale-utils.cpp  \
   $(adaptor_common_dir)/native-bitmap-buffer-impl.cpp \
index 8e9404b..e654fc8 100644 (file)
@@ -68,7 +68,7 @@ KernelTrace::~KernelTrace()
 // If the message did not get added to the trace, then check you have write permissions to the trace_marker file.
 //
 //
-void KernelTrace::Trace( const std::string& traceMessage )
+void KernelTrace::Trace( const PerformanceMarker& marker, const std::string& traceMessage )
 {
   // Open the trace_marker file
   if( mFileDescriptor == 0 )
index 654426d..89722c5 100644 (file)
@@ -18,7 +18,7 @@
  *
  */
 
-#include <base/interfaces/kernel-trace-interface.h>
+#include <base/interfaces/trace-interface.h>
 
 namespace Dali
 {
@@ -34,7 +34,7 @@ namespace Adaptor
  * Used to log trace messages to the kernel using ftrace.
  *
  */
-class KernelTrace : public KernelTraceInterface
+class KernelTrace : public TraceInterface
 {
 public:
 
@@ -51,7 +51,7 @@ public:
   /**
    * @copydoc KernelTracerInterface::KernelTrace()
    */
-  virtual void Trace( const std::string& traceMessage );
+  virtual void Trace( const PerformanceMarker& marker, const std::string& traceMessage );
 
 private:
 
diff --git a/adaptors/common/system-trace.cpp b/adaptors/common/system-trace.cpp
new file mode 100644 (file)
index 0000000..967520e
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "system-trace.h"
+
+// EXTERNAL HEADERS
+#include <string>
+#include <dali/public-api/common/hash.h>
+
+// INTERNAL HEADERS
+#include <dali/integration-api/debug.h>
+
+#ifdef ENABLE_TTRACE
+#include <ttrace.h>
+#else
+
+// Emulate trace calls if ttrace isn't available
+namespace
+{
+const int TTRACE_TAG_GRAPHICS = 1;
+
+void traceAsyncBegin(int tag, int cookie, const char *name, ...)
+{
+  Debug::LogMessage(Debug::DebugInfo, "AsyncBegin: %s : cookie %d\n", name, cookie );
+}
+void traceAsyncEnd(int tag, int cookie, const char *name, ...)
+{
+  Debug::LogMessage(Debug::DebugInfo, "AsyncEnd: %s : cookie %d\n", name, cookie );
+}
+void traceMark(int tag, const char *name, ...)
+{
+  Debug::LogMessage(Debug::DebugInfo, "Marker: %s \n", name);
+}
+} // un-named namespace
+#endif
+
+namespace
+{
+
+int GetCookie( const std::string& description, std::string& markerName )
+{
+  // description holds the marker name and postfix of _START or _END
+  std::size_t pos = description.find("_START");
+  if( pos == std::string::npos )
+  {
+    pos = description.find("_END");
+  }
+  if( !pos )
+  {
+    // if this asserts then check the postfix strings in StatContext.cpp for
+    // custom markers and performance-marker.cpp for built-in markers
+    DALI_ASSERT_DEBUG(0);
+  }
+  markerName = description.substr( 0, pos );
+
+  std::size_t hash =  Dali::CalculateHash( markerName.c_str() );
+  return static_cast<int>( hash );
+}
+}
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+SystemTrace::SystemTrace()
+{
+}
+SystemTrace::~SystemTrace()
+{
+}
+
+void SystemTrace::Trace( const PerformanceMarker& marker, const std::string& traceMessage )
+{
+  PerformanceMarker::MarkerEventType eventType = marker.GetEventType();
+
+  if( eventType == PerformanceMarker::SINGLE_EVENT )
+  {
+    traceMark( TTRACE_TAG_GRAPHICS, traceMessage.c_str() );
+    return;
+  }
+
+  // DALi is multi-threaded so timed events will occur asynchronously
+  std::string markerName;
+
+  int cookie = GetCookie(traceMessage, markerName );
+
+  if( eventType == PerformanceMarker::START_TIMED_EVENT )
+  {
+    traceAsyncBegin( TTRACE_TAG_GRAPHICS, cookie,  markerName.c_str() );
+  }
+  else
+  {
+    traceAsyncEnd( TTRACE_TAG_GRAPHICS, cookie,  markerName.c_str() );
+  }
+}
+
+} // namespace Internal
+
+} // namespace Adaptor
+
+} // namespace Dali
+
diff --git a/adaptors/common/system-trace.h b/adaptors/common/system-trace.h
new file mode 100644 (file)
index 0000000..32de01e
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef __DALI_INTERNAL_ADAPTOR_SYSTEM_TRACE_H__
+#define __DALI_INTERNAL_ADAPTOR_SYSTEM_TRACE_H__
+
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <base/interfaces/trace-interface.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+/**
+ * Concrete System  Tracing Interface.
+ * Used to log trace messages to the system using ttrace
+ *
+ */
+class SystemTrace : public TraceInterface
+{
+public:
+
+  /**
+   * Constructor
+   */
+  SystemTrace();
+
+  /**
+   * Destructor
+   */
+  virtual ~SystemTrace();
+
+  /**
+   * @copydoc KernelTracerInterface::KernelTrace()
+   */
+  virtual void Trace( const PerformanceMarker& marker, const std::string& traceMessage );
+
+};
+
+} // namespace Internal
+
+} // namespace Adaptor
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_ADAPTOR_SYSTEM_TRACE_H__
index 83a8467..a42e237 100644 (file)
@@ -47,6 +47,9 @@ PKG_CHECK_MODULES(LIBDRM, libdrm)
 PKG_CHECK_MODULES(LIBCURL, libcurl)
 PKG_CHECK_MODULES(HARFBUZZ, harfbuzz)
 PKG_CHECK_MODULES(FRIBIDI, fribidi)
+PKG_CHECK_MODULES(TTRACE,  ttrace, AC_DEFINE(ENABLE_TTRACE, 1, [ttrace available]),
+                  [ AC_MSG_NOTICE([Tizen Trace not avaiable]) ]
+                  )
 
 # Check for availability of BulletPhysics
 PKG_CHECK_EXISTS(bullet, [