mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
!7122 1.信号携带参数不触发id 2.信号携带参数单独触发GC
Merge pull request !7122 from Carmack/master
This commit is contained in:
@@ -116,8 +116,9 @@ enum class SignalType {
|
||||
SIGNAL_JSHEAP_OLD,
|
||||
SIGNAL_JSHEAP,
|
||||
SIGNAL_JSHEAP_PRIV,
|
||||
SIGNAL_START_SAMPLE,
|
||||
SIGNAL_STOP_SAMPLE,
|
||||
SIGNAL_NO_TRIGGERID,
|
||||
SIGNAL_NO_TRIGGERID_PRIV,
|
||||
SIGNAL_FORCE_FULLGC,
|
||||
};
|
||||
|
||||
constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME";
|
||||
@@ -2117,6 +2118,7 @@ void MainThread::HandleSignal(int signal, [[maybe_unused]] siginfo_t *siginfo, v
|
||||
{
|
||||
if (signal != MUSL_SIGNAL_JSHEAP) {
|
||||
HILOG_ERROR("HandleSignal failed, signal is %{public}d", signal);
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("HandleSignal sival_int is %{public}d", siginfo->si_value.sival_int);
|
||||
switch (static_cast<SignalType>(siginfo->si_value.sival_int)) {
|
||||
@@ -2135,12 +2137,25 @@ void MainThread::HandleSignal(int signal, [[maybe_unused]] siginfo_t *siginfo, v
|
||||
signalHandler_->PostTask(privateHeapFunc, "MainThread:SIGNAL_JSHEAP_PRIV");
|
||||
break;
|
||||
}
|
||||
case SignalType::SIGNAL_START_SAMPLE: {
|
||||
HILOG_ERROR("HandleSignal failed, SIGNAL_START_SAMPLE is retained");
|
||||
case SignalType::SIGNAL_NO_TRIGGERID: {
|
||||
auto heapFunc = std::bind(&MainThread::HandleDumpHeap, false);
|
||||
signalHandler_->PostTask(heapFunc, "MainThread::SIGNAL_JSHEAP");
|
||||
|
||||
auto noTriggerIdFunc = std::bind(&MainThread::DestroyHeapProfiler);
|
||||
signalHandler_->PostTask(noTriggerIdFunc, "MainThread::SIGNAL_NO_TRIGGERID");
|
||||
break;
|
||||
}
|
||||
case SignalType::SIGNAL_STOP_SAMPLE: {
|
||||
HILOG_ERROR("HandleSignal failed, SIGNAL_STOP_SAMPLE is retained");
|
||||
case SignalType::SIGNAL_NO_TRIGGERID_PRIV: {
|
||||
auto privateHeapFunc = std::bind(&MainThread::HandleDumpHeap, true);
|
||||
signalHandler_->PostTask(privateHeapFunc, "MainThread:SIGNAL_JSHEAP_PRIV");
|
||||
|
||||
auto noTriggerIdFunc = std::bind(&MainThread::DestroyHeapProfiler);
|
||||
signalHandler_->PostTask(noTriggerIdFunc, "MainThread::SIGNAL_NO_TRIGGERID_PRIV");
|
||||
break;
|
||||
}
|
||||
case SignalType::SIGNAL_FORCE_FULLGC: {
|
||||
auto forceFullGCFunc = std::bind(&MainThread::ForceFullGC);
|
||||
signalHandler_->PostTask(forceFullGCFunc, "MainThread:SIGNAL_FORCE_FULLGC");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2167,6 +2182,44 @@ void MainThread::HandleDumpHeap(bool isPrivate)
|
||||
mainHandler_->PostTask(task, "MainThread:DumpHeap");
|
||||
}
|
||||
|
||||
void MainThread::DestroyHeapProfiler()
|
||||
{
|
||||
HILOG_DEBUG("Destory heap profiler.");
|
||||
if (mainHandler_ == nullptr) {
|
||||
HILOG_ERROR("DestroyHeapProfiler failed, mainHandler is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto task = [] {
|
||||
auto app = applicationForDump_.lock();
|
||||
if (app == nullptr || app->GetRuntime() == nullptr) {
|
||||
HILOG_ERROR("runtime is nullptr.");
|
||||
return;
|
||||
}
|
||||
app->GetRuntime()->DestroyHeapProfiler();
|
||||
};
|
||||
mainHandler_->PostTask(task, "MainThread:DestroyHeapProfiler");
|
||||
}
|
||||
|
||||
void MainThread::ForceFullGC()
|
||||
{
|
||||
HILOG_DEBUG("Force fullGC.");
|
||||
if (mainHandler_ == nullptr) {
|
||||
HILOG_ERROR("ForceFullGC failed, mainHandler is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto task = [] {
|
||||
auto app = applicationForDump_.lock();
|
||||
if (app == nullptr || app->GetRuntime() == nullptr) {
|
||||
HILOG_ERROR("runtime is nullptr.");
|
||||
return;
|
||||
}
|
||||
app->GetRuntime()->ForceFullGC();
|
||||
};
|
||||
mainHandler_->PostTask(task, "MainThread:ForceFullGC");
|
||||
}
|
||||
|
||||
void MainThread::Start()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
|
||||
@@ -1056,6 +1056,19 @@ void JsRuntime::DumpHeapSnapshot(bool isPrivate)
|
||||
nativeEngine->DumpHeapSnapshot(true, DumpFormat::JSON, isPrivate);
|
||||
}
|
||||
|
||||
void JsRuntime::DestroyHeapProfiler()
|
||||
{
|
||||
CHECK_POINTER(jsEnv_);
|
||||
jsEnv_->DestroyHeapProfiler();
|
||||
}
|
||||
|
||||
void JsRuntime::ForceFullGC()
|
||||
{
|
||||
auto vm = GetEcmaVm();
|
||||
CHECK_POINTER(vm);
|
||||
panda::JSNApi::TriggerGC(vm, panda::JSNApi::TRIGGER_GC_TYPE::FULL_GC);
|
||||
}
|
||||
|
||||
bool JsRuntime::BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames)
|
||||
{
|
||||
auto nativeEngine = GetNativeEnginePointer();
|
||||
|
||||
@@ -77,6 +77,8 @@ public:
|
||||
void PostSyncTask(const std::function<void()>& task, const std::string& name);
|
||||
void RemoveTask(const std::string& name);
|
||||
void DumpHeapSnapshot(bool isPrivate) override;
|
||||
void DestroyHeapProfiler() override;
|
||||
void ForceFullGC() override;
|
||||
bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) override;
|
||||
void NotifyApplicationState(bool isBackground) override;
|
||||
bool SuspendVM(uint32_t tid) override;
|
||||
|
||||
@@ -78,6 +78,8 @@ public:
|
||||
virtual void StartDebugMode(bool needBreakPoint, const std::string &processName, bool isDebug = true) = 0;
|
||||
virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0;
|
||||
virtual void DumpHeapSnapshot(bool isPrivate) = 0;
|
||||
virtual void DestroyHeapProfiler() = 0;
|
||||
virtual void ForceFullGC() = 0;
|
||||
virtual void NotifyApplicationState(bool isBackground) = 0;
|
||||
virtual bool SuspendVM(uint32_t tid) = 0;
|
||||
virtual void ResumeVM(uint32_t tid) = 0;
|
||||
|
||||
@@ -521,6 +521,8 @@ private:
|
||||
void UpdateRuntimeModuleChecker(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
|
||||
|
||||
static void HandleDumpHeap(bool isPrivate);
|
||||
static void DestroyHeapProfiler();
|
||||
static void ForceFullGC();
|
||||
static void HandleSignal(int signal, siginfo_t *siginfo, void *context);
|
||||
|
||||
void NotifyAppFault(const FaultData &faultData);
|
||||
|
||||
@@ -284,6 +284,15 @@ void JsEnvironment::StartProfiler(const char* libraryPath, uint32_t instanceId,
|
||||
panda::DFXJSNApi::StartProfiler(vm_, option, tid, instanceId, debuggerPostTask);
|
||||
}
|
||||
|
||||
void JsEnvironment::DestroyHeapProfiler()
|
||||
{
|
||||
if (vm_ == nullptr) {
|
||||
JSENV_LOG_E("Invalid vm.");
|
||||
return;
|
||||
}
|
||||
panda::DFXJSNApi::DestroyHeapProfiler(vm_);
|
||||
}
|
||||
|
||||
void JsEnvironment::ReInitJsEnvImpl(std::unique_ptr<JsEnvironmentImpl> impl)
|
||||
{
|
||||
JSENV_LOG_I("ReInit jsenv impl.");
|
||||
|
||||
@@ -88,6 +88,8 @@ public:
|
||||
void StartProfiler(
|
||||
const char* libraryPath, uint32_t instanceId, PROFILERTYPE profiler, int32_t interval, uint32_t tid);
|
||||
|
||||
void DestroyHeapProfiler();
|
||||
|
||||
void ReInitJsEnvImpl(std::unique_ptr<JsEnvironmentImpl> impl);
|
||||
|
||||
void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate>& moduleCheckerDelegate);
|
||||
|
||||
@@ -62,6 +62,14 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
void DestroyHeapProfiler() override
|
||||
{
|
||||
return;
|
||||
}
|
||||
void ForceFullGC() override
|
||||
{
|
||||
return;
|
||||
}
|
||||
void NotifyApplicationState(bool isBackground) override
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user