From a1701bd69e5dd4645e02f2ec27b07c8e865da19e Mon Sep 17 00:00:00 2001 From: huzeqi Date: Mon, 25 Apr 2022 16:53:33 +0800 Subject: [PATCH] traceId Signed-off-by: huzeqi Change-Id: I145aa33500d44305bbe2c6d2f738686e7a63c1ab --- .../ohos/entrance/pa_engine/engine/BUILD.gn | 2 +- adapter/ohos/osal/BUILD.gn | 6 ++- adapter/ohos/osal/trace_id_impl.cpp | 52 +++++++++++++++++++ adapter/preview/osal/BUILD.gn | 1 + adapter/preview/osal/trace_id_impl.cpp | 27 ++++++++++ frameworks/base/log/trace_id.h | 34 ++++++++++++ .../bridge/declarative_frontend/BUILD.gn | 2 +- frameworks/bridge/js_frontend/engine/BUILD.gn | 2 +- frameworks/core/BUILD.gn | 18 +------ .../common/flutter/flutter_task_executor.cpp | 6 ++- 10 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 adapter/ohos/osal/trace_id_impl.cpp create mode 100644 adapter/preview/osal/trace_id_impl.cpp create mode 100644 frameworks/base/log/trace_id.h diff --git a/adapter/ohos/entrance/pa_engine/engine/BUILD.gn b/adapter/ohos/entrance/pa_engine/engine/BUILD.gn index ca697d0d..4e5e9a4d 100644 --- a/adapter/ohos/entrance/pa_engine/engine/BUILD.gn +++ b/adapter/ohos/entrance/pa_engine/engine/BUILD.gn @@ -39,7 +39,7 @@ template("js_pa_engine") { deps += [ "$ace_root/build:libace" ] if (defined(config.build_container_scope_lib) && config.build_container_scope_lib) { - deps += [ "$ace_root/frameworks/core:ace_container_scope" ] + external_deps = [ "napi:ace_container_scope" ] } } } diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index 284cd04d..895e7410 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -49,6 +49,7 @@ template("ace_osal_ohos_source_set") { "log_wrapper.cpp", "ressched_report.cpp", "system_properties.cpp", + "trace_id_impl.cpp", ] public_deps = @@ -76,7 +77,10 @@ template("ace_osal_ohos_source_set") { external_deps += [ "multimedia_image:image" ] } sources += [ "pixel_map_ohos.cpp" ] - external_deps += [ "hisysevent_native:libhisysevent" ] + external_deps += [ + "hisysevent_native:libhisysevent", + "hitrace_native:libhitrace", + ] } } diff --git a/adapter/ohos/osal/trace_id_impl.cpp b/adapter/ohos/osal/trace_id_impl.cpp new file mode 100644 index 00000000..05a50abb --- /dev/null +++ b/adapter/ohos/osal/trace_id_impl.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "frameworks/base/log/trace_id.h" + +#include "hitrace/trace.h" + +namespace OHOS::Ace { + +class TraceIdImpl : public TraceId { +public: + TraceIdImpl() + { + traceId_ = std::make_unique(OHOS::HiviewDFX::HiTrace::GetId()); + } + + ~TraceIdImpl() = default; + + void SetTraceId() override + { + if (traceId_ && traceId_->IsValid()) { + OHOS::HiviewDFX::HiTrace::SetId(*(traceId_.get())); + } + } + + void ClearTraceId() override + { + OHOS::HiviewDFX::HiTrace::ClearId(); + } + +private: + std::unique_ptr traceId_; +}; + +TraceId* TraceId::CreateTraceId() +{ + return new TraceIdImpl(); +} + +} // namespace OHOS::Ace \ No newline at end of file diff --git a/adapter/preview/osal/BUILD.gn b/adapter/preview/osal/BUILD.gn index 5e1bafa9..13e186e2 100644 --- a/adapter/preview/osal/BUILD.gn +++ b/adapter/preview/osal/BUILD.gn @@ -52,6 +52,7 @@ template("ace_osal_preview_source_set") { "ressched_report.cpp", "stage_card_parser.cpp", "system_properties.cpp", + "trace_id_impl.cpp", ] cflags_cc = [ diff --git a/adapter/preview/osal/trace_id_impl.cpp b/adapter/preview/osal/trace_id_impl.cpp new file mode 100644 index 00000000..331966b4 --- /dev/null +++ b/adapter/preview/osal/trace_id_impl.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "frameworks/base/log/trace_id.h" + +namespace OHOS::Ace { + +class TraceIdImpl : public TraceId {}; + +TraceId* TraceId::CreateTraceId() +{ + return new TraceIdImpl(); +} + +} // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/base/log/trace_id.h b/frameworks/base/log/trace_id.h new file mode 100644 index 00000000..b4149fed --- /dev/null +++ b/frameworks/base/log/trace_id.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_TRACE_ID_H +#define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_TRACE_ID_H + +#include "base/log/log.h" + +namespace OHOS::Ace { + +class TraceId { +public: + TraceId() = default; + virtual ~TraceId() = default; + static TraceId* CreateTraceId(); + virtual void SetTraceId() {} + virtual void ClearTraceId() {} +}; + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_TRACE_ID_H diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index 7cfa03f1..f5bda89b 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -282,7 +282,7 @@ template("declarative_js_engine") { deps += [ "$ace_root/build:libace" ] if (defined(config.build_container_scope_lib) && config.build_container_scope_lib) { - deps += [ "$ace_root/frameworks/core:ace_container_scope" ] + deps += [ "$ace_napi:ace_container_scope" ] } } diff --git a/frameworks/bridge/js_frontend/engine/BUILD.gn b/frameworks/bridge/js_frontend/engine/BUILD.gn index 295225f3..286a842f 100644 --- a/frameworks/bridge/js_frontend/engine/BUILD.gn +++ b/frameworks/bridge/js_frontend/engine/BUILD.gn @@ -43,7 +43,7 @@ template("js_engine") { deps += [ "$ace_root/build:libace" ] if (defined(config.build_container_scope_lib) && config.build_container_scope_lib) { - deps += [ "$ace_root/frameworks/core:ace_container_scope" ] + deps += [ "$ace_napi:ace_container_scope" ] } } } diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index 8f0e2547..7a80def1 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -361,7 +361,7 @@ template("ace_core_source_set") { if (defined(config.build_container_scope_lib) && config.build_container_scope_lib) { sources -= [ "common/container_scope.cpp" ] - deps += [ ":ace_container_scope" ] + deps += [ "$ace_napi:ace_container_scope" ] } if (defined(config.plugin_components_support) && @@ -390,22 +390,6 @@ template("ace_core_source_set") { } } -config("container_scope_config") { - visibility = [ ":*" ] - include_dirs = [ "$ace_root/frameworks" ] -} - -ohos_shared_library("ace_container_scope") { - public_configs = [ ":container_scope_config" ] - - configs = [ "$ace_root:ace_config" ] - - sources = [ "common/container_scope.cpp" ] - - subsystem_name = "ace" - part_name = ace_engine_part -} - foreach(item, ace_platforms) { ace_core_source_set("ace_core_" + item.name) { platform = item.name diff --git a/frameworks/core/common/flutter/flutter_task_executor.cpp b/frameworks/core/common/flutter/flutter_task_executor.cpp index f1e15f20..880d5c98 100644 --- a/frameworks/core/common/flutter/flutter_task_executor.cpp +++ b/frameworks/core/common/flutter/flutter_task_executor.cpp @@ -38,6 +38,7 @@ #include "base/thread/background_task_executor.h" #include "core/common/container.h" #include "core/common/container_scope.h" +#include "base/log/trace_id.h" namespace OHOS::Ace { namespace { @@ -53,10 +54,13 @@ inline std::string GenJsThreadName() TaskExecutor::Task WrapTaskWithContainer(TaskExecutor::Task&& task, int32_t id) { - auto wrappedTask = [originTask = std::move(task), id]() { + auto wrappedTask = [originTask = std::move(task), id, traceId = TraceId::CreateTraceId()]() { ContainerScope scope(id); + std::unique_ptr traceIdPtr(traceId); if (originTask) { + traceIdPtr->SetTraceId(); originTask(); + traceIdPtr->ClearTraceId(); } }; return wrappedTask;