Allow worker thread trace 57/297057/3
authorEunki Hong <eunkiki.hong@samsung.com>
Wed, 9 Aug 2023 13:42:41 +0000 (22:42 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 9 Aug 2023 22:48:36 +0000 (07:48 +0900)
Let we make ttrace can trace worker threads if we want.
And also, let we make AsyncTaskManager's thread can use trace.

Change-Id: I4a04a1d480f0cf96541f380d46513258d85deee0
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/integration-api/adaptor-framework/adaptor.h
dali/integration-api/adaptor-framework/trace-factory-interface.h [new file with mode: 0644]
dali/integration-api/file.list
dali/internal/adaptor/common/adaptor-impl.cpp
dali/internal/adaptor/common/adaptor-impl.h
dali/internal/adaptor/common/adaptor.cpp
dali/internal/system/common/async-task-manager-impl.cpp
dali/internal/system/common/async-task-manager-impl.h
dali/internal/system/common/environment-options.h
dali/internal/window-system/common/gl-window-render-thread.cpp
dali/internal/window-system/common/gl-window-render-thread.h

index 9bcb8c6..26deedf 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTEGRATION_ADAPTOR_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -29,6 +29,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
+#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
 #include <dali/public-api/adaptor-framework/window.h>
 #include <dali/public-api/dali-adaptor-common.h>
 
@@ -404,6 +405,12 @@ public:
   const LogFactoryInterface& GetLogFactory();
 
   /**
+   * @brief The trace factory allows installation of a trace function in worker threads.
+   * @return An interface to a tracing factory
+   */
+  const TraceFactoryInterface& GetTraceFactory();
+
+  /**
    * @brief Register a processor implementing the Integration::Processor interface with dali-core.
    * @param[in] processor the Processor to register
    * @param[in] postProcessor set this processor required to be called after size negotiation. Default is false.
diff --git a/dali/integration-api/adaptor-framework/trace-factory-interface.h b/dali/integration-api/adaptor-framework/trace-factory-interface.h
new file mode 100644 (file)
index 0000000..7cefdec
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef DALI_ADAPTOR_TRACE_FACTORY_INTERFACE_H
+#define DALI_ADAPTOR_TRACE_FACTORY_INTERFACE_H
+
+/*
+ * Copyright (c) 2023 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.
+ */
+
+namespace Dali
+{
+class TraceFactoryInterface
+{
+public:
+  /**
+   * @brief Install a trace function for this thread.
+   *
+   * Only need to use once per thread, before any processing occurs.
+   */
+  virtual void InstallTraceFunction() const = 0;
+};
+
+} // namespace Dali
+
+#endif //DALI_ADAPTOR_TRACE_FACTORY_INTERFACE_H
index 40e11c9..11cacd7 100644 (file)
@@ -17,6 +17,7 @@ SET( adaptor_integration_api_header_files
   ${adaptor_integration_api_dir}/adaptor-framework/scene-holder.h
   ${adaptor_integration_api_dir}/adaptor-framework/scene-holder-impl.h
   ${adaptor_integration_api_dir}/adaptor-framework/thread-synchronization-interface.h
+  ${adaptor_integration_api_dir}/adaptor-framework/trace-factory-interface.h
   ${adaptor_integration_api_dir}/adaptor-framework/trigger-event-interface.h
   ${adaptor_integration_api_dir}/adaptor-framework/trigger-event-factory.h
   ${adaptor_integration_api_dir}/adaptor-framework/native-image-surface.h
index 093d7aa..fd8238b 100644 (file)
@@ -1159,6 +1159,11 @@ const LogFactoryInterface& Adaptor::GetLogFactory()
   return *mEnvironmentOptions;
 }
 
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
+{
+  return *mEnvironmentOptions;
+}
+
 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
   GetCore().RegisterProcessor(processor, postProcessor);
index a24a7f2..2b27610 100644 (file)
@@ -444,6 +444,11 @@ public:
   const LogFactoryInterface& GetLogFactory();
 
   /**
+   * @copydoc Dali::Adaptor::GetTraceFactory
+   */
+  const TraceFactoryInterface& GetTraceFactory();
+
+  /**
    * @copydoc Dali::Adaptor::RegisterProcessor
    */
   void RegisterProcessor(Integration::Processor& processor, bool postProcessor);
index d320604..f84547d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -230,6 +230,11 @@ const LogFactoryInterface& Adaptor::GetLogFactory()
   return mImpl->GetLogFactory();
 }
 
