diff --git a/flow/BUILD.gn b/flow/BUILD.gn index 09ed594157cab57c9cb299499a6ae2b84ae0ec52..58bb7cf9bcc0379259cae8f7c887299334f0a6ac 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -83,6 +83,7 @@ source_set("flow") { "surface.h", "surface_frame.cc", "surface_frame.h", + "hitrace/trace.h", ] public_configs = [ @@ -97,6 +98,8 @@ source_set("flow") { "//third_party/skia", ] + ldflags = [] + ldflags += ["lhitrace_ndk.z"] public_deps = [ "//flutter/display_list" ] } diff --git a/flow/hitrace/trace.h b/flow/hitrace/trace.h new file mode 100644 index 0000000000000000000000000000000000000000..1940d14b18dfb83310b9e2d214a1f098f482e884 --- /dev/null +++ b/flow/hitrace/trace.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2023 Huawei Device 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. + */ + +#ifndef HIVIEWDFX_HITRACE_H +#define HIVIEWDFX_HITRACE_H +/** + * @addtogroup Hitrace + * @{ + * + * @brief hiTraceMeter provides APIs for system performance trace. + * + * You can call the APIs provided by hiTraceMeter in your own service logic to effectively + * track service processes and check the system performance. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * + * @since 10 + */ + +/** + * @file trace.h + * + * @brief Defines APIs of the HiTraceMeter module for performance trace. + * + * Sample code: \n + * Synchronous timeslice trace event: \n + * OH_HiTrace_StartTrace("hitraceTest");\n + * OH_HiTrace_FinishTrace();\n + * Output: \n + * <...>-1668 (-------) [003] .... 135.059377: tracing_mark_write: B|1668|H:hitraceTest \n + * <...>-1668 (-------) [003] .... 135.059415: tracing_mark_write: E|1668| \n + * Asynchronous timeslice trace event:\n + * OH_HiTrace_StartAsyncTrace("hitraceTest", 123); \n + * OH_HiTrace_FinishAsyncTrace("hitraceTest", 123); \n + * Output: \n + * <...>-2477 (-------) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123 \n + * <...>-2477 (-------) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123 \n + * Integer value trace event:\n + * OH_HiTrace_CountTrace("hitraceTest", 500); \n + * Output: \n + * <...>-2638 (-------) [002] .... 458.904382: tracing_mark_write: C|2638|H:hitraceTest 500 \n + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Marks the start of a synchronous trace task. + * + * The OH_HiTrace_StartTrace and OH_HiTrace_FinishTrace APIs must be used in pairs. + * The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing. + * + * @param name Name of a trace task. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_StartTrace(const char *name); + +/** + * @brief Marks the end of a synchronous trace task. + * + * This API must be used with OH_HiTrace_StartTrace in pairs. During trace data parsing, the system matches + * it with the OH_HiTrace_StartTrace API recently invoked in the service process. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_FinishTrace(void); + +/** + * @brief Marks the start of an asynchronous trace task. + * + * This API is called to implement performance trace in asynchronous manner. The start and end of an asynchronous + * trace task do not occur in sequence. Therefore, a unique taskId is required to ensure proper data parsing. + * It is passed as an input parameter for the asynchronous API. + * This API is used with OH_HiTrace_FinishAsyncTrace in pairs. The two APIs that have the same name and + * task ID together form an asynchronous timeslice trace task. + * If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be + * performed multiple times concurrently, different task IDs must be specified in OH_HiTrace_StartTrace. + * If the trace tasks with the same name are not performed at the same time, the same taskId can be used. + * + * @param name Name of the asynchronous trace task. + * @param taskId ID of the asynchronous trace task. The start and end of an asynchronous trace task do not occur in + * sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the + * unique task ID together. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_StartAsyncTrace(const char *name, int32_t taskId); + +/** + * @brief Marks the end of an asynchronous trace task. + * + * This API is called in the callback function after an asynchronous trace is complete. + * It is used with OH_HiTrace_StartAsyncTrace in pairs. Its name and task ID must be the same as those of + * OH_HiTrace_StartAsyncTrace. + * + * @param name Name of the asynchronous trace task. + * @param taskId ID of the asynchronous trace task. The start and end of an asynchronous trace task do not occur in + * sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the + * unique task ID together. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_FinishAsyncTrace(const char *name, int32_t taskId); + +/** + * @brief Traces the value change of an integer variable based on its name. + * + * This API can be executed for multiple times to trace the value change of a given integer variable at different + * time points. + * + * @param name Name of the integer variable. It does not need to be the same as the real variable name. + * @param count Integer value. Generally, an integer variable can be passed. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_CountTrace(const char *name, int64_t count); + +#ifdef __cplusplus +} +#endif +#endif // HIVIEWDFX_HITRACE_H diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 7fa0c1b23ae702ec61d968210891c412fdc6f482..3f16ec59ad331f5ba2645c20e88082e5c284da47 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -140,6 +140,8 @@ source_set("common") { "//third_party/skia", ] + ldflags = [] + ldflags += ["lhitrace_ndk.z"] if (impeller_supports_rendering) { sources += [ "snapshot_controller_impeller.cc", diff --git a/shell/common/animator.cc b/shell/common/animator.cc index 07963bf190de9d0a801faa7c366eb447ba75c693..b6417ce42f0771f45a879bb210ea0cc05ebc19c0 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -9,6 +9,11 @@ #include "flutter/fml/trace_event.h" #include "third_party/dart/runtime/include/dart_tools_api.h" #include "flutter/fml/logging.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif namespace flutter { @@ -90,7 +95,17 @@ void Animator::BeginFrame( // full because the consumer is being too slow. Try again at the next // frame interval. TRACE_EVENT0("flutter", "PipelineFull"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("animator RequestFrame"); +#elif defined(__ANDROID__) + ATrace_beginSection("animator RequestFrame"); +#endif RequestFrame(); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif return; } } @@ -184,7 +199,11 @@ void Animator::DrawLastLayerTree( // This method is very cheap, but this makes it explicitly clear in trace // files. TRACE_EVENT0("flutter", "Animator::DrawLastLayerTree"); - +#if defined(__OHOS__) + OH_HiTrace_StartTrace("animator Animator::DrawLastLayerTree"); +#elif defined(__ANDROID__) + ATrace_beginSection("animator Animator::DrawLastLayerTree"); +#endif pending_frame_semaphore_.Signal(); // In this case BeginFrame doesn't get called, we need to // adjust frame timings to update build start and end times, @@ -194,6 +213,11 @@ void Animator::DrawLastLayerTree( frame_timings_recorder->RecordBuildStart(now); frame_timings_recorder->RecordBuildEnd(now); delegate_.OnAnimatorDrawLastLayerTree(std::move(frame_timings_recorder)); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif } void Animator::RequestFrame(bool regenerate_layer_tree) { diff --git a/shell/common/engine.cc b/shell/common/engine.cc index bbdf61cac7194f7b779497f4e7d85ee76d0a8b14..a19f03b28b8baaa5bd7273b03fb9e49d507ab904 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -20,6 +20,11 @@ #include "flutter/shell/common/shell.h" #include "rapidjson/document.h" #include "third_party/dart/runtime/include/dart_tools_api.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif namespace flutter { @@ -148,7 +153,17 @@ fml::WeakPtr Engine::GetWeakPtr() const { void Engine::SetupDefaultFontManager() { TRACE_EVENT0("flutter", "Engine::SetupDefaultFontManager"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Engine::SetupDefaultFontManager"); +#elif defined(__ANDROID__) + ATrace_beginSection("Engine::SetupDefaultFontManager"); +#endif font_collection_->SetupDefaultFontManager(settings_.font_initialization_data); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif } std::shared_ptr Engine::GetAssetManager() { @@ -438,7 +453,17 @@ std::string Engine::DefaultRouteName() { } void Engine::ScheduleFrame(bool regenerate_layer_tree) { +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Engine::ScheduleFrame"); +#elif defined(__ANDROID__) + ATrace_beginSection("Engine::ScheduleFrame"); +#endif animator_->RequestFrame(regenerate_layer_tree); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif } void Engine::Render(std::shared_ptr layer_tree) { diff --git a/shell/common/hitrace/trace.h b/shell/common/hitrace/trace.h new file mode 100644 index 0000000000000000000000000000000000000000..1940d14b18dfb83310b9e2d214a1f098f482e884 --- /dev/null +++ b/shell/common/hitrace/trace.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2023 Huawei Device 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. + */ + +#ifndef HIVIEWDFX_HITRACE_H +#define HIVIEWDFX_HITRACE_H +/** + * @addtogroup Hitrace + * @{ + * + * @brief hiTraceMeter provides APIs for system performance trace. + * + * You can call the APIs provided by hiTraceMeter in your own service logic to effectively + * track service processes and check the system performance. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * + * @since 10 + */ + +/** + * @file trace.h + * + * @brief Defines APIs of the HiTraceMeter module for performance trace. + * + * Sample code: \n + * Synchronous timeslice trace event: \n + * OH_HiTrace_StartTrace("hitraceTest");\n + * OH_HiTrace_FinishTrace();\n + * Output: \n + * <...>-1668 (-------) [003] .... 135.059377: tracing_mark_write: B|1668|H:hitraceTest \n + * <...>-1668 (-------) [003] .... 135.059415: tracing_mark_write: E|1668| \n + * Asynchronous timeslice trace event:\n + * OH_HiTrace_StartAsyncTrace("hitraceTest", 123); \n + * OH_HiTrace_FinishAsyncTrace("hitraceTest", 123); \n + * Output: \n + * <...>-2477 (-------) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123 \n + * <...>-2477 (-------) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123 \n + * Integer value trace event:\n + * OH_HiTrace_CountTrace("hitraceTest", 500); \n + * Output: \n + * <...>-2638 (-------) [002] .... 458.904382: tracing_mark_write: C|2638|H:hitraceTest 500 \n + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Marks the start of a synchronous trace task. + * + * The OH_HiTrace_StartTrace and OH_HiTrace_FinishTrace APIs must be used in pairs. + * The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing. + * + * @param name Name of a trace task. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_StartTrace(const char *name); + +/** + * @brief Marks the end of a synchronous trace task. + * + * This API must be used with OH_HiTrace_StartTrace in pairs. During trace data parsing, the system matches + * it with the OH_HiTrace_StartTrace API recently invoked in the service process. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_FinishTrace(void); + +/** + * @brief Marks the start of an asynchronous trace task. + * + * This API is called to implement performance trace in asynchronous manner. The start and end of an asynchronous + * trace task do not occur in sequence. Therefore, a unique taskId is required to ensure proper data parsing. + * It is passed as an input parameter for the asynchronous API. + * This API is used with OH_HiTrace_FinishAsyncTrace in pairs. The two APIs that have the same name and + * task ID together form an asynchronous timeslice trace task. + * If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be + * performed multiple times concurrently, different task IDs must be specified in OH_HiTrace_StartTrace. + * If the trace tasks with the same name are not performed at the same time, the same taskId can be used. + * + * @param name Name of the asynchronous trace task. + * @param taskId ID of the asynchronous trace task. The start and end of an asynchronous trace task do not occur in + * sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the + * unique task ID together. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_StartAsyncTrace(const char *name, int32_t taskId); + +/** + * @brief Marks the end of an asynchronous trace task. + * + * This API is called in the callback function after an asynchronous trace is complete. + * It is used with OH_HiTrace_StartAsyncTrace in pairs. Its name and task ID must be the same as those of + * OH_HiTrace_StartAsyncTrace. + * + * @param name Name of the asynchronous trace task. + * @param taskId ID of the asynchronous trace task. The start and end of an asynchronous trace task do not occur in + * sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the + * unique task ID together. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_FinishAsyncTrace(const char *name, int32_t taskId); + +/** + * @brief Traces the value change of an integer variable based on its name. + * + * This API can be executed for multiple times to trace the value change of a given integer variable at different + * time points. + * + * @param name Name of the integer variable. It does not need to be the same as the real variable name. + * @param count Integer value. Generally, an integer variable can be passed. + * + * @syscap SystemCapability.HiviewDFX.HiTrace + * @since 10 + */ +void OH_HiTrace_CountTrace(const char *name, int64_t count); + +#ifdef __cplusplus +} +#endif +#endif // HIVIEWDFX_HITRACE_H diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 78a42915e1244d08a09060700aa505bfe6a6e9c9..c6a4630869bd7e0bcaeb66740c2c336aa0bfbdc4 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -23,6 +23,11 @@ #include "third_party/skia/include/utils/SkBase64.h" #include "flutter/fml/logging.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif namespace flutter { @@ -179,6 +184,12 @@ RasterStatus Rasterizer::Draw( const std::shared_ptr& pipeline, LayerTreeDiscardCallback discard_callback) { TRACE_EVENT0("flutter", "GPURasterizer::Draw"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Rasterizer::Draw"); +#elif defined(__ANDROID__) + ATrace_beginSection("Rasterizer::Draw"); +#endif + if (raster_thread_merger_ && !raster_thread_merger_->IsOnRasterizingThread()) { // we yield and let this frame be serviced on the right thread. @@ -248,7 +259,11 @@ RasterStatus Rasterizer::Draw( default: break; } - +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif return raster_status; } @@ -289,6 +304,11 @@ std::unique_ptr Rasterizer::MakeSkiaGpuImage( sk_sp display_list, const SkImageInfo& image_info) { TRACE_EVENT0("flutter", "Rasterizer::MakeGpuImage"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Rasterizer::MakeGpuImage"); +#elif defined(__ANDROID__) + ATrace_beginSection("Rasterizer::MakeGpuImage"); +#endif FML_DCHECK(display_list); // TODO(dnfield): the Linux embedding is in a rough state right now and @@ -346,6 +366,11 @@ std::unique_ptr Rasterizer::MakeSkiaGpuImage( result = std::make_unique( texture, sk_ref_sp(context), nullptr, ""); })); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif return result; } @@ -371,7 +396,11 @@ RasterStatus Rasterizer::DoDraw( FML_DCHECK(delegate_.GetTaskRunners() .GetRasterTaskRunner() ->RunsTasksOnCurrentThread()); - +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Rasterizer::DoDraw"); +#elif defined(__ANDROID__) + ATrace_beginSection("Rasterizer::DoDraw"); +#endif if (!layer_tree || !surface_) { return RasterStatus::kFailed; } @@ -460,6 +489,11 @@ RasterStatus Rasterizer::DoDraw( return RasterStatus::kEnqueuePipeline; } } +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif return raster_status; } @@ -468,6 +502,11 @@ RasterStatus Rasterizer::DrawToSurface( FrameTimingsRecorder& frame_timings_recorder, flutter::LayerTree& layer_tree) { TRACE_EVENT0("flutter", "Rasterizer::DrawToSurface"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Rasterizer::Draw"); +#elif defined(__ANDROID__) + ATrace_beginSection("Rasterizer::Draw"); +#endif FML_DCHECK(surface_); RasterStatus raster_status; @@ -482,7 +521,11 @@ RasterStatus Rasterizer::DrawToSurface( DrawToSurfaceUnsafe(frame_timings_recorder, layer_tree); })); } - +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif return raster_status; } diff --git a/shell/common/shell.cc b/shell/common/shell.cc index b0bf51ae5d5cc87e53aeb2f9544b01fc6a8e5bd0..54075e32198c6d0c370af6efec404d1f8c96c364 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -34,6 +34,12 @@ #include "third_party/skia/include/utils/SkBase64.h" #include "third_party/tonic/common/log.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif + namespace flutter { constexpr char kSkiaChannel[] = "flutter/skia"; @@ -1086,8 +1092,17 @@ void Shell::OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) { if (!texture) { return; } - +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Shell::OnPlatformViewMarkTextureFrameAvailable"); +#elif defined(__ANDROID__) + ATrace_beginSection("Shell::OnPlatformViewMarkTextureFrameAvailable"); +#endif texture->MarkNewFrameAvailable(); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif }); // Schedule a new frame without having to rebuild the layer tree. diff --git a/shell/gpu/gpu_surface_gl_skia.cc b/shell/gpu/gpu_surface_gl_skia.cc index 01be975ee831ae13e4f6140058fb5769d5a9100f..31f72301cbad526ba08ad064bbc410324ee4f52d 100644 --- a/shell/gpu/gpu_surface_gl_skia.cc +++ b/shell/gpu/gpu_surface_gl_skia.cc @@ -19,6 +19,12 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrContextOptions.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif + // These are common defines present on all OpenGL headers. However, we don't // want to perform GL header reasolution on each platform we support. So just // define these upfront. It is unlikely we will need more. But, if we do, we can @@ -268,7 +274,17 @@ bool GPUSurfaceGLSkia::PresentSurface(const SurfaceFrame& frame, { TRACE_EVENT0("flutter", "SkCanvas::Flush"); + #if defined(__OHOS__) + OH_HiTrace_StartTrace("SkCanvas::Flush"); + #elif defined(__ANDROID__) + ATrace_beginSection("SkCanvas::Flush"); + #endif onscreen_surface_->getCanvas()->flush(); + #if defined(__OHOS__) + OH_HiTrace_FinishTrace(); + #elif defined(__ANDROID__) + ATrace_endSection(); + #endif } GLPresentInfo present_info = { diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 7b888c0d6e3e9ab29fbd6c831731c0a7e0bef259..77abe9c4ebc50453ee510af0de7f75e463a30056 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -221,6 +221,7 @@ shared_library("flutter_shell_native") { ldflags += ["-lace_napi.z"] ldflags += ["-lace_ndk.z"] ldflags += ["-lhilog_ndk.z"] + ldflags += ["-lhitrace_ndk.z"] ldflags += ["-luv"] ldflags += ["-lrawfile.z"] ldflags += ["-lEGL"] diff --git a/shell/platform/ohos/ohos_egl_surface.cpp b/shell/platform/ohos/ohos_egl_surface.cpp index e7ee3d9a8f426f7e27c216da81be5ab2afd384ec..26df98766362241ace3c7440654b0a982af7a6d8 100755 --- a/shell/platform/ohos/ohos_egl_surface.cpp +++ b/shell/platform/ohos/ohos_egl_surface.cpp @@ -21,6 +21,11 @@ #include #include "flutter/fml/trace_event.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif namespace flutter { @@ -237,7 +242,18 @@ bool OhosEGLSurface::SetPresentationTime( bool OhosEGLSurface::SwapBuffers(const std::optional& surface_damage) { TRACE_EVENT0("flutter", "OhosContextGL::SwapBuffers"); - return damage_->SwapBuffersWithDamage(display_, surface_, surface_damage); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("Rasterizer::Draw"); +#elif defined(__ANDROID__) + ATrace_beginSection("Rasterizer::Draw"); +#endif + bool ret = damage_->SwapBuffersWithDamage(display_, surface_, surface_damage); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif + return ret; } bool OhosEGLSurface::SupportsPartialRepaint() const { diff --git a/shell/platform/ohos/vsync_waiter_ohos.cpp b/shell/platform/ohos/vsync_waiter_ohos.cpp index 26cc3d2d8b70f30aff8ce278e8b5592a489782d2..e0a225971247e8be53716653f8f258ef5168c1f7 100644 --- a/shell/platform/ohos/vsync_waiter_ohos.cpp +++ b/shell/platform/ohos/vsync_waiter_ohos.cpp @@ -16,6 +16,11 @@ #include "flutter/shell/platform/ohos/vsync_waiter_ohos.h" #include "flutter/fml/logging.h" #include "napi_common.h" +#if defined(__OHOS__) +#include "hitrace/trace.h" +#elif defined(__ANDROID__) +#include "android/trace.h" +#endif namespace flutter { @@ -52,6 +57,12 @@ void VsyncWaiterOHOS::AwaitVSync() { } void VsyncWaiterOHOS::OnVsyncFromOHOS(long long timestamp, void* data) { + TRACE_EVENT0("flutter", "VSYNC"); +#if defined(__OHOS__) + OH_HiTrace_StartTrace("VsyncWaiterOHOS::OnVsyncFromOHOS"); +#elif defined(__ANDROID__) + ATrace_beginSection("VsyncWaiterOHOS::OnVsyncFromOHOS"); +#endif int64_t frame_nanos = static_cast(timestamp); auto frame_time = fml::TimePoint::FromEpochDelta( fml::TimeDelta::FromNanoseconds(frame_nanos)); @@ -63,6 +74,11 @@ void VsyncWaiterOHOS::OnVsyncFromOHOS(long long timestamp, void* data) { 1000000000.0 / g_refresh_rate_); auto* weak_this = reinterpret_cast*>(data); ConsumePendingCallback(weak_this, frame_time, target_time); +#if defined(__OHOS__) + OH_HiTrace_FinishTrace(); +#elif defined(__ANDROID__) + ATrace_endSection(); +#endif } void VsyncWaiterOHOS::ConsumePendingCallback(