mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-18 20:54:27 -04:00
traceId
Signed-off-by: huzeqi <huzeqi@huawei.com> Change-Id: I145aa33500d44305bbe2c6d2f738686e7a63c1ab
This commit is contained in:
@@ -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" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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::HiTraceId>(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<OHOS::HiviewDFX::HiTraceId> traceId_;
|
||||
};
|
||||
|
||||
TraceId* TraceId::CreateTraceId()
|
||||
{
|
||||
return new TraceIdImpl();
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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" ]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<TraceId> traceIdPtr(traceId);
|
||||
if (originTask) {
|
||||
traceIdPtr->SetTraceId();
|
||||
originTask();
|
||||
traceIdPtr->ClearTraceId();
|
||||
}
|
||||
};
|
||||
return wrappedTask;
|
||||
|
||||
Reference in New Issue
Block a user