add container scope in napi async task

Signed-off-by: sunfei <sunfei.sun@huawei.com>
Change-Id: I0ca11807772dcb6640f29bd53ce4b05d5ed5983d
This commit is contained in:
sunfei
2022-02-26 22:51:03 +08:00
parent 6e28f995cb
commit cf8a04f628
3 changed files with 28 additions and 3 deletions
+6 -1
View File
@@ -130,6 +130,7 @@ if (defined(ohos_lite)) {
defines = []
public_configs = [ ":ace_napi_config" ]
public_deps = [ "//third_party/libuv:uv" ]
deps = []
include_dirs = [
"//foundation/ace/napi",
@@ -159,12 +160,16 @@ if (defined(ohos_lite)) {
"hiviewdfx_hilog_native:libhilog",
]
defines += [ "ENABLE_HITRACE" ]
if (product_name != "ohos-sdk") {
deps += [ "$ace_root/frameworks/core:ace_container_scope" ]
defines += [ "ENABLE_CONTAINER_SCOPE" ]
}
} else {
external_deps = [ "hilog:libhilog" ]
}
}
deps = [
deps += [
"//third_party/libuv:uv",
"//utils/native/base:utilsecurec",
]
+18 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@@ -18,11 +18,18 @@
#ifdef ENABLE_HITRACE
#include "hitrace/trace.h"
#endif
#ifdef ENABLE_CONTAINER_SCOPE
#include "core/common/container_scope.h"
#endif
#include "napi/native_api.h"
#include "native_engine.h"
#include "utils/log.h"
#ifdef ENABLE_CONTAINER_SCOPE
using OHOS::Ace::ContainerScope;
#endif
NativeAsyncWork::NativeAsyncWork(NativeEngine* engine,
NativeAsyncExecuteCallback execute,
NativeAsyncCompleteCallback complete,
@@ -33,6 +40,9 @@ NativeAsyncWork::NativeAsyncWork(NativeEngine* engine,
#ifdef ENABLE_HITRACE
traceId_ = std::make_unique<OHOS::HiviewDFX::HiTraceId>(OHOS::HiviewDFX::HiTrace::GetId());
#endif
#ifdef ENABLE_CONTAINER_SCOPE
containerScopeId_ = ContainerScope::CurrentId();
#endif
}
NativeAsyncWork::~NativeAsyncWork() = default;
@@ -125,6 +135,10 @@ void NativeAsyncWork::AsyncWorkCallback(uv_work_t* req)
}
auto that = reinterpret_cast<NativeAsyncWork*>(req->data);
#ifdef ENABLE_CONTAINER_SCOPE
ContainerScope containerScope(that->containerScopeId_);
#endif
#ifdef ENABLE_HITRACE
if (that->traceId_ && that->traceId_->IsValid()) {
OHOS::HiviewDFX::HiTrace::SetId(*(that->traceId_.get()));
@@ -172,6 +186,9 @@ void NativeAsyncWork::AsyncAfterWorkCallback(uv_work_t* req, int status)
default:
nstatus = napi_generic_failure;
}
#ifdef ENABLE_CONTAINER_SCOPE
ContainerScope containerScope(that->containerScopeId_);
#endif
#ifdef ENABLE_HITRACE
if (that->traceId_ && that->traceId_->IsValid()) {
OHOS::HiviewDFX::HiTrace::SetId(*(that->traceId_.get()));
+4 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@@ -85,6 +85,9 @@ private:
#ifdef ENABLE_HITRACE
std::unique_ptr<OHOS::HiviewDFX::HiTraceId> traceId_;
#endif
#ifdef ENABLE_CONTAINER_SCOPE
int32_t containerScopeId_;
#endif
};
#endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_ASYNC_WORK_H */