Fixed bug in host trace logging 23/187523/2
authorDavid Steele <david.steele@samsung.com>
Thu, 23 Aug 2018 20:26:11 +0000 (21:26 +0100)
committerDavid Steele <david.steele@samsung.com>
Wed, 16 Nov 2022 15:52:11 +0000 (15:52 +0000)
Trace macros in Ubuntu were not using the server context properly, so asserted after
65536 frames.

Added a getter to the stat-context-manager to get contexts by name, then utilized this
to add custom markers for tracing code.

(Trace macros are turned off by default, so they don't affect performance)

Enable by re-configuring with --enable-trace or gbs build --define "enable_trace 1"
in dali-core and dali-adaptor.

On desktop, also re-configure dali-adaptor with --enable-networklogging, and
run with DALI_NETWORK_CONTROL=3. Connect to the server using "nc localhost 3031"
and type "set_marker 131" to enable Update/Render/Custom trace.

On target, custom tags are sent to ttrace.

Change-Id: Iaff816f33c6c6034629759d1727a520a5cf5faf1
Signed-off-by: David Steele <david.steele@samsung.com>
dali/internal/system/common/performance-interface.h
dali/internal/system/common/performance-server.cpp
dali/internal/system/common/performance-server.h
dali/internal/system/common/stat-context-manager.cpp
dali/internal/system/common/stat-context-manager.h
dali/internal/trace/generic/trace-manager-impl-generic.cpp

index 19c3e1a..c138a29 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_BASE_PERFORMANCE_INTERFACE_H
 
 /*
- * Copyright (c) 2021 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.
@@ -118,6 +118,14 @@ public:
   virtual ContextId AddContext(const char* name) = 0;
 
   /**
+   * @brief Get the context for a custom name.
+   *
+   * @param[in] name The name of the context
+   * @return Return the unique id for this context
+   */
+  virtual ContextId GetContextId( const char* name ) = 0;
+
+  /**
    * @brief Remove a context from use
    *
    * @param[in] contextId The ID of the context to remove
index 21f77a6..4f85519 100644 (file)
@@ -116,6 +116,12 @@ PerformanceInterface::ContextId PerformanceServer::AddContext(const char* name)
   return mStatContextManager.AddContext(name, PerformanceMarker::CUSTOM_EVENTS);
 }
 
+PerformanceInterface::ContextId PerformanceServer::GetContextId( const char* name )
+{
+  // for adding custom contexts
+  return mStatContextManager.GetContextId( name );
+}
+
 void PerformanceServer::RemoveContext(ContextId contextId)
 {
   mStatContextManager.RemoveContext(contextId);
index f4aaf15..88e669a 100644 (file)
@@ -64,6 +64,11 @@ public:
   ContextId AddContext(const char* name) override;
 
   /**
+   * @copydoc PerformanceLogger::GetContextId()
+   */
+  virtual ContextId GetContextId( const char* name );
+
+  /**
    * @copydoc PerformanceLogger::RemoveContext()
    */
   void RemoveContext(ContextId contextId) override;
index 24e7028..cceb07a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -58,10 +58,11 @@ StatContextManager::~StatContextManager()
   }
   mStatContexts.Clear();
 }
