提交 07d320ce 编写于 作者: Z zhou-liting125

add bytrace

Signed-off-by: Nzhou-liting125 <zhouliting5@huawei.com>
上级 aba5a43c
......@@ -25,10 +25,14 @@ ohos_shared_library("rpc") {
"$SUBSYSTEM_DIR/utils/include",
"//foundation/ace/napi/interfaces/kits",
"//utils/system/safwk/native/include",
"$SUBSYSTEM_DIR/ipc/native/c/adapter/bytrace/include",
"$SUBSYSTEM_DIR/ipc/native/c/adapter/include",
]
public_configs = [ ":rpc_public_config" ]
sources = [
"$SUBSYSTEM_DIR/ipc/native/c/adapter/bytrace/source/rpc_bytrace.c",
"$SUBSYSTEM_DIR/ipc/native/c/adapter/bytrace/source/rpc_bytrace_inner.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_ashmem.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_message_option.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_message_parcel.cpp",
......@@ -43,6 +47,7 @@ ohos_shared_library("rpc") {
]
external_deps = [
"bytrace_standard:bytrace_core",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
......
/*
* Copyright (C) 2021 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 RPC_BYTRACE_INNER_H
#define RPC_BYTRACE_INNER_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void RpcStartTraceInner(uint64_t label, const char *value);
void RpcFinishTraceInner(uint64_t label);
void RpcStartAsyncTraceInner(uint64_t label, const char *value, int32_t TraceId);
void RpcFinishAsyncTraceInner(uint64_t label, const char *value, int32_t TraceId);
void RpcMiddleTraceInner(uint64_t label, const char *beforeValue, const char *afterValue);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
/*
* Copyright (C) 2021 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 "rpc_bytrace.h"
#include <stddef.h>
#include <stdint.h>
#include "rpc_bytrace_inner.h"
static const uint64_t BYTRACE_TAG_RPC = (1ULL << 46); // RPC and IPC tag.
void RpcStartTrace(const char *value)
{
if (value == NULL) {
return;
}
RpcStartTraceInner(BYTRACE_TAG_RPC, value);
}
void RpcFinishTrace(void)
{
RpcFinishTraceInner(BYTRACE_TAG_RPC);
}
void RpcStartAsyncTrace(const char *value, int32_t TraceId)
{
if (value == NULL) {
return;
}
RpcStartAsyncTraceInner(BYTRACE_TAG_RPC, value, TraceId);
}
void RpcFinishAsyncTrace(const char *value, int32_t TraceId)
{
if (value == NULL) {
return;
}
RpcFinishAsyncTraceInner(BYTRACE_TAG_RPC, value, TraceId);
}
void RpcMiddleTrace(const char *beforeValue, const char *afterValue)
{
if (beforeValue == NULL || afterValue == NULL) {
return;
}
RpcMiddleTraceInner(BYTRACE_TAG_RPC, beforeValue, afterValue);
}
\ No newline at end of file
/*
* Copyright (C) 2021 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 "rpc_bytrace_inner.h"
#include <cstddef>
#include <cstdint>
#include "bytrace.h"
using namespace std;
void RpcStartTraceInner(uint64_t label, const char *value)
{
if (value == nullptr) {
return;
}
StartTrace(label, value);
}
void RpcFinishTraceInner(uint64_t label)
{
FinishTrace(label);
}
void RpcStartAsyncTraceInner(uint64_t label, const char *value, int32_t TraceId)
{
if (value == nullptr) {
return;
}
StartAsyncTrace(label, value, TraceId);
}
void RpcFinishAsyncTraceInner(uint64_t label, const char *value, int32_t TraceId)
{
if (value == nullptr) {
return;
}
FinishAsyncTrace(label, value, TraceId);
}
void RpcMiddleTraceInner(uint64_t label, const char *beforeValue, const char *afterValue)
{
if (beforeValue == nullptr || afterValue == nullptr) {
return;
}
MiddleTrace(label, beforeValue, afterValue);
}
\ No newline at end of file
/*
* Copyright (C) 2021 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 <stdint.h>
#include "rpc_bytrace.h"
void RpcStartTrace(const char *value)
{
return;
}
void RpcFinishTrace(void)
{
return;
}
void RpcStartAsyncTrace(const char *value, int32_t TraceId)
{
return;
}
void RpcFinishAsyncTrace(const char *value, int32_t TraceId)
{
return;
}
void RpcMiddleTrace(const char *beforeValue, const char *afterValue)
{
return;
}
\ No newline at end of file
/*
* Copyright (C) 2021 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 RPC_BYTRACE_H
#define RPC_BYTRACE_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void RpcStartTrace(const char *value);
void RpcFinishTrace(void);
void RpcStartAsyncTrace(const char *value, int32_t TraceId);
void RpcFinishAsyncTrace(const char *value, int32_t TraceId);
void RpcMiddleTrace(const char *beforeValue, const char *afterValue);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
......@@ -21,6 +21,7 @@
#include "napi/native_node_api.h"
#include "refbase.h"
constexpr size_t TRACESIZE = 64;
namespace OHOS {
EXTERN_C_START
napi_value NAPIIPCSkeletonExport(napi_env env, napi_value exports);
......@@ -98,6 +99,8 @@ EXTERN_C_END
napi_ref jsReplyRef;
napi_ref callback;
napi_env env;
char traceVaue[TRACESIZE];
int32_t traceId;
};
} // namespace OHOS
#endif // NAPI_IPC_OHOS_REMOTE_OBJECT_H
\ No newline at end of file
......@@ -29,8 +29,11 @@
#include "log_tags.h"
#include "napi_message_option.h"
#include "napi_message_parcel.h"
#include "rpc_bytrace.h"
#include "string_ex.h"
static std::atomic<int32_t> bytraceId = 1000;
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC, "napi_remoteObject" };
#ifndef TITLE
......@@ -1185,7 +1188,9 @@ void StubExecuteSendRequest(napi_env env, SendRequestParam *param)
param->errCode = param->target->SendRequest(param->code,
*(param->data.get()), *(param->reply.get()), param->option);
DBINDER_LOGI("sendRequest done, errCode:%{public}d", param->errCode);
if (param->traceId != 0) {
RpcFinishAsyncTrace(param->traceVaue, param->traceId);
}
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(env, &loop);
uv_work_t *work = new uv_work_t;
......@@ -1245,7 +1250,18 @@ napi_value StubSendRequestAsync(napi_env env, sptr<IRemoteObject> target, uint32
.jsReplyRef = nullptr,
.callback = nullptr,
.env = env,
.traceVaue = "",
.traceId = 0,
};
IPCObjectProxy *targetProxy = reinterpret_cast<IPCObjectProxy *>(target.GetRefPtr());
if (targetProxy != nullptr) {
std::u16string remoteDescriptor = targetProxy->GetInterfaceDescriptor();
if (sprintf_s(sendRequestParam->traceVaue, sizeof(sendRequestParam->traceVaue), "%s:%d",
Str16ToStr8(remoteDescriptor).c_str(), code) > 0) {
sendRequestParam->traceId = bytraceId.fetch_add(1, std::memory_order_seq_cst);
RpcStartAsyncTrace(sendRequestParam->traceVaue, sendRequestParam->traceId);
}
}
napi_create_reference(env, argv[0], 1, &sendRequestParam->jsCodeRef);
napi_create_reference(env, argv[1], 1, &sendRequestParam->jsDataRef);
napi_create_reference(env, argv[2], 1, &sendRequestParam->jsReplyRef);
......@@ -1278,7 +1294,18 @@ napi_value StubSendRequestPromise(napi_env env, sptr<IRemoteObject> target, uint
.jsReplyRef = nullptr,
.callback = nullptr,
.env = env,
.traceVaue = "",
.traceId = 0,
};
IPCObjectProxy *targetProxy = reinterpret_cast<IPCObjectProxy *>(target.GetRefPtr());
if (targetProxy != nullptr) {
std::u16string remoteDescriptor = targetProxy->GetInterfaceDescriptor();
if (sprintf_s(sendRequestParam->traceVaue, sizeof(sendRequestParam->traceVaue), "%s:%d",
Str16ToStr8(remoteDescriptor).c_str(), code) > 0) {
sendRequestParam->traceId = bytraceId.fetch_add(1, std::memory_order_seq_cst);
RpcStartAsyncTrace(sendRequestParam->traceVaue, sendRequestParam->traceId);
}
}
napi_create_reference(env, argv[0], 1, &sendRequestParam->jsCodeRef);
napi_create_reference(env, argv[1], 1, &sendRequestParam->jsDataRef);
napi_create_reference(env, argv[2], 1, &sendRequestParam->jsReplyRef);
......@@ -1393,6 +1420,9 @@ void ExecuteSendRequest(napi_env env, void *data)
param->errCode = param->target->SendRequest(param->code,
*(param->data.get()), *(param->reply.get()), param->option);
DBINDER_LOGI("sendRequest done, errCode:%{public}d", param->errCode);
if (param->traceId != 0) {
RpcFinishAsyncTrace(param->traceVaue, param->traceId);
}
}
// This method runs on the main thread after 'ExecuteSendRequest' exits
......@@ -1435,6 +1465,7 @@ napi_value SendRequestAsync(napi_env env, sptr<IRemoteObject> target, uint32_t c
std::shared_ptr<MessageParcel> data, std::shared_ptr<MessageParcel> reply,
MessageOption &option, napi_value *argv)
{
napi_value result = nullptr;
SendRequestParam *sendRequestParam = new SendRequestParam {
.target = target,
.code = code,
......@@ -1449,7 +1480,18 @@ napi_value SendRequestAsync(napi_env env, sptr<IRemoteObject> target, uint32_t c
.jsReplyRef = nullptr,
.callback = nullptr,
.env = env,
.traceVaue = "",
.traceId = 0,
};
IPCObjectProxy *targetProxy = reinterpret_cast<IPCObjectProxy *>(target.GetRefPtr());
if (targetProxy != nullptr) {
std::u16string remoteDescriptor = targetProxy->GetInterfaceDescriptor();
if (sprintf_s(sendRequestParam->traceVaue, sizeof(sendRequestParam->traceVaue), "%s:%d",
Str16ToStr8(remoteDescriptor).c_str(), code) > 0) {
sendRequestParam->traceId = bytraceId.fetch_add(1, std::memory_order_seq_cst);
RpcStartAsyncTrace(sendRequestParam->traceVaue, sendRequestParam->traceId);
}
}
napi_create_reference(env, argv[0], 1, &sendRequestParam->jsCodeRef);
napi_create_reference(env, argv[1], 1, &sendRequestParam->jsDataRef);
napi_create_reference(env, argv[2], 1, &sendRequestParam->jsReplyRef);
......@@ -1459,7 +1501,6 @@ napi_value SendRequestAsync(napi_env env, sptr<IRemoteObject> target, uint32_t c
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName, ExecuteSendRequest,
SendRequestCbComplete, (void *)sendRequestParam, &sendRequestParam->asyncWork));
NAPI_CALL(env, napi_queue_async_work(env, sendRequestParam->asyncWork));
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
......@@ -1485,7 +1526,18 @@ napi_value SendRequestPromise(napi_env env, sptr<IRemoteObject> target, uint32_t
.jsReplyRef = nullptr,
.callback = nullptr,
.env = env,
.traceVaue = "",
.traceId = 0,
};
IPCObjectProxy *targetProxy = reinterpret_cast<IPCObjectProxy *>(target.GetRefPtr());
if (targetProxy != nullptr) {
std::u16string remoteDescriptor = targetProxy->GetInterfaceDescriptor();
if (sprintf_s(sendRequestParam->traceVaue, sizeof(sendRequestParam->traceVaue), "%s:%d",
Str16ToStr8(remoteDescriptor).c_str(), code) > 0) {
sendRequestParam->traceId = bytraceId.fetch_add(1, std::memory_order_seq_cst);
RpcStartAsyncTrace(sendRequestParam->traceVaue, sendRequestParam->traceId);
}
}
napi_create_reference(env, argv[0], 1, &sendRequestParam->jsCodeRef);
napi_create_reference(env, argv[1], 1, &sendRequestParam->jsDataRef);
napi_create_reference(env, argv[2], 1, &sendRequestParam->jsReplyRef);
......@@ -1533,7 +1585,6 @@ napi_value NAPI_RemoteProxy_sendRequest(napi_env env, napi_callback_info info)
NAPI_ASSERT(env, proxyHolder != nullptr, "failed to get proxy holder");
sptr<IRemoteObject> target = proxyHolder->object_;
NAPI_ASSERT(env, target != nullptr, "invalid proxy object");
if (argc == argcCallback) {
napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
napi_valuetype valuetype = napi_undefined;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册