+const TraceFactoryInterface& Adaptor::GetTraceFactory()
+{
+  return mImpl->GetTraceFactory();
+}
+
 void Adaptor::RegisterProcessor(Integration::Processor& processor, bool postProcessor)
 {
   mImpl->RegisterProcessor(processor, postProcessor);
index 7019ae2..740f365 100644 (file)
@@ -73,6 +73,7 @@ AsyncTaskThread::AsyncTaskThread(AsyncTaskManager& asyncTaskManager)
 : mConditionalWait(),
   mAsyncTaskManager(asyncTaskManager),
   mLogFactory(Dali::Adaptor::Get().GetLogFactory()),
+  mTraceFactory(Dali::Adaptor::Get().GetTraceFactory()),
   mDestroyThread(false),
   mIsThreadStarted(false),
   mIsThreadIdle(true)
@@ -129,6 +130,7 @@ void AsyncTaskThread::Run()
   SetThreadName("AsyncTaskThread");
 #endif
   mLogFactory.InstallLogFunction();
+  mTraceFactory.InstallTraceFunction();
 
   while(!mDestroyThread)
   {
index e126a16..6690098 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
+#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
 #include <dali/integration-api/processor-interface.h>
 #include <dali/public-api/common/list-wrapper.h>
 #include <dali/public-api/object/base-object.h>
@@ -76,12 +77,13 @@ private:
   AsyncTaskThread& operator=(const AsyncTaskThread& thread) = delete;
 
 private:
-  ConditionalWait                  mConditionalWait;
-  AsyncTaskManager&                mAsyncTaskManager;
-  const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
-  bool                             mDestroyThread;
-  bool                             mIsThreadStarted;
-  bool                             mIsThreadIdle;
+  ConditionalWait                    mConditionalWait;
+  AsyncTaskManager&                  mAsyncTaskManager;
+  const Dali::LogFactoryInterface&   mLogFactory;   ///< The log factory
+  const Dali::TraceFactoryInterface& mTraceFactory; ///< The trace factory
+  bool                               mDestroyThread;
+  bool                               mIsThreadStarted;
+  bool                               mIsThreadIdle;
 };
 
 /**
index 13299e6..d6bf0ce 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_ADAPTOR_ENVIRONMENT_OPTIONS_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -24,6 +24,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
+#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
 #include <dali/internal/adaptor/common/threading-mode.h>
 
 namespace Dali
@@ -40,7 +41,7 @@ class PerformanceInterface;
  * the ability to install a log function.
  *
  */
-class EnvironmentOptions : public Dali::LogFactoryInterface
+class EnvironmentOptions : public Dali::LogFactoryInterface, public Dali::TraceFactoryInterface
 {
 public:
   /**
@@ -60,9 +61,9 @@ public:
   void CreateTraceManager(PerformanceInterface* performanceInterface);
 
   /**
-   * Initialize TraceManager by installing Trace function.
+   * Install the TraceManager's trace function for the current thread.
    */
-  void InstallTraceFunction() const;
+  void InstallTraceFunction() const override;
 
   /**
    * @param logFunction logging function
index 532d61d..a1c1582 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -46,6 +46,7 @@ GlWindowRenderThread::GlWindowRenderThread(PositionSize positionSize, ColorDepth
   mWindowBase(nullptr),
   mWindowRotationTrigger(),
   mLogFactory(Dali::Adaptor::Get().GetLogFactory()),
+  mTraceFactory(Dali::Adaptor::Get().GetTraceFactory()),
   mPositionSize(positionSize),
   mColorDepth(colorDepth),
   mGLInitCallback(),
@@ -215,6 +216,7 @@ void GlWindowRenderThread::Run()
 {
   Dali::SetThreadName("GlWindowRenderThread");
   mLogFactory.InstallLogFunction();
+  mTraceFactory.InstallTraceFunction();
 
   int          renderFrameResult = 0;
   unsigned int isSurfaceChanged  = 0;
index 2b4871b..4091c8c 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_GL_WINDOW_RENDER_THREAD_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -21,6 +21,8 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/thread.h>
+#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
+#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
 
 // INTERNAL INCLUDES
 #include <dali/internal/graphics/gles/egl-graphics.h>
@@ -245,7 +247,8 @@ private:
   WindowBase*                            mWindowBase;
   std::unique_ptr<TriggerEventInterface> mWindowRotationTrigger;
 
-  const Dali::LogFactoryInterface& mLogFactory;
+  const Dali::LogFactoryInterface&   mLogFactory;
+  const Dali::TraceFactoryInterface& mTraceFactory;
 
   PositionSize mPositionSize; ///< Position
   ColorDepth   mColorDepth;