+
 PerformanceInterface::ContextId StatContextManager::AddContext(const char* const               name,
                                                                PerformanceMarker::MarkerFilter type)
 {
-  unsigned int contextId = mNextContextId++;
+  unsigned int contextId = ++mNextContextId;
 
   DALI_ASSERT_DEBUG(NULL == GetContext(contextId));
 
@@ -178,6 +179,24 @@ const char* StatContextManager::GetContextName(PerformanceInterface::ContextId c
   return "context not found";
 }
 
+PerformanceInterface::ContextId StatContextManager::GetContextId(const char* name) const
+{
+  std::string match(name);
+
+  for( StatContexts::Iterator it = mStatContexts.Begin(), itEnd = mStatContexts.End(); it != itEnd; ++it )
+  {
+    StatContext* context = *it;
+
+    std::string contextName( context->GetName() );
+    if( contextName.compare(match) == 0 )
+    {
+      return context->GetId();
+    }
+  }
+  return 0;
+}
+
+
 const char* StatContextManager::GetMarkerDescription(PerformanceInterface::MarkerType type, PerformanceInterface::ContextId contextId) const
 {
   StatContext* context = GetContext(contextId);
index 9f82ab5..337b270 100644 (file)
@@ -50,105 +50,112 @@ class StatContextManager
 {
 public:
   /**
-     * @brief Constructor
-     * @param[in] logInterface interface to log statistics to
-     */
-  StatContextManager(StatContextLogInterface& logInterface);
+   * @brief Constructor
+   * @param[in] logInterface interface to log statistics to
+   */
+    StatContextManager( StatContextLogInterface& logInterface );
 
   /**
-     * @brief destructor, not intended as a bass class
-     */
+   * @brief destructor, not intended as a bass class
+   */
   ~StatContextManager();
 
   /**
-     * @brief Add a context
-     * @param[in] name Name of the context to print in console
-     * @param[in] type the type of events to filter ( e.g. event, update, render or custom)
-     * @return The ID to give the context
-     */
-  PerformanceInterface::ContextId AddContext(const char* const name, PerformanceMarker::MarkerFilter type);
+   * @brief Add a context
+   * @param[in] name Name of the context to print in console
+   * @param[in] type the type of events to filter ( e.g. event, update, render or custom)
+   * @return The ID to give the context
+   */
+  PerformanceInterface::ContextId AddContext( const char* const name, PerformanceMarker::MarkerFilter type );
 
   /**
-     * @brief Remove a context
-     * @param[in] contextId id of the context to remove
-     */
-  void RemoveContext(PerformanceInterface::ContextId contextId);
+   * @brief Remove a context
+   * @param[in] contextId id of the context to remove
+   */
+  void RemoveContext(PerformanceInterface::ContextId contextId );
 
   /**
-     * @brief Add an internal marker (e.g. v-sync, update, render markers)
-     * @param[in] marker the marker to add
-     */
-  void AddInternalMarker(const PerformanceMarker& marker);
+   * @brief Add an internal marker (e.g. v-sync, update, render markers)
+   * @param[in] marker the marker to add
+   */
+  void AddInternalMarker( const PerformanceMarker& marker );
 
   /**
-     * @brief Add a custom marker defined by the application
-     * @param[in] marker the marker to add
-     * @param[in] contextId the context the custom marker is designed for
-     */
-  void AddCustomMarker(const PerformanceMarker& marker, PerformanceInterface::ContextId contextId);
+   * @brief Add a custom marker defined by the application
+   * @param[in] marker the marker to add
+   * @param[in] contextId the context the custom marker is designed for
+   */
+  void AddCustomMarker( const PerformanceMarker& marker , PerformanceInterface::ContextId contextId );
 
   /**
-     * @brief Get the nane of a context
-     * @param[in] contextId id of the context to get the name
-     * @return context name
-     */
-  const char* GetContextName(PerformanceInterface::ContextId contextId) const;
+   * @brief Get the name of a context
+   * @param[in] contextId id of the context to get the name
+   * @return context name
+   */
+  const char* GetContextName( PerformanceInterface::ContextId contextId ) const;
 
   /**
-     * @brief Get the full description of a marker for this context
-     * @param[in] type marker type, for a customer marker this will be either START or END
-     * @param[in] contextId id of the context to get the name
-     * @return marker description in relation to this context
-     */
-  const char* GetMarkerDescription(PerformanceInterface::MarkerType type, PerformanceInterface::ContextId contextId) const;
+   * @brief Get the id of a context name
+   * @param[in] name Name of the context to retrieve
+   * @return context id, or 0 if not found
+   */
+  PerformanceInterface::ContextId GetContextId(const char* name) const;
 
   /**
-     * @brief enable / disable logging for a context
-     * @param[in] enable whether to enable logging
-     * @param[in] contextId the context to configure
-     */
-  void EnableLogging(bool enable, PerformanceInterface::ContextId contextId);
+   * @brief Get the full description of a marker for this context
+   * @param[in] type marker type, for a customer marker this will be either START or END
+   * @param[in] contextId id of the context to get the name
+   * @return marker description in relation to this context
+   */
+    const char* GetMarkerDescription( PerformanceInterface::MarkerType type, PerformanceInterface::ContextId contextId ) const;
 
   /**
-     * @brief set global logging level and frequency.
-     * @param[in] statisticsLogOptions  log options
-     * @param[in] logFrequency frequency in seconds
-     */
-  void SetLoggingLevel(unsigned int statisticsLogOptions, unsigned int logFrequency);
+   * @brief enable / disable logging for a context
+   * @param[in] enable whether to enable logging
+   * @param[in] contextId the context to configure
+   */
+  void EnableLogging( bool enable, PerformanceInterface::ContextId contextId );
 
   /**
-     * @brief Set the frequency of logging for an individual context
-     * @param[in] logFrequency log frequency in seconds
-     * @param[in] contextId the context to configure
-     */
-  void SetLoggingFrequency(unsigned int logFrequency, PerformanceInterface::ContextId contextId);
+   * @brief set global logging level and frequency.
+   * @param[in] statisticsLogOptions  log options
+   * @param[in] logFrequency frequency in seconds
+   */
+  void SetLoggingLevel( unsigned int statisticsLogOptions, unsigned int logFrequency);
+
+  /**
+   * @brief Set the frequency of logging for an individual context
+   * @param[in] logFrequency log frequency in seconds
+   * @param[in] contextId the context to configure
+   */
+  void SetLoggingFrequency( unsigned int logFrequency, PerformanceInterface::ContextId contextId  );
 
 private:
-  StatContextManager(const StatContextManager&);            ///< Undefined
-  StatContextManager& operator=(const StatContextManager&); ///< Undefined
+  StatContextManager( const StatContextManager& ); ///< Undefined
+  StatContextManager& operator=( const StatContextManager& ); ///< Undefined
 
-  typedef Dali::Vector<StatContext*> StatContexts;
+  typedef Dali::Vector< StatContext* > StatContexts;
 
   /**
-     * @brief helper
-     * @param[in] contextId the context to get
-     * @return context
-     */
-  StatContext* GetContext(PerformanceInterface::ContextId contextId) const;
+   * @brief helper
+   * @param[in] contextId the context to get
+   * @return context
+   */
+  StatContext* GetContext( PerformanceInterface::ContextId contextId ) const;
 
-  Dali::Mutex              mDataMutex;    ///< mutex
-  StatContexts             mStatContexts; ///< The list of stat contexts
-  StatContextLogInterface& mLogInterface; ///< Log interface
+  Dali::Mutex mDataMutex;                            ///< mutex
+  StatContexts mStatContexts;                        ///< The list of stat contexts
+  StatContextLogInterface& mLogInterface;            ///< Log interface
 
-  PerformanceInterface::ContextId mNextContextId; ///< The next valid context ID
+  PerformanceInterface::ContextId mNextContextId;    ///< The next valid context ID
 
   // Some defaults contexts
-  PerformanceInterface::ContextId mUpdateStats; ///< update time statistics
-  PerformanceInterface::ContextId mRenderStats; ///< render time statistics
-  PerformanceInterface::ContextId mEventStats;  ///< event time statistics
+  PerformanceInterface::ContextId mUpdateStats;    ///< update time statistics
+  PerformanceInterface::ContextId mRenderStats;    ///< render time statistics
+  PerformanceInterface::ContextId mEventStats;     ///< event time statistics
 
-  unsigned int mStatisticsLogBitmask; ///< statistics log bitmask
-  unsigned int mLogFrequency;         ///< log frequency
+  unsigned int mStatisticsLogBitmask;              ///< statistics log bitmask
+  unsigned int mLogFrequency;                      ///< log frequency
 };
 
 } // namespace Adaptor
index bf9c696..57e2fd6 100644 (file)
@@ -46,12 +46,16 @@ void TraceManagerGeneric::LogContext(bool start, const char* tag)
   {
     if(start)
     {
-      unsigned short contextId = traceManagerGeneric->mPerformanceInterface->AddContext(tag);
+      unsigned short contextId = traceManagerGeneric->mPerformanceInterface->GetContextId( tag );
+      if( !contextId )
+      {
+        contextId = traceManagerGeneric->mPerformanceInterface->AddContext( tag );
+      }
       traceManagerGeneric->mPerformanceInterface->AddMarker(PerformanceInterface::START, contextId);
     }
     else
     {
-      unsigned short contextId = traceManagerGeneric->mPerformanceInterface->AddContext(tag);
+      unsigned short contextId = traceManagerGeneric->mPerformanceInterface->GetContextId( tag );
       traceManagerGeneric->mPerformanceInterface->AddMarker(PerformanceInterface::END, contextId);
     }
   }