From 430d2845a5122684276dc72c42732e99809e9b8d Mon Sep 17 00:00:00 2001 From: quiet-thought Date: Tue, 8 Nov 2022 19:24:11 +0800 Subject: [PATCH] Fix lack node problem https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5Z1J9 Signed-off-by: quiet-thought Change-Id: Ie333db958a3cb373cb9ca06e014436ba6722417e --- BUILD.gn | 9 +++++++-- test/test_helper.gni | 1 + tooling/BUILD.gn | 4 ++++ tooling/agent/heapprofiler_impl.cpp | 26 +++++++++++++++++++++++--- tooling/agent/heapprofiler_impl.h | 7 +++++-- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 2942d1e9..067ac81e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,7 +29,7 @@ config("ark_toolchain_common_config") { "-fasynchronous-unwind-tables", "-Wformat=2", ] - + include_dirs = [ "//third_party/libuv/include" ] if (is_linux) { defines += [ "PANDA_TARGET_UNIX", @@ -124,6 +124,7 @@ group("ark_toolchain_packages") { deps += [ "//arkcompiler/toolchain/inspector:ark_debugger", "//arkcompiler/toolchain/tooling:libark_ecma_debugger", + "//third_party/libuv:uv", ] } } @@ -132,7 +133,10 @@ group("ark_toolchain_unittest") { testonly = true deps = [] if (host_os != "mac") { - deps += [ "//arkcompiler/toolchain/tooling/test:unittest" ] + deps += [ + "//arkcompiler/toolchain/tooling/test:unittest", + "//third_party/libuv:uv", + ] if (is_ohos && is_standard_system) { deps += [ "//arkcompiler/toolchain/test/fuzztest:fuzztest" ] } @@ -153,5 +157,6 @@ group("ark_js_host_unittest") { deps = [ "//arkcompiler/ets_runtime:ark_runtime_host_unittest", "//arkcompiler/toolchain:ark_toolchain_host_unittest", + "//third_party/libuv:uv", ] } diff --git a/test/test_helper.gni b/test/test_helper.gni index 0ab7c137..a2f9e516 100644 --- a/test/test_helper.gni +++ b/test/test_helper.gni @@ -54,6 +54,7 @@ template("host_unittest_action") { rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime:" + rebase_path(_root_out_dir_) + "/test/test:" + rebase_path(_root_out_dir_) + "/${_icu_path_}:" + + rebase_path(_root_out_dir_) + "/thirdparty/libuv:" + rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), "--timeout-limit", "1200", diff --git a/tooling/BUILD.gn b/tooling/BUILD.gn index 80c5b6d1..26ec4d8d 100644 --- a/tooling/BUILD.gn +++ b/tooling/BUILD.gn @@ -58,6 +58,7 @@ source_set("libark_ecma_debugger_set") { deps = [ "$ark_root/libpandafile:arkfile_header_deps", "//third_party/cJSON:cjson_static", + "//third_party/libuv:uv", ] if (is_mingw || is_mac) { @@ -95,6 +96,7 @@ ohos_shared_library("libark_ecma_debugger") { deps = [ ":libark_ecma_debugger_set", "//arkcompiler/ets_runtime:libark_jsruntime", + "//third_party/libuv:uv", ] install_enable = true @@ -134,6 +136,7 @@ source_set("libark_ecma_debugger_test_set") { deps = [ "$ark_root/libpandafile:arkfile_header_deps", "//third_party/cJSON:cjson_static", + "//third_party/libuv:uv", ] } @@ -141,6 +144,7 @@ ohos_shared_library("libark_ecma_debugger_test") { deps = [ ":libark_ecma_debugger_test_set", "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//third_party/libuv:uv", ] if (is_ohos && is_standard_system) { diff --git a/tooling/agent/heapprofiler_impl.cpp b/tooling/agent/heapprofiler_impl.cpp index b87babf2..8552f906 100644 --- a/tooling/agent/heapprofiler_impl.cpp +++ b/tooling/agent/heapprofiler_impl.cpp @@ -16,6 +16,7 @@ #include "agent/heapprofiler_impl.h" namespace panda::ecmascript::tooling { +static constexpr int32_t MILLI_TO_MICRO = 1000; void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { static std::unordered_map dispatcherTable { @@ -300,7 +301,16 @@ DispatchResponse HeapProfilerImpl::StartSampling([[maybe_unused]]const StartSamp DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects(const StartTrackingHeapObjectsParams ¶ms) { bool traceAllocation = params.GetTrackAllocations(); - bool result = panda::DFXJSNApi::StartHeapTracking(vm_, INTERVAL, true, &stream_, traceAllocation); + bool result = panda::DFXJSNApi::StartHeapTracking(vm_, INTERVAL, true, &stream_, traceAllocation, false); + + uv_loop_t *loop = reinterpret_cast(vm_->GetLoop()); + uv_timer_init(loop, &handle_); + handle_.data = this; + uv_timer_start(&handle_, HeapTrackingCallback, 0, INTERVAL * MILLI_TO_MICRO); + + uv_work_t *work = new uv_work_t; + uv_queue_work(loop, work, [](uv_work_t *) { }, [](uv_work_t *work, int32_t) { delete work; }); + if (result) { return DispatchResponse::Ok(); } else { @@ -308,6 +318,15 @@ DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects(const StartTrackingH } } +void HeapProfilerImpl::HeapTrackingCallback(uv_timer_t* handle) +{ + HeapProfilerImpl *heapProfilerImpl = static_cast(handle->data); + if (heapProfilerImpl == nullptr) { + return; + } + panda::DFXJSNApi::UpdateHeapTracking(heapProfilerImpl->vm_, &(heapProfilerImpl->stream_)); +} + DispatchResponse HeapProfilerImpl::StopSampling([[maybe_unused]]std::unique_ptr *profile) { return DispatchResponse::Fail("StopSampling not support now."); @@ -318,10 +337,11 @@ DispatchResponse HeapProfilerImpl::StopTrackingHeapObjects(const StopTrackingHea bool result = false; if (params.GetReportProgress()) { HeapProfilerProgress progress(&frontend_); - result = panda::DFXJSNApi::StopHeapTracking(vm_, &stream_, &progress); + result = panda::DFXJSNApi::StopHeapTracking(vm_, &stream_, &progress, false); } else { - result = panda::DFXJSNApi::StopHeapTracking(vm_, &stream_, nullptr); + result = panda::DFXJSNApi::StopHeapTracking(vm_, &stream_, nullptr, false); } + uv_timer_stop(&handle_); if (result) { return DispatchResponse::Ok(); } else { diff --git a/tooling/agent/heapprofiler_impl.h b/tooling/agent/heapprofiler_impl.h index 80eca16f..615d38c1 100644 --- a/tooling/agent/heapprofiler_impl.h +++ b/tooling/agent/heapprofiler_impl.h @@ -16,6 +16,8 @@ #ifndef ECMASCRIPT_TOOLING_AGENT_HEAPPROFILER_IMPL_H #define ECMASCRIPT_TOOLING_AGENT_HEAPPROFILER_IMPL_H +#include + #include "base/pt_params.h" #include "base/pt_events.h" #include "base/pt_returns.h" @@ -30,8 +32,7 @@ #include -static const double INTERVAL = 0.05; - +static const double INTERVAL = 0.2; namespace panda::ecmascript::tooling { class HeapProfilerImpl final { public: @@ -49,6 +50,7 @@ public: DispatchResponse GetSamplingProfile(std::unique_ptr *profile); DispatchResponse StartSampling(const StartSamplingParams ¶ms); DispatchResponse StartTrackingHeapObjects(const StartTrackingHeapObjectsParams ¶ms); + static void HeapTrackingCallback(uv_timer_t* handle); DispatchResponse StopSampling(std::unique_ptr *profile); DispatchResponse StopTrackingHeapObjects(const StopTrackingHeapObjectsParams ¶ms); // The params type of TakeHeapSnapshot is the same as of StopTrackingHeapObjects. @@ -170,6 +172,7 @@ private: const EcmaVM *vm_ {nullptr}; Frontend frontend_; HeapProfilerStream stream_; + uv_timer_t handle_; }; } // namespace panda::ecmascript::tooling #endif \ No newline at end of file -- Gitee