From 6bc5409c5db75a570eefcb87ea57a8c5f9e1b56c Mon Sep 17 00:00:00 2001 From: Eunki Hong Date: Wed, 9 Aug 2023 22:42:41 +0900 Subject: [PATCH] Allow worker thread trace 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 --- dali/integration-api/adaptor-framework/adaptor.h | 9 +++++- .../adaptor-framework/trace-factory-interface.h | 35 ++++++++++++++++++++++ dali/integration-api/file.list | 1 + dali/internal/adaptor/common/adaptor-impl.cpp | 5 ++++ dali/internal/adaptor/common/adaptor-impl.h | 5 ++++ dali/internal/adaptor/common/adaptor.cpp | 7 ++++- .../system/common/async-task-manager-impl.cpp | 2 ++ .../system/common/async-task-manager-impl.h | 14 +++++---- dali/internal/system/common/environment-options.h | 9 +++--- .../common/gl-window-render-thread.cpp | 4 ++- .../window-system/common/gl-window-render-thread.h | 7 +++-- 11 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 dali/integration-api/adaptor-framework/trace-factory-interface.h diff --git a/dali/integration-api/adaptor-framework/adaptor.h b/dali/integration-api/adaptor-framework/adaptor.h index 9bcb8c6..26deedf 100644 --- a/dali/integration-api/adaptor-framework/adaptor.h +++ b/dali/integration-api/adaptor-framework/adaptor.h @@ -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 +#include #include #include @@ -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 index 0000000..7cefdec --- /dev/null +++ b/dali/integration-api/adaptor-framework/trace-factory-interface.h @@ -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 diff --git a/dali/integration-api/file.list b/dali/integration-api/file.list index 40e11c9..11cacd7 100644 --- a/dali/integration-api/file.list +++ b/dali/integration-api/file.list @@ -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 diff --git a/dali/internal/adaptor/common/adaptor-impl.cpp b/dali/internal/adaptor/common/adaptor-impl.cpp index 093d7aa..fd8238b 100644 --- a/dali/internal/adaptor/common/adaptor-impl.cpp +++ b/dali/internal/adaptor/common/adaptor-impl.cpp @@ -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); diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index a24a7f2..2b27610 100644 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -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); diff --git a/dali/internal/adaptor/common/adaptor.cpp b/dali/internal/adaptor/common/adaptor.cpp index d320604..f84547d 100644 --- a/dali/internal/adaptor/common/adaptor.cpp +++ b/dali/internal/adaptor/common/adaptor.cpp @@ -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); diff --git a/dali/internal/system/common/async-task-manager-impl.cpp b/dali/internal/system/common/async-task-manager-impl.cpp index 7019ae2..740f365 100644 --- a/dali/internal/system/common/async-task-manager-impl.cpp +++ b/dali/internal/system/common/async-task-manager-impl.cpp @@ -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) { diff --git a/dali/internal/system/common/async-task-manager-impl.h b/dali/internal/system/common/async-task-manager-impl.h index e126a16..6690098 100644 --- a/dali/internal/system/common/async-task-manager-impl.h +++ b/dali/internal/system/common/async-task-manager-impl.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -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; }; /** diff --git a/dali/internal/system/common/environment-options.h b/dali/internal/system/common/environment-options.h index 13299e6..d6bf0ce 100644 --- a/dali/internal/system/common/environment-options.h +++ b/dali/internal/system/common/environment-options.h @@ -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 +#include #include 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 diff --git a/dali/internal/window-system/common/gl-window-render-thread.cpp b/dali/internal/window-system/common/gl-window-render-thread.cpp index 532d61d..a1c1582 100644 --- a/dali/internal/window-system/common/gl-window-render-thread.cpp +++ b/dali/internal/window-system/common/gl-window-render-thread.cpp @@ -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; diff --git a/dali/internal/window-system/common/gl-window-render-thread.h b/dali/internal/window-system/common/gl-window-render-thread.h index 2b4871b..4091c8c 100644 --- a/dali/internal/window-system/common/gl-window-render-thread.h +++ b/dali/internal/window-system/common/gl-window-render-thread.h @@ -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 #include +#include +#include // INTERNAL INCLUDES #include @@ -245,7 +247,8 @@ private: WindowBase* mWindowBase; std::unique_ptr mWindowRotationTrigger; - const Dali::LogFactoryInterface& mLogFactory; + const Dali::LogFactoryInterface& mLogFactory; + const Dali::TraceFactoryInterface& mTraceFactory; PositionSize mPositionSize; ///< Position ColorDepth mColorDepth; -- 2.7.4