From f6a0cee827c4d40245fcc18ef29a1b2af5703ffa Mon Sep 17 00:00:00 2001 From: cwx1148594 Date: Tue, 10 Jan 2023 18:41:43 +0800 Subject: [PATCH] Descriptor: heapprofiler support GC details: heapprofiler support GC issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/I69UQN Signed-off-by: cwx1148594 --- tooling/agent/heapprofiler_impl.cpp | 4 +++- tooling/test/heapprofiler_impl_test.cpp | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tooling/agent/heapprofiler_impl.cpp b/tooling/agent/heapprofiler_impl.cpp index 8552f906..6afb2be7 100644 --- a/tooling/agent/heapprofiler_impl.cpp +++ b/tooling/agent/heapprofiler_impl.cpp @@ -261,7 +261,9 @@ DispatchResponse HeapProfilerImpl::AddInspectedHeapObject([[maybe_unused]] const DispatchResponse HeapProfilerImpl::CollectGarbage() { - return DispatchResponse::Fail("CollectGarbage not support now"); + panda::JSNApi::TriggerGC(vm_, panda::JSNApi::TRIGGER_GC_TYPE::FULL_GC); + panda::JSNApi::TriggerGC(vm_, panda::JSNApi::TRIGGER_GC_TYPE::OLD_GC); + return DispatchResponse::Ok(); } DispatchResponse HeapProfilerImpl::Enable() diff --git a/tooling/test/heapprofiler_impl_test.cpp b/tooling/test/heapprofiler_impl_test.cpp index fd3e8550..258949a2 100644 --- a/tooling/test/heapprofiler_impl_test.cpp +++ b/tooling/test/heapprofiler_impl_test.cpp @@ -64,8 +64,8 @@ HWTEST_F_L0(HeapProfilerImplTest, CollectGarbage) ProtocolChannel *channel = nullptr; auto heapProfiler = std::make_unique(ecmaVm, channel); DispatchResponse response = heapProfiler->CollectGarbage(); - ASSERT_TRUE(response.GetMessage() == "CollectGarbage not support now"); - ASSERT_TRUE(!response.IsOk()); + ASSERT_TRUE(response.GetMessage() == ""); + ASSERT_TRUE(response.IsOk()); } HWTEST_F_L0(HeapProfilerImplTest, Enable) @@ -203,7 +203,7 @@ HWTEST_F_L0(HeapProfilerImplTest, DispatcherImplCollectGarbage) std::string msg = std::string() + R"({"id":0,"method":"HeapProfiler.collectGarbage","params":{}})"; DispatchRequest request(msg); dispatcherImpl->CollectGarbage(request); - ASSERT_TRUE(result.find("CollectGarbage not support now") != std::string::npos); + ASSERT_TRUE(result == "{\"id\":0,\"result\":{}}"); if (channel) { delete channel; channel = nullptr; -- Gitee