mirror of
https://github.com/openharmony/js_sys_module.git
synced 2026-07-01 22:04:01 -04:00
Modify and supplement the stack column printing code of DFX module
上传dfx模块代码,增加native栈栈列打印功能 https://gitee.com/openharmony/ark_js_runtime/issues/I4VB5Z Signed-off-by: shikai-123 <shikai25@huawei.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "native_engine.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "securec.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
namespace OHOS::Js_sys_module::Dfx {
|
||||
@@ -53,9 +54,14 @@ namespace OHOS::Js_sys_module::Dfx {
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
|
||||
std::string stackTraceResult = engine->BuildNativeAndJsBackStackTrace();
|
||||
std::string stackTraceResult = "";
|
||||
bool temp = engine->BuildNativeAndJsBackStackTrace(stackTraceResult);
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, stackTraceResult.c_str(), stackTraceResult.size(), &result));
|
||||
return result;
|
||||
if (temp) {
|
||||
return result;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static napi_value StartHeapTracking(napi_env env, napi_callback_info info)
|
||||
@@ -66,11 +72,21 @@ namespace OHOS::Js_sys_module::Dfx {
|
||||
NAPI_ASSERT(env, argc <= requireArgc, "Wrong number of arguments");
|
||||
napi_value *argv = nullptr;
|
||||
argv = new napi_value[argc];
|
||||
NAPI_ASSERT(env, argc > 0, "argc == 0");
|
||||
argv = new napi_value[argc + 1];
|
||||
if (memset_s(argv, argc + 1, 0, argc + 1) != 0) {
|
||||
HILOG_ERROR("argv memset error");
|
||||
delete []argv;
|
||||
argv = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
double timeInterval = 0;
|
||||
napi_get_value_double(env, argv[0], &timeInterval);
|
||||
bool isVmMode = true;
|
||||
napi_get_value_bool(env, argv[1], &isVmMode);
|
||||
delete []argv;
|
||||
argv = nullptr;
|
||||
NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
|
||||
auto startResult = engine->StartHeapTracking(timeInterval, isVmMode);
|
||||
napi_value result = nullptr;
|
||||
|
||||
@@ -70,12 +70,12 @@ namespace OHOS::Js_sys_module::Process {
|
||||
{
|
||||
int ret = pipe(stdOutFd_);
|
||||
if (ret < 0) {
|
||||
HILOG_ERROR("pipe1 faile %{public}d", errno);
|
||||
HILOG_ERROR("pipe1 failed %{public}d", errno);
|
||||
return;
|
||||
}
|
||||
ret = pipe(stdErrFd_);
|
||||
if (ret < 0) {
|
||||
HILOG_ERROR("pipe2 faile %{public}d", errno);
|
||||
HILOG_ERROR("pipe2 failed %{public}d", errno);
|
||||
return;
|
||||
}
|
||||
std::string strCommnd = RequireStrValue(command);
|
||||
|
||||
@@ -92,16 +92,16 @@ namespace OHOS::Js_sys_module::Process {
|
||||
if (std::find(pgrous.begin(), pgrous.end(), proegid) == pgrous.end()) {
|
||||
pgrous.push_back(proegid);
|
||||
}
|
||||
std::vector<uint32_t> arry;
|
||||
std::vector<uint32_t> array;
|
||||
for (auto iter = pgrous.begin(); iter != pgrous.end(); iter++) {
|
||||
auto recive = static_cast<uint32_t>(*iter);
|
||||
arry.push_back(recive);
|
||||
array.push_back(recive);
|
||||
}
|
||||
NAPI_CALL(env_, napi_create_array(env_, &result));
|
||||
size_t len = arry.size();
|
||||
size_t len = array.size();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
napi_value numvalue = nullptr;
|
||||
NAPI_CALL(env_, napi_create_uint32(env_, arry[i], &numvalue));
|
||||
NAPI_CALL(env_, napi_create_uint32(env_, array[i], &numvalue));
|
||||
NAPI_CALL(env_, napi_set_element(env_, result, i, numvalue));
|
||||
}
|
||||
return result;
|
||||
@@ -290,7 +290,7 @@ namespace OHOS::Js_sys_module::Process {
|
||||
auto prouid = static_cast<int32_t>(getuid());
|
||||
auto uid = prouid % PER_USER_RANGE;
|
||||
if ((uid >= 99000 && uid <= 99999) || // 99999:Only isolateuid numbers between 99000 and 99999.
|
||||
(uid >= 9000 && uid <= 98999)) { // 98999:Only appuid numbers betweeen 9000 and 98999.
|
||||
(uid >= 9000 && uid <= 98999)) { // 98999:Only appuid numbers between 9000 and 98999.
|
||||
NAPI_CALL(env_, napi_get_boolean(env_, flag, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user