diff --git a/ecmascript/dfx/hprof/heap_profiler.cpp b/ecmascript/dfx/hprof/heap_profiler.cpp index 06ba227351067f6452ae91ff94ff12724d5d9bcd..d7b6cef38f1b067e08785bb95f95e31ac0c5aac0 100755 --- a/ecmascript/dfx/hprof/heap_profiler.cpp +++ b/ecmascript/dfx/hprof/heap_profiler.cpp @@ -408,7 +408,8 @@ bool HeapProfiler::DumpHeapSnapshot(Stream *stream, const DumpSnapShotOption &du } } AppFreezeFilterCallback appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); - if (appfreezeCallback != nullptr && !appfreezeCallback(getpid(), false)) { + std::string unused; + if (appfreezeCallback != nullptr && !appfreezeCallback(getpid(), false, unused)) { LOG_ECMA(ERROR) << "failed to set appfreeze filter"; return false; } diff --git a/ecmascript/dfx/hprof/heap_profiler_interface.cpp b/ecmascript/dfx/hprof/heap_profiler_interface.cpp index 9ea6a21e3483587daea4f56fe718c5c887c43a1d..d39cd8631201dc84aaa04fb58b679f50f3a0fe7e 100644 --- a/ecmascript/dfx/hprof/heap_profiler_interface.cpp +++ b/ecmascript/dfx/hprof/heap_profiler_interface.cpp @@ -48,7 +48,10 @@ void panda::ecmascript::HeapProfilerInterface::DumpHeapSnapshotForCMCOOM(void *t } auto appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); - if (appfreezeCallback != nullptr && !appfreezeCallback(getprocpid(), true)) { + std::string eventConfig; + bool shouldDump = appfreezeCallback == nullptr || appfreezeCallback(getprocpid(), true, eventConfig); + vm->GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", 0, 0, eventConfig); + if (!shouldDump) { LOG_ECMA(INFO) << "DumpHeapSnapshotForCMCOOM, no dump quota."; return; } @@ -58,7 +61,6 @@ void panda::ecmascript::HeapProfilerInterface::DumpHeapSnapshotForCMCOOM(void *t dumpOption.isFullGC = false; dumpOption.isDumpOOM = true; - vm->GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", 0, 0); vm->GetOrNewHeapProfile()->DumpHeapSnapshotForOOM(dumpOption); #endif } diff --git a/ecmascript/mem/gc_key_stats.cpp b/ecmascript/mem/gc_key_stats.cpp index ddc47c410954cc070dbca3e920b7764674025fb0..e060b76c5f2a8a64e59549ad81669c0f630de8c3 100644 --- a/ecmascript/mem/gc_key_stats.cpp +++ b/ecmascript/mem/gc_key_stats.cpp @@ -113,7 +113,8 @@ void GCKeyStats::SendSysEvent() const #endif } -void GCKeyStats::SendSysEventBeforeDump(std::string type, size_t limitSize, size_t activeMemory) const +void GCKeyStats::SendSysEventBeforeDump(std::string type, size_t limitSize, size_t activeMemory, + const std::string &eventConfig) const { #ifdef ENABLE_HISYSEVENT int32_t ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::FRAMEWORK, @@ -125,6 +126,7 @@ void GCKeyStats::SendSysEventBeforeDump(std::string type, size_t limitSize, size "LIMITSIZE", limitSize, "ACTIVE_MEMORY", activeMemory, "TYPE", type, + "EVENT_CONFIG", eventConfig, "APP_RUNNING_UNIQUE_ID", &DFX_GetAppRunningUniqueId == nullptr ? "" : DFX_GetAppRunningUniqueId()); if (ret != 0) { LOG_GC(ERROR) << "GCKeyStats SendSysEventBeforeDump Failed! ret = " << ret; diff --git a/ecmascript/mem/gc_key_stats.h b/ecmascript/mem/gc_key_stats.h index c4d3d32a5a7817c66c9da547a4b21580c234d131..c8f49b0569301a973d7b655ff1b7b7789caffcd3 100644 --- a/ecmascript/mem/gc_key_stats.h +++ b/ecmascript/mem/gc_key_stats.h @@ -18,6 +18,7 @@ #include #include +#include #include "ecmascript/common_enum.h" #include "ecmascript/mem/mem_common.h" @@ -69,7 +70,8 @@ public: void AddGCStatsToKey(); bool CheckIfMainThread() const; bool CheckIfKeyPauseTime() const; - void SendSysEventBeforeDump(std::string type, size_t limitSize, size_t activeMemory) const; + void SendSysEventBeforeDump(std::string type, size_t limitSize, size_t activeMemory, + const std::string &eventConfig) const; int32_t SendSysEventDataSize(std::vector filePaths, std::vector fileSizes) const; void ProcessLongGCEvent(); static bool IsIdle(GCReason gcReason) diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index 9c1bc4066e6de9d84b5d3583e9ebd61408ee0573..93e332b1108d339b8edc20ad43950548e82c4442 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -790,14 +790,18 @@ void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]JSThread *thread, { #if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(ENABLE_DUMP_IN_FAULTLOG) AppFreezeFilterCallback appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); - if (appfreezeCallback != nullptr && !appfreezeCallback(getprocpid(), true)) { + std::string eventConfig; + bool shouldDump = (appfreezeCallback == nullptr || appfreezeCallback(getprocpid(), true, eventConfig)); + EcmaVM *vm = thread->GetEcmaVM(); + vm->GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", GetEcmaParamConfiguration().GetMaxHeapSize(), + GetHeapObjectSize(), eventConfig); + if (!shouldDump) { LOG_ECMA(INFO) << "SharedHeap::DumpHeapSnapshotBeforeOOM, no dump quota."; return; } #endif #if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) #if defined(ENABLE_DUMP_IN_FAULTLOG) - EcmaVM *vm = thread->GetEcmaVM(); HeapProfilerInterface *heapProfile = nullptr; if (source == SharedHeapOOMSource::SHARED_GC) { #ifndef NDEBUG @@ -815,8 +819,6 @@ void SharedHeap::DumpHeapSnapshotBeforeOOM([[maybe_unused]]JSThread *thread, // Filter appfreeze when dump. LOG_ECMA(INFO) << "SharedHeap::DumpHeapSnapshotBeforeOOM, trigger oom dump"; base::BlockHookScope blockScope; - vm->GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", GetEcmaParamConfiguration().GetMaxHeapSize(), - GetHeapObjectSize()); DumpSnapShotOption dumpOption; dumpOption.dumpFormat = DumpFormat::BINARY; dumpOption.isVmMode = true; @@ -1704,7 +1706,10 @@ void Heap::DumpHeapSnapshotBeforeOOM() { #if defined(ECMASCRIPT_SUPPORT_SNAPSHOT) && defined(ENABLE_DUMP_IN_FAULTLOG) AppFreezeFilterCallback appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); - if (appfreezeCallback != nullptr && !appfreezeCallback(getprocpid(), true)) { + std::string eventConfig; + bool shouldDump = (appfreezeCallback == nullptr || appfreezeCallback(getprocpid(), true, eventConfig)); + GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", GetHeapLimitSize(), GetLiveObjectSize(), eventConfig); + if (!shouldDump) { LOG_ECMA(INFO) << "Heap::DumpHeapSnapshotBeforeOOM, no dump quota."; return; } @@ -1719,10 +1724,7 @@ void Heap::DumpHeapSnapshotBeforeOOM() LOG_ECMA(INFO) << " Heap::DumpHeapSnapshotBeforeOOM, trigger oom dump"; base::BlockHookScope blockScope; HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(ecmaVm_); -#ifdef ENABLE_HISYSEVENT - GetEcmaGCKeyStats()->SendSysEventBeforeDump("OOMDump", GetHeapLimitSize(), GetLiveObjectSize()); hasOOMDump_ = true; -#endif // Vm should always allocate young space successfully. Really OOM will occur in the non-young spaces. DumpSnapShotOption dumpOption; dumpOption.dumpFormat = DumpFormat::BINARY; @@ -2978,13 +2980,16 @@ void Heap::ThresholdReachedDump() base::BlockHookScope blockScope; HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(ecmaVm_); AppFreezeFilterCallback appfreezeCallback = Runtime::GetInstance()->GetAppFreezeFilterCallback(); - if (appfreezeCallback != nullptr && appfreezeCallback(getprocpid(), true)) { + std::string eventConfig; + bool shouldDump = (appfreezeCallback == nullptr || appfreezeCallback(getprocpid(), true, eventConfig)); + GetEcmaGCKeyStats()->SendSysEventBeforeDump("thresholdReachedDump", + GetHeapLimitSize(), GetLiveObjectSize(), eventConfig); + if (shouldDump) { LOG_ECMA(INFO) << "ThresholdReachedDump and avoid freeze success."; } else { LOG_ECMA(WARN) << "ThresholdReachedDump but avoid freeze failed."; + return; } - GetEcmaGCKeyStats()->SendSysEventBeforeDump("thresholdReachedDump", - GetHeapLimitSize(), GetLiveObjectSize()); DumpSnapShotOption dumpOption; dumpOption.dumpFormat = DumpFormat::BINARY; dumpOption.isVmMode = true; diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index bd6db36ec50a4514a28fe8bcaaa9919a7a019b3e..be8bce6e74f826ff6395005db797f676ef50d5cb 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -83,7 +83,8 @@ using IdleNotifyStatusCallback = std::function; using FinishGCListener = void (*)(void *); using GCListenerId = std::vector>::const_iterator; using Clock = std::chrono::high_resolution_clock; -using AppFreezeFilterCallback = std::function; +using AppFreezeFilterCallback = + std::function; using BytesAndDuration = std::pair; using MemoryReduceDegree = panda::JSNApi::MemoryReduceDegree; using NativePointerList = CVector; diff --git a/ecmascript/napi/include/dfx_jsnapi.h b/ecmascript/napi/include/dfx_jsnapi.h index 523bbb62e0f6fa3f43fc7f231a4e9271ea92c0a5..3a72340472a9b06f3517d91e2b8a3cb8be8439a4 100644 --- a/ecmascript/napi/include/dfx_jsnapi.h +++ b/ecmascript/napi/include/dfx_jsnapi.h @@ -56,7 +56,8 @@ using JsFrameInfo = ecmascript::JsFrameInfo; using SamplingInfo = ecmascript::SamplingInfo; using DebuggerPostTask = std::function &&)>; using TraceEvent = ecmascript::TraceEvent; -using AppFreezeFilterCallback = std::function; +using AppFreezeFilterCallback = + std::function; using DumpSnapShotOption = ecmascript::DumpSnapShotOption; using DumpFormat = ecmascript::DumpFormat; using CropLevel = ecmascript::RawHeapDumpCropLevel; diff --git a/ecmascript/runtime.h b/ecmascript/runtime.h index 0baf9bfa8efe974c0ed737dce7079d1d5627df2a..3f166b60f0478ec4bc42729baf79b34688efa493 100644 --- a/ecmascript/runtime.h +++ b/ecmascript/runtime.h @@ -35,7 +35,8 @@ namespace panda::ecmascript { class EcmaStringTable; -using AppFreezeFilterCallback = std::function; +using AppFreezeFilterCallback = + std::function; using ReleaseSecureMemCallback = std::function; class Runtime { @@ -396,7 +397,7 @@ private: RawHeapDumpCropLevel rawHeapDumpCropLevel_ {RawHeapDumpCropLevel::DEFAULT}; // for 1.2runtime interface type bool isHybridVm_ {false}; - + // release secure mem after jspandafile released. ReleaseSecureMemCallback releaseSecureMemCallback_ {nullptr}; Mutex releaseSecureMemCallbackLock_;