Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
07d320ce
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
07d320ce
编写于
1月 20, 2022
作者:
Z
zhou-liting125
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add bytrace
Signed-off-by:
N
zhou-liting125
<
zhouliting5@huawei.com
>
上级
aba5a43c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
284 addition
and
3 deletion
+284
-3
interfaces/kits/js/napi/BUILD.gn
interfaces/kits/js/napi/BUILD.gn
+5
-0
ipc/native/c/adapter/bytrace/include/rpc_bytrace_inner.h
ipc/native/c/adapter/bytrace/include/rpc_bytrace_inner.h
+33
-0
ipc/native/c/adapter/bytrace/source/rpc_bytrace.c
ipc/native/c/adapter/bytrace/source/rpc_bytrace.c
+57
-0
ipc/native/c/adapter/bytrace/source/rpc_bytrace_inner.cpp
ipc/native/c/adapter/bytrace/source/rpc_bytrace_inner.cpp
+57
-0
ipc/native/c/adapter/bytrace/source/rpc_bytrace_virtual.c
ipc/native/c/adapter/bytrace/source/rpc_bytrace_virtual.c
+42
-0
ipc/native/c/adapter/include/rpc_bytrace.h
ipc/native/c/adapter/include/rpc_bytrace.h
+33
-0
ipc/native/src/napi/include/napi_remote_object.h
ipc/native/src/napi/include/napi_remote_object.h
+3
-0
ipc/native/src/napi/src/napi_remote_object.cpp
ipc/native/src/napi/src/napi_remote_object.cpp
+54
-3
未找到文件。
interfaces/kits/js/napi/BUILD.gn
浏览文件 @
07d320ce
...
...
@@ -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",
]
...
...
ipc/native/c/adapter/bytrace/include/rpc_bytrace_inner.h
0 → 100644
浏览文件 @
07d320ce
/*
* 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
ipc/native/c/adapter/bytrace/source/rpc_bytrace.c
0 → 100644
浏览文件 @
07d320ce
/*
* 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
ipc/native/c/adapter/bytrace/source/rpc_bytrace_inner.cpp
0 → 100644
浏览文件 @
07d320ce
/*
* 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
ipc/native/c/adapter/bytrace/source/rpc_bytrace_virtual.c
0 → 100644
浏览文件 @
07d320ce
/*
* 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
ipc/native/c/adapter/include/rpc_bytrace.h
0 → 100644
浏览文件 @
07d320ce
/*
* 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
ipc/native/src/napi/include/napi_remote_object.h
浏览文件 @
07d320ce
...
...
@@ -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
ipc/native/src/napi/src/napi_remote_object.cpp
浏览文件 @
07d320ce
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录