14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#include "ecmascript/mem/gc_stats.h"
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_ci#include <iomanip>
194514f5e3Sopenharmony_ci#include "ecmascript/mem/heap-inl.h"
204514f5e3Sopenharmony_ci
214514f5e3Sopenharmony_ciconstexpr int DESCRIPTION_LENGTH = 25;
224514f5e3Sopenharmony_ciconstexpr int DATA_LENGTH = 8;
234514f5e3Sopenharmony_ci
244514f5e3Sopenharmony_ci#define STATS_DESCRIPTION_FORMAT(description)    \
254514f5e3Sopenharmony_ci    std::left << std::setw(DESCRIPTION_LENGTH) << (description)
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_ci#define STATS_DATA_FORMAT(data)    \
284514f5e3Sopenharmony_ci    std::setw(DATA_LENGTH) << (data)
294514f5e3Sopenharmony_ci
304514f5e3Sopenharmony_cinamespace panda::ecmascript {
314514f5e3Sopenharmony_civoid GCStats::PrintStatisticResult()
324514f5e3Sopenharmony_ci{
334514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/******************* GCStats statistic: *******************/";
344514f5e3Sopenharmony_ci    PrintGCSummaryStatistic(GCType::PARTIAL_EDEN_GC);
354514f5e3Sopenharmony_ci    PrintGCSummaryStatistic(GCType::PARTIAL_YOUNG_GC);
364514f5e3Sopenharmony_ci    PrintGCSummaryStatistic(GCType::PARTIAL_OLD_GC);
374514f5e3Sopenharmony_ci    PrintGCSummaryStatistic(GCType::COMPRESS_GC);
384514f5e3Sopenharmony_ci    PrintGCMemoryStatistic();
394514f5e3Sopenharmony_ci}
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_civoid GCStats::PrintGCStatistic()
424514f5e3Sopenharmony_ci{
434514f5e3Sopenharmony_ci    ASSERT(heap_ != nullptr);
444514f5e3Sopenharmony_ci    ASSERT(heap_->GetEcmaVM() != nullptr);
454514f5e3Sopenharmony_ci    if (heap_->GetEcmaVM()->GetJSOptions().EnableGCTracer() || CheckIfLongTimePause()) {
464514f5e3Sopenharmony_ci        LOG_GC(INFO) << " [ " << GetGCTypeName() << " ] "
474514f5e3Sopenharmony_ci                        << sizeToMB(recordData_[(uint8_t)RecordData::START_OBJ_SIZE]) << " ("
484514f5e3Sopenharmony_ci                        << sizeToMB(recordData_[(uint8_t)RecordData::START_COMMIT_SIZE]) << ") -> "
494514f5e3Sopenharmony_ci                        << sizeToMB(recordData_[(uint8_t)RecordData::END_OBJ_SIZE]) << " ("
504514f5e3Sopenharmony_ci                        << sizeToMB(recordData_[(uint8_t)RecordData::END_COMMIT_SIZE]) << ") MB, "
514514f5e3Sopenharmony_ci                        << scopeDuration_[Scope::ScopeId::TotalGC] << "(+"
524514f5e3Sopenharmony_ci                        << GetConcurrrentMarkDuration()
534514f5e3Sopenharmony_ci                        << ")ms, " << GCReasonToString(reason_);
544514f5e3Sopenharmony_ci        LOG_GC(INFO) << "IsInBackground: " << heap_->IsInBackground() << "; "
554514f5e3Sopenharmony_ci            << "SensitiveStatus: " << static_cast<int>(heap_->GetSensitiveStatus()) << "; "
564514f5e3Sopenharmony_ci            << "OnStartupEvent: " << heap_->OnStartupEvent() << "; "
574514f5e3Sopenharmony_ci            << "BundleName: " << heap_->GetEcmaVM()->GetBundleName() << ";";
584514f5e3Sopenharmony_ci        // print verbose gc statsistics
594514f5e3Sopenharmony_ci        PrintVerboseGCStatistic();
604514f5e3Sopenharmony_ci    }
614514f5e3Sopenharmony_ci    InitializeRecordList();
624514f5e3Sopenharmony_ci}
634514f5e3Sopenharmony_ci
644514f5e3Sopenharmony_ciconst char *GCStats::GCReasonToString()
654514f5e3Sopenharmony_ci{
664514f5e3Sopenharmony_ci    return GCReasonToString(reason_);
674514f5e3Sopenharmony_ci}
684514f5e3Sopenharmony_ci
694514f5e3Sopenharmony_ciconst char *GCStats::GCReasonToString(GCReason reason)
704514f5e3Sopenharmony_ci{
714514f5e3Sopenharmony_ci    switch (reason) {
724514f5e3Sopenharmony_ci        case GCReason::ALLOCATION_LIMIT:
734514f5e3Sopenharmony_ci            return "Memory reach limit";
744514f5e3Sopenharmony_ci        case GCReason::ALLOCATION_FAILED:
754514f5e3Sopenharmony_ci            return "Allocate object failed";
764514f5e3Sopenharmony_ci        case GCReason::IDLE:
774514f5e3Sopenharmony_ci            return "Idle time task";
784514f5e3Sopenharmony_ci        case GCReason::SWITCH_BACKGROUND:
794514f5e3Sopenharmony_ci            return "Switch to background";
804514f5e3Sopenharmony_ci        case GCReason::EXTERNAL_TRIGGER:
814514f5e3Sopenharmony_ci            return "Externally triggered";
824514f5e3Sopenharmony_ci        case GCReason::WORKER_DESTRUCTION:
834514f5e3Sopenharmony_ci            return "Worker Destruction";
844514f5e3Sopenharmony_ci        case GCReason::TRIGGER_BY_JS:
854514f5e3Sopenharmony_ci            return "Trigger by JS";
864514f5e3Sopenharmony_ci        case GCReason::TRIGGER_BY_ARKUI:
874514f5e3Sopenharmony_ci            return "Trigger by ArkUI";
884514f5e3Sopenharmony_ci        case GCReason::TRIGGER_BY_ABILITY:
894514f5e3Sopenharmony_ci            return "Trigger by AbilityRuntime";
904514f5e3Sopenharmony_ci        case GCReason::TRIGGER_BY_MEM_TOOLS:
914514f5e3Sopenharmony_ci            return "Trigger by Mem tools";
924514f5e3Sopenharmony_ci        case GCReason::TRIGGER_BY_TASKPOOL:
934514f5e3Sopenharmony_ci            return "Trigger by taskPool";
944514f5e3Sopenharmony_ci        default:
954514f5e3Sopenharmony_ci            return "Other";
964514f5e3Sopenharmony_ci    }
974514f5e3Sopenharmony_ci}
984514f5e3Sopenharmony_ci
994514f5e3Sopenharmony_cifloat GCStats::GetConcurrrentMarkDuration()
1004514f5e3Sopenharmony_ci{
1014514f5e3Sopenharmony_ci    return concurrentMark_ ? scopeDuration_[Scope::ScopeId::ConcurrentMark] : 0;
1024514f5e3Sopenharmony_ci}
1034514f5e3Sopenharmony_ci
1044514f5e3Sopenharmony_civoid GCStats::PrintVerboseGCStatistic()
1054514f5e3Sopenharmony_ci{
1064514f5e3Sopenharmony_ci    PrintGCDurationStatistic();
1074514f5e3Sopenharmony_ci    PrintGCMemoryStatistic();
1084514f5e3Sopenharmony_ci    PrintGCSummaryStatistic();
1094514f5e3Sopenharmony_ci}
1104514f5e3Sopenharmony_ci
1114514f5e3Sopenharmony_civoid GCStats::PrintGCMemoryStatistic()
1124514f5e3Sopenharmony_ci{
1134514f5e3Sopenharmony_ci    NativeAreaAllocator *nativeAreaAllocator = heap_->GetNativeAreaAllocator();
1144514f5e3Sopenharmony_ci    HeapRegionAllocator *heapRegionAllocator = heap_->GetHeapRegionAllocator();
1154514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/****************** GC Memory statistic: *****************/";
1164514f5e3Sopenharmony_ci    LOG_GC(INFO) << "AllSpaces        used:"
1174514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetHeapObjectSize())) << "KB"
1184514f5e3Sopenharmony_ci                    << "     committed:"
1194514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetCommittedSize())) << "KB\n"
1204514f5e3Sopenharmony_ci                    << "EdenSpace        used:"
1214514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetEdenSpace()->GetHeapObjectSize())) << "KB"
1224514f5e3Sopenharmony_ci                    << "     committed:"
1234514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetEdenSpace()->GetCommittedSize())) << "KB\n"
1244514f5e3Sopenharmony_ci                    << "ActiveSemiSpace  used:"
1254514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNewSpace()->GetHeapObjectSize())) << "KB"
1264514f5e3Sopenharmony_ci                    << "     committed:"
1274514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNewSpace()->GetCommittedSize())) << "KB\n"
1284514f5e3Sopenharmony_ci                    << "OldSpace         used:"
1294514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetOldSpace()->GetHeapObjectSize())) << "KB"
1304514f5e3Sopenharmony_ci                    << "     committed:"
1314514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetOldSpace()->GetCommittedSize())) << "KB\n"
1324514f5e3Sopenharmony_ci                    << "HugeObjectSpace  used:"
1334514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetHugeObjectSpace()->GetHeapObjectSize())) << "KB"
1344514f5e3Sopenharmony_ci                    << "     committed:"
1354514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetHugeObjectSpace()->GetCommittedSize())) << "KB\n"
1364514f5e3Sopenharmony_ci                    << "NonMovableSpace  used:"
1374514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNonMovableSpace()->GetHeapObjectSize())) << "KB"
1384514f5e3Sopenharmony_ci                    << "     committed:"
1394514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNonMovableSpace()->GetCommittedSize())) << "KB\n"
1404514f5e3Sopenharmony_ci                    << "MachineCodeSpace used:"
1414514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetMachineCodeSpace()->GetHeapObjectSize())) << "KB"
1424514f5e3Sopenharmony_ci                    << "     committed:"
1434514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetMachineCodeSpace()->GetCommittedSize())) << "KB\n"
1444514f5e3Sopenharmony_ci                    << "HugeMachineCodeSpace used:"
1454514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetHugeMachineCodeSpace()->GetHeapObjectSize())) << "KB"
1464514f5e3Sopenharmony_ci                    << "     committed:"
1474514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetHugeMachineCodeSpace()->GetCommittedSize())) << "KB\n"
1484514f5e3Sopenharmony_ci                    << "SnapshotSpace    used:"
1494514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetSnapshotSpace()->GetHeapObjectSize())) << "KB"
1504514f5e3Sopenharmony_ci                    << "     committed:"
1514514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetSnapshotSpace()->GetCommittedSize())) << "KB\n"
1524514f5e3Sopenharmony_ci                    << "AppSpawnSpace    used:"
1534514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetAppSpawnSpace()->GetHeapObjectSize())) << "KB"
1544514f5e3Sopenharmony_ci                    << "     committed:"
1554514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetAppSpawnSpace()->GetCommittedSize())) << "KB";
1564514f5e3Sopenharmony_ci
1574514f5e3Sopenharmony_ci    LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Anno memory usage size:")
1584514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToMB(heapRegionAllocator->GetAnnoMemoryUsage())) << "MB\n"
1594514f5e3Sopenharmony_ci                    << STATS_DESCRIPTION_FORMAT("Native memory usage size:")
1604514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToMB(nativeAreaAllocator->GetNativeMemoryUsage())) << "MB\n"
1614514f5e3Sopenharmony_ci                    << STATS_DESCRIPTION_FORMAT("NativeBindingSize:")
1624514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeBindingSize())) << "KB\n"
1634514f5e3Sopenharmony_ci                    << STATS_DESCRIPTION_FORMAT("ArrayBufferNativeSize:")
1644514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetArrayBufferNativeSize()))
1654514f5e3Sopenharmony_ci                    << "KB\n"
1664514f5e3Sopenharmony_ci                    << STATS_DESCRIPTION_FORMAT("RegExpByteCodeNativeSize:")
1674514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetRegExpNativeSize())) << "KB\n"
1684514f5e3Sopenharmony_ci                    << STATS_DESCRIPTION_FORMAT("ChunkNativeSize:")
1694514f5e3Sopenharmony_ci                    << STATS_DATA_FORMAT(sizeToKB(heap_->GetNativeAreaAllocator()->GetChunkNativeSize())) << "KB";
1704514f5e3Sopenharmony_ci    switch (gcType_) {
1714514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC: {
1724514f5e3Sopenharmony_ci            size_t commitSize = GetRecordData(RecordData::EDEN_COMMIT_SIZE);
1734514f5e3Sopenharmony_ci            double copiedRate = commitSize == 0 ? 0 : (double(GetRecordData(RecordData::EDEN_ALIVE_SIZE)) / commitSize);
1744514f5e3Sopenharmony_ci            double premotedRate =
1754514f5e3Sopenharmony_ci                commitSize == 0 ? 0 : (double(GetRecordData(RecordData::EDEN_PROMOTE_SIZE)) / commitSize);
1764514f5e3Sopenharmony_ci            double survivalRate = std::min(copiedRate + premotedRate, 1.0);
1774514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Eden copied rate:") << STATS_DATA_FORMAT(copiedRate) << "\n"
1784514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Eden promoted rate:") << STATS_DATA_FORMAT(premotedRate) << "\n"
1794514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Eden survival rate:") << STATS_DATA_FORMAT(survivalRate);
1804514f5e3Sopenharmony_ci            break;
1814514f5e3Sopenharmony_ci        }
1824514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC: {
1834514f5e3Sopenharmony_ci            double copiedRate = double(GetRecordData(RecordData::YOUNG_ALIVE_SIZE)) /
1844514f5e3Sopenharmony_ci                                GetRecordData(RecordData::YOUNG_COMMIT_SIZE);
1854514f5e3Sopenharmony_ci            double premotedRate = double(GetRecordData(RecordData::YOUNG_PROMOTE_SIZE)) /
1864514f5e3Sopenharmony_ci                                  GetRecordData(RecordData::YOUNG_COMMIT_SIZE);
1874514f5e3Sopenharmony_ci            double survivalRate = std::min(copiedRate + premotedRate, 1.0);
1884514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Young copied rate:") << STATS_DATA_FORMAT(copiedRate) << "\n"
1894514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Young promoted rate:") << STATS_DATA_FORMAT(premotedRate) << "\n"
1904514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Young survival rate:") << STATS_DATA_FORMAT(survivalRate);
1914514f5e3Sopenharmony_ci            break;
1924514f5e3Sopenharmony_ci        }
1934514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC: {
1944514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Heap alive rate:")
1954514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(double(GetRecordData(RecordData::OLD_ALIVE_SIZE)) /
1964514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::OLD_COMMIT_SIZE));
1974514f5e3Sopenharmony_ci            break;
1984514f5e3Sopenharmony_ci        }
1994514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC: {
2004514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Heap alive rate:")
2014514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(double(GetRecordData(RecordData::COMPRESS_ALIVE_SIZE)) /
2024514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::COMPRESS_COMMIT_SIZE));
2034514f5e3Sopenharmony_ci            break;
2044514f5e3Sopenharmony_ci        }
2054514f5e3Sopenharmony_ci        default:
2064514f5e3Sopenharmony_ci            break;
2074514f5e3Sopenharmony_ci    }
2084514f5e3Sopenharmony_ci}
2094514f5e3Sopenharmony_ci
2104514f5e3Sopenharmony_civoid GCStats::PrintGCDurationStatistic()
2114514f5e3Sopenharmony_ci{
2124514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/***************** GC Duration statistic: ****************/";
2134514f5e3Sopenharmony_ci    switch (gcType_) {
2144514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC:
2154514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC:
2164514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC:
2174514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("TotalGC:")
2184514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::TotalGC]) << "ms\n"
2194514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Initialize:")
2204514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Initialize]) << "ms\n"
2214514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Mark:")
2224514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Mark]) << "ms\n"
2234514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("MarkRoots:")
2244514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::MarkRoots]) << "ms\n"
2254514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ConcurrentMark pause:")
2264514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ConcurrentMark]) << "ms\n"
2274514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("WaitConcurrentMarkFinish:")
2284514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::WaitConcurrentMarkFinished]) << "ms\n"
2294514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ReMark:")
2304514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ReMark]) << "ms\n"
2314514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ProcessSharedGCRSetWorkList:")
2324514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProcessSharedGCRSetWorkList]) << "ms\n"
2334514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Sweep:")
2344514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Sweep]) << "ms\n"
2354514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ClearNativeObject:")
2364514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ClearNativeObject]) << "ms\n"
2374514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Evacuate:")
2384514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Evacuate]) << "ms\n"
2394514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("UpdateReference:")
2404514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::UpdateReference]) << "ms\n"
2414514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("UpdateWeekRef:")
2424514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::UpdateWeekRef]) << "ms\n"
2434514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("UpdateRoot:")
2444514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::UpdateRoot]) << "ms\n"
2454514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ProceeWorkload:")
2464514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProceeWorkload]) << "ms\n"
2474514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("EvacuateSpace:")
2484514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::EvacuateSpace]) << "ms\n"
2494514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("EvacuateRegion:")
2504514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::EvacuateRegion]) << "ms\n"
2514514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("WaitFinish:")
2524514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::WaitFinish]) << "ms\n"
2534514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Finish:")
2544514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Finish]) << "ms";
2554514f5e3Sopenharmony_ci            break;
2564514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC:
2574514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("TotalGC:")
2584514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::TotalGC]) << "ms\n"
2594514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("ProcessSharedGCRSetWorkList:")
2604514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ProcessSharedGCRSetWorkList]) << "ms\n"
2614514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Initialize:")
2624514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Initialize]) << "ms\n"
2634514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Mark:")
2644514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Mark]) << "ms\n"
2654514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("MarkRoots:")
2664514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::MarkRoots]) << "ms\n"
2674514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Sweep:")
2684514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Sweep]) << "ms\n"
2694514f5e3Sopenharmony_ci                         << STATS_DESCRIPTION_FORMAT("Finish:")
2704514f5e3Sopenharmony_ci                         << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Finish]) << "ms";
2714514f5e3Sopenharmony_ci            break;
2724514f5e3Sopenharmony_ci        default:
2734514f5e3Sopenharmony_ci            break;
2744514f5e3Sopenharmony_ci    }
2754514f5e3Sopenharmony_ci}
2764514f5e3Sopenharmony_ci
2774514f5e3Sopenharmony_cibool GCStats::CheckIfNeedPrint(GCType type)
2784514f5e3Sopenharmony_ci{
2794514f5e3Sopenharmony_ci    uint32_t gcCount = 0;
2804514f5e3Sopenharmony_ci    switch (type) {
2814514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC:
2824514f5e3Sopenharmony_ci            gcCount = GetRecordData(RecordData::EDEN_COUNT);
2834514f5e3Sopenharmony_ci            break;
2844514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC:
2854514f5e3Sopenharmony_ci            gcCount = GetRecordData(RecordData::YOUNG_COUNT);
2864514f5e3Sopenharmony_ci            break;
2874514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC:
2884514f5e3Sopenharmony_ci            gcCount = GetRecordData(RecordData::OLD_COUNT);
2894514f5e3Sopenharmony_ci            break;
2904514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC:
2914514f5e3Sopenharmony_ci            gcCount = GetRecordData(RecordData::COMPRESS_COUNT);
2924514f5e3Sopenharmony_ci            break;
2934514f5e3Sopenharmony_ci        default:
2944514f5e3Sopenharmony_ci            break;
2954514f5e3Sopenharmony_ci    }
2964514f5e3Sopenharmony_ci
2974514f5e3Sopenharmony_ci    if (gcCount > 0) {
2984514f5e3Sopenharmony_ci        return true;
2994514f5e3Sopenharmony_ci    }
3004514f5e3Sopenharmony_ci    return false;
3014514f5e3Sopenharmony_ci}
3024514f5e3Sopenharmony_ci
3034514f5e3Sopenharmony_civoid GCStats::PrintGCSummaryStatistic(GCType type)
3044514f5e3Sopenharmony_ci{
3054514f5e3Sopenharmony_ci    if (type != GCType::START && !CheckIfNeedPrint(type)) {
3064514f5e3Sopenharmony_ci        return;
3074514f5e3Sopenharmony_ci    } else {
3084514f5e3Sopenharmony_ci        type = type == GCType::START ? gcType_ : type;
3094514f5e3Sopenharmony_ci    }
3104514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/***************** GC summary statistic: *****************/";
3114514f5e3Sopenharmony_ci    switch (type) {
3124514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC: {
3134514f5e3Sopenharmony_ci            size_t commitSize = GetRecordData(RecordData::EDEN_TOTAL_COMMIT);
3144514f5e3Sopenharmony_ci            double copiedRate =
3154514f5e3Sopenharmony_ci                commitSize == 0 ? 0 : (double(GetRecordData(RecordData::EDEN_TOTAL_ALIVE)) / commitSize);
3164514f5e3Sopenharmony_ci            double promotedRate =
3174514f5e3Sopenharmony_ci                commitSize == 0 ? 0 : (double(GetRecordData(RecordData::EDEN_TOTAL_PROMOTE)) / commitSize);
3184514f5e3Sopenharmony_ci            double survivalRate =  std::min(copiedRate + promotedRate, 1.0);
3194514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("EdenGC occurs count")
3204514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordData(RecordData::EDEN_COUNT)) << "\n"
3214514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("EdenGC max pause:")
3224514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::EDEN_MAX_PAUSE)) << "ms\n"
3234514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("EdenGC min pause:")
3244514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::EDEN_MIN_PAUSE)) << "ms\n"
3254514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("EdenGC average pause:")
3264514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::EDEN_TOTAL_PAUSE) /
3274514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::EDEN_COUNT)) << "ms\n"
3284514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Eden average copied rate:") << STATS_DATA_FORMAT(copiedRate) << "\n"
3294514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Eden average promoted rate:") << STATS_DATA_FORMAT(promotedRate) << "\n"
3304514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Eden average survival rate:") << STATS_DATA_FORMAT(survivalRate);
3314514f5e3Sopenharmony_ci            break;
3324514f5e3Sopenharmony_ci        }
3334514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC: {
3344514f5e3Sopenharmony_ci            double copiedRate = double(GetRecordData(RecordData::YOUNG_TOTAL_ALIVE)) /
3354514f5e3Sopenharmony_ci                                GetRecordData(RecordData::YOUNG_TOTAL_COMMIT);
3364514f5e3Sopenharmony_ci            double promotedRate = double(GetRecordData(RecordData::YOUNG_TOTAL_PROMOTE)) /
3374514f5e3Sopenharmony_ci                                  GetRecordData(RecordData::YOUNG_TOTAL_COMMIT);
3384514f5e3Sopenharmony_ci            double survivalRate =  std::min(copiedRate + promotedRate, 1.0);
3394514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("YoungGC occurs count")
3404514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordData(RecordData::YOUNG_COUNT)) << "\n"
3414514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("YoungGC max pause:")
3424514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::YOUNG_MAX_PAUSE)) << "ms\n"
3434514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("YoungGC min pause:")
3444514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::YOUNG_MIN_PAUSE)) << "ms\n"
3454514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("YoungGC average pause:")
3464514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::YOUNG_TOTAL_PAUSE) /
3474514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::YOUNG_COUNT)) << "ms\n"
3484514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Young average copied rate:") << STATS_DATA_FORMAT(copiedRate) << "\n"
3494514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Young average promoted rate:") << STATS_DATA_FORMAT(promotedRate) << "\n"
3504514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Young average survival rate:") << STATS_DATA_FORMAT(survivalRate);
3514514f5e3Sopenharmony_ci            break;
3524514f5e3Sopenharmony_ci        }
3534514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC: {
3544514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("OldGC occurs count")
3554514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordData(RecordData::OLD_COUNT)) << "\n"
3564514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("OldGC max pause:")
3574514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::OLD_MAX_PAUSE)) << "ms\n"
3584514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("OldGC min pause:")
3594514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::OLD_MIN_PAUSE)) << "ms\n"
3604514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("OldGC average pause:")
3614514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::OLD_TOTAL_PAUSE) /
3624514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::OLD_COUNT)) << "ms\n"
3634514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Heap average alive rate:")
3644514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(double(GetRecordData(RecordData::OLD_TOTAL_ALIVE)) /
3654514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::OLD_TOTAL_COMMIT));
3664514f5e3Sopenharmony_ci            break;
3674514f5e3Sopenharmony_ci        }
3684514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC: {
3694514f5e3Sopenharmony_ci            LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("CompressGC occurs count")
3704514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordData(RecordData::COMPRESS_COUNT)) << "\n"
3714514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("CompressGC max pause:")
3724514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::COMPRESS_MAX_PAUSE)) << "ms\n"
3734514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("CompressGC min pause:")
3744514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::COMPRESS_MIN_PAUSE)) << "ms\n"
3754514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("CompressGC average pause:")
3764514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::COMPRESS_TOTAL_PAUSE) /
3774514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::COMPRESS_COUNT)) << "ms\n"
3784514f5e3Sopenharmony_ci                << STATS_DESCRIPTION_FORMAT("Heap average alive rate:")
3794514f5e3Sopenharmony_ci                << STATS_DATA_FORMAT(double(GetRecordData(RecordData::COMPRESS_TOTAL_ALIVE)) /
3804514f5e3Sopenharmony_ci                                     GetRecordData(RecordData::COMPRESS_TOTAL_COMMIT));
3814514f5e3Sopenharmony_ci            break;
3824514f5e3Sopenharmony_ci        }
3834514f5e3Sopenharmony_ci        default:
3844514f5e3Sopenharmony_ci            break;
3854514f5e3Sopenharmony_ci    }
3864514f5e3Sopenharmony_ci}
3874514f5e3Sopenharmony_ci
3884514f5e3Sopenharmony_cisize_t GCStats::GetAccumulatedAllocateSize()
3894514f5e3Sopenharmony_ci{
3904514f5e3Sopenharmony_ci    return accumulatedFreeSize_ + heap_->GetHeapObjectSize();
3914514f5e3Sopenharmony_ci}
3924514f5e3Sopenharmony_ci
3934514f5e3Sopenharmony_civoid GCStats::RecordStatisticBeforeGC(TriggerGCType gcType, GCReason reason)
3944514f5e3Sopenharmony_ci{
3954514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_OBJ_SIZE, heap_->GetHeapObjectSize());
3964514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_COMMIT_SIZE, heap_->GetCommittedSize());
3974514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_EDEN_OBJ_SIZE, heap_->GetEdenSpace()->GetHeapObjectSize());
3984514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_YOUNG_OBJ_SIZE, heap_->GetNewSpace()->GetHeapObjectSize());
3994514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_NATIVE_POINTER_NUM, heap_->GetNativePointerListSize());
4004514f5e3Sopenharmony_ci    gcType_ = GetGCType(gcType);
4014514f5e3Sopenharmony_ci    reason_ = reason;
4024514f5e3Sopenharmony_ci
4034514f5e3Sopenharmony_ci    switch (gcType_) {
4044514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC: {
4054514f5e3Sopenharmony_ci            size_t edenCommitSize = heap_->GetEdenSpace()->GetCommittedSize();
4064514f5e3Sopenharmony_ci            SetRecordData(RecordData::EDEN_COMMIT_SIZE, edenCommitSize);
4074514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::EDEN_TOTAL_COMMIT, edenCommitSize);
4084514f5e3Sopenharmony_ci            break;
4094514f5e3Sopenharmony_ci        }
4104514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC: {
4114514f5e3Sopenharmony_ci            size_t youngCommitSize =
4124514f5e3Sopenharmony_ci                heap_->GetNewSpace()->GetCommittedSize() + heap_->GetEdenSpace()->GetCommittedSize();
4134514f5e3Sopenharmony_ci            SetRecordData(RecordData::YOUNG_COMMIT_SIZE, youngCommitSize);
4144514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::YOUNG_TOTAL_COMMIT, youngCommitSize);
4154514f5e3Sopenharmony_ci            break;
4164514f5e3Sopenharmony_ci        }
4174514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC: {
4184514f5e3Sopenharmony_ci            size_t oldCommitSize = heap_->GetCommittedSize();
4194514f5e3Sopenharmony_ci            SetRecordData(RecordData::OLD_COMMIT_SIZE, oldCommitSize);
4204514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::OLD_TOTAL_COMMIT, oldCommitSize);
4214514f5e3Sopenharmony_ci            break;
4224514f5e3Sopenharmony_ci        }
4234514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC: {
4244514f5e3Sopenharmony_ci            size_t compressCommitSize = heap_->GetCommittedSize();
4254514f5e3Sopenharmony_ci            SetRecordData(RecordData::COMPRESS_COMMIT_SIZE, compressCommitSize);
4264514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::COMPRESS_TOTAL_COMMIT, compressCommitSize);
4274514f5e3Sopenharmony_ci            break;
4284514f5e3Sopenharmony_ci        }
4294514f5e3Sopenharmony_ci        default:
4304514f5e3Sopenharmony_ci            break;
4314514f5e3Sopenharmony_ci    }
4324514f5e3Sopenharmony_ci}
4334514f5e3Sopenharmony_ci
4344514f5e3Sopenharmony_civoid GCStats::RecordStatisticAfterGC()
4354514f5e3Sopenharmony_ci{
4364514f5e3Sopenharmony_ci    SetRecordData(RecordData::END_OBJ_SIZE, heap_->GetHeapObjectSize());
4374514f5e3Sopenharmony_ci    SetRecordData(RecordData::END_COMMIT_SIZE, heap_->GetCommittedSize());
4384514f5e3Sopenharmony_ci
4394514f5e3Sopenharmony_ci    float duration = scopeDuration_[Scope::ScopeId::TotalGC];
4404514f5e3Sopenharmony_ci    switch (gcType_) {
4414514f5e3Sopenharmony_ci        case GCType::PARTIAL_EDEN_GC: {
4424514f5e3Sopenharmony_ci            if (GetRecordData(RecordData::EDEN_COUNT) == 0) {
4434514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::EDEN_MIN_PAUSE, duration);
4444514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::EDEN_MAX_PAUSE, duration);
4454514f5e3Sopenharmony_ci            } else {
4464514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::EDEN_MIN_PAUSE,
4474514f5e3Sopenharmony_ci                    std::min(GetRecordDuration(RecordDuration::EDEN_MIN_PAUSE), duration));
4484514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::EDEN_MAX_PAUSE,
4494514f5e3Sopenharmony_ci                    std::max(GetRecordDuration(RecordDuration::EDEN_MAX_PAUSE), duration));
4504514f5e3Sopenharmony_ci            }
4514514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::EDEN_COUNT);
4524514f5e3Sopenharmony_ci            IncreaseRecordDuration(RecordDuration::EDEN_TOTAL_PAUSE, duration);
4534514f5e3Sopenharmony_ci            size_t edenToYoungSize = heap_->GetEdenToYoungSize();
4544514f5e3Sopenharmony_ci            SetRecordData(RecordData::EDEN_ALIVE_SIZE, edenToYoungSize);
4554514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::EDEN_TOTAL_ALIVE, edenToYoungSize);
4564514f5e3Sopenharmony_ci            size_t promotedSize = heap_->GetPromotedSize();
4574514f5e3Sopenharmony_ci            SetRecordData(RecordData::EDEN_PROMOTE_SIZE, promotedSize);
4584514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::EDEN_TOTAL_PROMOTE, promotedSize);
4594514f5e3Sopenharmony_ci            break;
4604514f5e3Sopenharmony_ci        }
4614514f5e3Sopenharmony_ci        case GCType::PARTIAL_YOUNG_GC: {
4624514f5e3Sopenharmony_ci            if (GetRecordData(RecordData::YOUNG_COUNT) == 0) {
4634514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::YOUNG_MIN_PAUSE, duration);
4644514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::YOUNG_MAX_PAUSE, duration);
4654514f5e3Sopenharmony_ci            } else {
4664514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::YOUNG_MIN_PAUSE,
4674514f5e3Sopenharmony_ci                    std::min(GetRecordDuration(RecordDuration::YOUNG_MIN_PAUSE), duration));
4684514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::YOUNG_MAX_PAUSE,
4694514f5e3Sopenharmony_ci                    std::max(GetRecordDuration(RecordDuration::YOUNG_MAX_PAUSE), duration));
4704514f5e3Sopenharmony_ci            }
4714514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::YOUNG_COUNT);
4724514f5e3Sopenharmony_ci            IncreaseRecordDuration(RecordDuration::YOUNG_TOTAL_PAUSE, duration);
4734514f5e3Sopenharmony_ci            size_t youngAliveSize = heap_->GetNewSpace()->GetHeapObjectSize();
4744514f5e3Sopenharmony_ci            SetRecordData(RecordData::YOUNG_ALIVE_SIZE, youngAliveSize);
4754514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::YOUNG_TOTAL_ALIVE, youngAliveSize);
4764514f5e3Sopenharmony_ci            size_t promotedSize = heap_->GetPromotedSize();
4774514f5e3Sopenharmony_ci            SetRecordData(RecordData::YOUNG_PROMOTE_SIZE, promotedSize);
4784514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::YOUNG_TOTAL_PROMOTE, promotedSize);
4794514f5e3Sopenharmony_ci            break;
4804514f5e3Sopenharmony_ci        }
4814514f5e3Sopenharmony_ci        case GCType::PARTIAL_OLD_GC: {
4824514f5e3Sopenharmony_ci            if (GetRecordData(RecordData::OLD_COUNT) == 0) {
4834514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::OLD_MIN_PAUSE, duration);
4844514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::OLD_MAX_PAUSE, duration);
4854514f5e3Sopenharmony_ci            } else {
4864514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::OLD_MIN_PAUSE,
4874514f5e3Sopenharmony_ci                    std::min(GetRecordDuration(RecordDuration::OLD_MIN_PAUSE), duration));
4884514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::OLD_MAX_PAUSE,
4894514f5e3Sopenharmony_ci                    std::max(GetRecordDuration(RecordDuration::OLD_MAX_PAUSE), duration));
4904514f5e3Sopenharmony_ci            }
4914514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::OLD_COUNT);
4924514f5e3Sopenharmony_ci            IncreaseRecordDuration(RecordDuration::OLD_TOTAL_PAUSE, duration);
4934514f5e3Sopenharmony_ci            size_t oldAliveSize = heap_->GetHeapObjectSize();
4944514f5e3Sopenharmony_ci            SetRecordData(RecordData::OLD_ALIVE_SIZE, oldAliveSize);
4954514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::OLD_TOTAL_ALIVE, oldAliveSize);
4964514f5e3Sopenharmony_ci            break;
4974514f5e3Sopenharmony_ci        }
4984514f5e3Sopenharmony_ci        case GCType::COMPRESS_GC: {
4994514f5e3Sopenharmony_ci            if (GetRecordData(RecordData::COMPRESS_COUNT) == 0) {
5004514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::COMPRESS_MIN_PAUSE, duration);
5014514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::COMPRESS_MAX_PAUSE, duration);
5024514f5e3Sopenharmony_ci            } else {
5034514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::COMPRESS_MIN_PAUSE,
5044514f5e3Sopenharmony_ci                    std::min(GetRecordDuration(RecordDuration::COMPRESS_MIN_PAUSE), duration));
5054514f5e3Sopenharmony_ci                SetRecordDuration(RecordDuration::COMPRESS_MAX_PAUSE,
5064514f5e3Sopenharmony_ci                    std::max(GetRecordDuration(RecordDuration::COMPRESS_MAX_PAUSE), duration));
5074514f5e3Sopenharmony_ci            }
5084514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::COMPRESS_COUNT);
5094514f5e3Sopenharmony_ci            IncreaseRecordDuration(RecordDuration::COMPRESS_TOTAL_PAUSE, duration);
5104514f5e3Sopenharmony_ci            size_t compressAliveSize = heap_->GetHeapObjectSize();
5114514f5e3Sopenharmony_ci            SetRecordData(RecordData::COMPRESS_ALIVE_SIZE, compressAliveSize);
5124514f5e3Sopenharmony_ci            IncreaseRecordData(RecordData::COMPRESS_TOTAL_ALIVE, compressAliveSize);
5134514f5e3Sopenharmony_ci            break;
5144514f5e3Sopenharmony_ci        }
5154514f5e3Sopenharmony_ci        default:
5164514f5e3Sopenharmony_ci            break;
5174514f5e3Sopenharmony_ci    }
5184514f5e3Sopenharmony_ci    RecordGCSpeed();
5194514f5e3Sopenharmony_ci
5204514f5e3Sopenharmony_ci    if (gcType_ == GCType::COMPRESS_GC && scopeDuration_[Scope::ScopeId::TotalGC] > longPauseTime_) {
5214514f5e3Sopenharmony_ci        IncreaseFullGCLongTimeCount();
5224514f5e3Sopenharmony_ci    }
5234514f5e3Sopenharmony_ci    IncreaseTotalDuration(scopeDuration_[Scope::ScopeId::TotalGC]);
5244514f5e3Sopenharmony_ci    IncreaseAccumulatedFreeSize(GetRecordData(RecordData::START_OBJ_SIZE) -
5254514f5e3Sopenharmony_ci                                GetRecordData(RecordData::END_OBJ_SIZE));
5264514f5e3Sopenharmony_ci}
5274514f5e3Sopenharmony_ci
5284514f5e3Sopenharmony_civoid GCStats::RecordGCSpeed()
5294514f5e3Sopenharmony_ci{
5304514f5e3Sopenharmony_ci    double survivalRate = GetAvgSurvivalRate();
5314514f5e3Sopenharmony_ci    size_t clearNativeSpeed = GetRecordData(RecordData::START_NATIVE_POINTER_NUM) /
5324514f5e3Sopenharmony_ci                              scopeDuration_[Scope::ScopeId::ClearNativeObject];
5334514f5e3Sopenharmony_ci
5344514f5e3Sopenharmony_ci    if (gcType_ == GCType::PARTIAL_EDEN_GC) {
5354514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::MARK_SPEED] =
5364514f5e3Sopenharmony_ci            GetRecordData(RecordData::START_EDEN_OBJ_SIZE) / scopeDuration_[Scope::ScopeId::Mark];
5374514f5e3Sopenharmony_ci        size_t evacuateSpeed = survivalRate * GetRecordData(RecordData::START_EDEN_OBJ_SIZE) /
5384514f5e3Sopenharmony_ci                               scopeDuration_[Scope::ScopeId::EvacuateSpace];
5394514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::EDEN_EVACUATE_SPACE_SPEED] =
5404514f5e3Sopenharmony_ci            (evacuateSpeed + gcSpeed_[(uint8_t)SpeedData::EDEN_EVACUATE_SPACE_SPEED]) / 2;  // 2 means half
5414514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::EDEN_CLEAR_NATIVE_OBJ_SPEED] =
5424514f5e3Sopenharmony_ci            (clearNativeSpeed + gcSpeed_[(uint8_t)SpeedData::EDEN_CLEAR_NATIVE_OBJ_SPEED]) / 2;  // 2 means half
5434514f5e3Sopenharmony_ci        size_t updateReferenceSpeed = GetRecordData(RecordData::START_OBJ_SIZE) /
5444514f5e3Sopenharmony_ci                                      scopeDuration_[Scope::ScopeId::UpdateReference];
5454514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::EDEN_UPDATE_REFERENCE_SPEED] =
5464514f5e3Sopenharmony_ci            (updateReferenceSpeed + gcSpeed_[(uint8_t)SpeedData::EDEN_UPDATE_REFERENCE_SPEED]) / 2;  // 2 means half
5474514f5e3Sopenharmony_ci    } else if (gcType_ == GCType::PARTIAL_YOUNG_GC) {
5484514f5e3Sopenharmony_ci        size_t objSize =
5494514f5e3Sopenharmony_ci            GetRecordData(RecordData::START_YOUNG_OBJ_SIZE) + GetRecordData(RecordData::START_EDEN_OBJ_SIZE);
5504514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::MARK_SPEED] = objSize / scopeDuration_[Scope::ScopeId::Mark];
5514514f5e3Sopenharmony_ci        size_t evacuateSpeed = survivalRate * objSize / scopeDuration_[Scope::ScopeId::EvacuateSpace];
5524514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::YOUNG_EVACUATE_SPACE_SPEED] =
5534514f5e3Sopenharmony_ci            (evacuateSpeed + gcSpeed_[(uint8_t)SpeedData::YOUNG_EVACUATE_SPACE_SPEED]) / 2;  // 2 means half
5544514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::YOUNG_CLEAR_NATIVE_OBJ_SPEED] =
5554514f5e3Sopenharmony_ci            (clearNativeSpeed + gcSpeed_[(uint8_t)SpeedData::YOUNG_CLEAR_NATIVE_OBJ_SPEED]) / 2;  // 2 means half
5564514f5e3Sopenharmony_ci        size_t updateReferenceSpeed = GetRecordData(RecordData::START_OBJ_SIZE) /
5574514f5e3Sopenharmony_ci                                      scopeDuration_[Scope::ScopeId::UpdateReference];
5584514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::YOUNG_UPDATE_REFERENCE_SPEED] =
5594514f5e3Sopenharmony_ci            (updateReferenceSpeed + gcSpeed_[(uint8_t)SpeedData::YOUNG_UPDATE_REFERENCE_SPEED]) / 2;  // 2 means half
5604514f5e3Sopenharmony_ci    } else if (gcType_ == GCType::PARTIAL_OLD_GC) {
5614514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::MARK_SPEED] =
5624514f5e3Sopenharmony_ci            GetRecordData(RecordData::START_OBJ_SIZE) / scopeDuration_[Scope::ScopeId::Mark];
5634514f5e3Sopenharmony_ci        size_t sweepSpeed = GetRecordData(RecordData::START_OBJ_SIZE) / scopeDuration_[Scope::ScopeId::Sweep];
5644514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::SWEEP_SPEED] =
5654514f5e3Sopenharmony_ci            (sweepSpeed + gcSpeed_[(uint8_t)SpeedData::SWEEP_SPEED]) / 2;  // 2 means half
5664514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::OLD_CLEAR_NATIVE_OBJ_SPEED] =
5674514f5e3Sopenharmony_ci            (clearNativeSpeed + gcSpeed_[(uint8_t)SpeedData::OLD_CLEAR_NATIVE_OBJ_SPEED]) / 2;  // 2 means half
5684514f5e3Sopenharmony_ci
5694514f5e3Sopenharmony_ci        size_t evacuateSpaceSpeed = (survivalRate * (GetRecordData(RecordData::START_YOUNG_OBJ_SIZE) +
5704514f5e3Sopenharmony_ci            GetRecordData(RecordData::START_EDEN_OBJ_SIZE)) + GetRecordData(RecordData::COLLECT_REGION_SET_SIZE)) /
5714514f5e3Sopenharmony_ci            scopeDuration_[Scope::ScopeId::EvacuateSpace];
5724514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::OLD_EVACUATE_SPACE_SPEED] =
5734514f5e3Sopenharmony_ci            (evacuateSpaceSpeed + gcSpeed_[(uint8_t)SpeedData::OLD_EVACUATE_SPACE_SPEED]) / 2;  // 2 means half
5744514f5e3Sopenharmony_ci
5754514f5e3Sopenharmony_ci        size_t updateReferenceSpeed = GetRecordData(RecordData::START_OBJ_SIZE) /
5764514f5e3Sopenharmony_ci                                    scopeDuration_[Scope::ScopeId::UpdateReference];
5774514f5e3Sopenharmony_ci        gcSpeed_[(uint8_t)SpeedData::UPDATE_REFERENCE_SPEED] =
5784514f5e3Sopenharmony_ci            (updateReferenceSpeed + gcSpeed_[(uint8_t)SpeedData::UPDATE_REFERENCE_SPEED]) / 2;  // 2 means half
5794514f5e3Sopenharmony_ci    }
5804514f5e3Sopenharmony_ci}
5814514f5e3Sopenharmony_ci
5824514f5e3Sopenharmony_ciGCType GCStats::GetGCType(TriggerGCType gcType)
5834514f5e3Sopenharmony_ci{
5844514f5e3Sopenharmony_ci    if (heap_ && !heap_->IsReadyToConcurrentMark()) {
5854514f5e3Sopenharmony_ci        switch (heap_->GetMarkType()) {
5864514f5e3Sopenharmony_ci            case MarkType::MARK_EDEN:
5874514f5e3Sopenharmony_ci                return GCType::PARTIAL_EDEN_GC;
5884514f5e3Sopenharmony_ci            case MarkType::MARK_YOUNG:
5894514f5e3Sopenharmony_ci                return GCType::PARTIAL_YOUNG_GC;
5904514f5e3Sopenharmony_ci            case MarkType::MARK_FULL:
5914514f5e3Sopenharmony_ci                return GCType::PARTIAL_OLD_GC;
5924514f5e3Sopenharmony_ci            default:
5934514f5e3Sopenharmony_ci                return GCType::OTHER;
5944514f5e3Sopenharmony_ci        }
5954514f5e3Sopenharmony_ci    }
5964514f5e3Sopenharmony_ci    switch (gcType) {
5974514f5e3Sopenharmony_ci        case TriggerGCType::EDEN_GC:
5984514f5e3Sopenharmony_ci            return GCType::PARTIAL_EDEN_GC;
5994514f5e3Sopenharmony_ci        case TriggerGCType::YOUNG_GC:
6004514f5e3Sopenharmony_ci            return GCType::PARTIAL_YOUNG_GC;
6014514f5e3Sopenharmony_ci        case TriggerGCType::OLD_GC:
6024514f5e3Sopenharmony_ci            return GCType::PARTIAL_OLD_GC;
6034514f5e3Sopenharmony_ci        case TriggerGCType::FULL_GC:
6044514f5e3Sopenharmony_ci            return GCType::COMPRESS_GC;
6054514f5e3Sopenharmony_ci        case TriggerGCType::SHARED_GC:
6064514f5e3Sopenharmony_ci            return GCType::SHARED_GC;
6074514f5e3Sopenharmony_ci        case TriggerGCType::SHARED_FULL_GC:
6084514f5e3Sopenharmony_ci            return GCType::SHARED_FULL_GC;
6094514f5e3Sopenharmony_ci        default:
6104514f5e3Sopenharmony_ci            return GCType::OTHER;
6114514f5e3Sopenharmony_ci    }
6124514f5e3Sopenharmony_ci}
6134514f5e3Sopenharmony_ci
6144514f5e3Sopenharmony_civoid GCStats::InitializeRecordList()
6154514f5e3Sopenharmony_ci{
6164514f5e3Sopenharmony_ci    for (float &duration : scopeDuration_) {
6174514f5e3Sopenharmony_ci        duration = 0.0f;
6184514f5e3Sopenharmony_ci    }
6194514f5e3Sopenharmony_ci    concurrentMark_ = false;
6204514f5e3Sopenharmony_ci}
6214514f5e3Sopenharmony_ci
6224514f5e3Sopenharmony_cibool GCStats::CheckIfLongTimePause()
6234514f5e3Sopenharmony_ci{
6244514f5e3Sopenharmony_ci    if (scopeDuration_[Scope::ScopeId::TotalGC] > longPauseTime_) {
6254514f5e3Sopenharmony_ci        LOG_GC(INFO) << "Has checked a long time gc";
6264514f5e3Sopenharmony_ci        return true;
6274514f5e3Sopenharmony_ci    }
6284514f5e3Sopenharmony_ci    return false;
6294514f5e3Sopenharmony_ci}
6304514f5e3Sopenharmony_ci
6314514f5e3Sopenharmony_civoid SharedGCStats::PrintStatisticResult()
6324514f5e3Sopenharmony_ci{
6334514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/******************* SharedGCStats statistic: *******************/";
6344514f5e3Sopenharmony_ci    PrintSharedGCSummaryStatistic();
6354514f5e3Sopenharmony_ci    PrintGCMemoryStatistic();
6364514f5e3Sopenharmony_ci}
6374514f5e3Sopenharmony_ci
6384514f5e3Sopenharmony_civoid SharedGCStats::PrintGCStatistic()
6394514f5e3Sopenharmony_ci{
6404514f5e3Sopenharmony_ci    if (enableGCTracer_) {
6414514f5e3Sopenharmony_ci        LOG_GC(INFO) << " [ " << GetGCTypeName() << " ] "
6424514f5e3Sopenharmony_ci                     << sizeToMB(recordData_[(uint8_t)RecordData::START_OBJ_SIZE]) << " ("
6434514f5e3Sopenharmony_ci                     << sizeToMB(recordData_[(uint8_t)RecordData::START_COMMIT_SIZE]) << ") -> "
6444514f5e3Sopenharmony_ci                     << sizeToMB(recordData_[(uint8_t)RecordData::END_OBJ_SIZE]) << " ("
6454514f5e3Sopenharmony_ci                     << sizeToMB(recordData_[(uint8_t)RecordData::END_COMMIT_SIZE]) << ") MB, "
6464514f5e3Sopenharmony_ci                     << scopeDuration_[Scope::ScopeId::TotalGC] << "ms, " << GCReasonToString(reason_);
6474514f5e3Sopenharmony_ci        PrintSharedGCDuration();
6484514f5e3Sopenharmony_ci        PrintGCMemoryStatistic();
6494514f5e3Sopenharmony_ci        PrintSharedGCSummaryStatistic();
6504514f5e3Sopenharmony_ci    }
6514514f5e3Sopenharmony_ci    InitializeRecordList();
6524514f5e3Sopenharmony_ci}
6534514f5e3Sopenharmony_ci
6544514f5e3Sopenharmony_civoid SharedGCStats::PrintSharedGCSummaryStatistic()
6554514f5e3Sopenharmony_ci{
6564514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/***************** GC summary statistic: *****************/";
6574514f5e3Sopenharmony_ci    LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("SharedGC occurs count")
6584514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(GetRecordData(RecordData::SHARED_COUNT)) << "\n"
6594514f5e3Sopenharmony_ci                 << STATS_DESCRIPTION_FORMAT("SharedGC max pause:")
6604514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::SHARED_MAX_PAUSE)) << "ms\n"
6614514f5e3Sopenharmony_ci                 << STATS_DESCRIPTION_FORMAT("SharedGC min pause:")
6624514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::SHARED_MIN_PAUSE)) << "ms\n"
6634514f5e3Sopenharmony_ci                 << STATS_DESCRIPTION_FORMAT("SharedGC average pause:")
6644514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(GetRecordDuration(RecordDuration::SHARED_TOTAL_PAUSE) /
6654514f5e3Sopenharmony_ci                                      GetRecordData(RecordData::SHARED_COUNT)) << "ms\n"
6664514f5e3Sopenharmony_ci                 << STATS_DESCRIPTION_FORMAT("SharedHeap average alive rate:")
6674514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(double(GetRecordData(RecordData::SHARED_TOTAL_ALIVE)) /
6684514f5e3Sopenharmony_ci                                      GetRecordData(RecordData::SHARED_TOTAL_COMMIT));
6694514f5e3Sopenharmony_ci}
6704514f5e3Sopenharmony_ci
6714514f5e3Sopenharmony_civoid SharedGCStats::PrintGCMemoryStatistic()
6724514f5e3Sopenharmony_ci{
6734514f5e3Sopenharmony_ci    NativeAreaAllocator *nativeAreaAllocator = sHeap_->GetNativeAreaAllocator();
6744514f5e3Sopenharmony_ci    HeapRegionAllocator *heapRegionAllocator = sHeap_->GetHeapRegionAllocator();
6754514f5e3Sopenharmony_ci    LOG_GC(INFO) << "/****************** GC Memory statistic: *****************/";
6764514f5e3Sopenharmony_ci    LOG_GC(INFO) << "AllSpaces         used:"
6774514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetHeapObjectSize())) << "KB"
6784514f5e3Sopenharmony_ci                 << "     committed:"
6794514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetCommittedSize())) << "KB\n"
6804514f5e3Sopenharmony_ci                 << "SharedOldSpace         used:"
6814514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetOldSpace()->GetHeapObjectSize())) << "KB"
6824514f5e3Sopenharmony_ci                 << "     committed:"
6834514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetOldSpace()->GetCommittedSize())) << "KB\n"
6844514f5e3Sopenharmony_ci                 << "SharedNonMovableSpace  used:"
6854514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetNonMovableSpace()->GetHeapObjectSize())) << "KB"
6864514f5e3Sopenharmony_ci                 << "     committed:"
6874514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetNonMovableSpace()->GetCommittedSize())) << "KB\n"
6884514f5e3Sopenharmony_ci                 << "SharedHugeObjectSpace  used:"
6894514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetHugeObjectSpace()->GetHeapObjectSize())) << "KB"
6904514f5e3Sopenharmony_ci                 << "     committed:"
6914514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetHugeObjectSpace()->GetCommittedSize())) << "KB\n"
6924514f5e3Sopenharmony_ci                 << "SharedAppSpawnSpace    used:"
6934514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetAppSpawnSpace()->GetHeapObjectSize())) << "KB"
6944514f5e3Sopenharmony_ci                 << "     committed:"
6954514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToKB(sHeap_->GetAppSpawnSpace()->GetCommittedSize())) << "KB";
6964514f5e3Sopenharmony_ci
6974514f5e3Sopenharmony_ci    LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Anno memory usage size:")
6984514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToMB(heapRegionAllocator->GetAnnoMemoryUsage())) << "MB\n"
6994514f5e3Sopenharmony_ci                 << STATS_DESCRIPTION_FORMAT("Native memory usage size:")
7004514f5e3Sopenharmony_ci                 << STATS_DATA_FORMAT(sizeToMB(nativeAreaAllocator->GetNativeMemoryUsage())) << "MB\n";
7014514f5e3Sopenharmony_ci
7024514f5e3Sopenharmony_ci    LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("Heap alive rate:")
7034514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(double(GetRecordData(RecordData::SHARED_ALIVE_SIZE)) /
7044514f5e3Sopenharmony_ci                                    GetRecordData(RecordData::SHARED_COMMIT_SIZE));
7054514f5e3Sopenharmony_ci}
7064514f5e3Sopenharmony_ci
7074514f5e3Sopenharmony_civoid SharedGCStats::PrintSharedGCDuration()
7084514f5e3Sopenharmony_ci{
7094514f5e3Sopenharmony_ci    LOG_GC(INFO) << STATS_DESCRIPTION_FORMAT("TotalGC:")
7104514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::TotalGC]) << "ms\n"
7114514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("Initialize:")
7124514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Initialize]) << "ms\n"
7134514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("Mark:")
7144514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Mark]) << "ms\n"
7154514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("Sweep:")
7164514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Sweep]) << "ms\n"
7174514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("Finish:")
7184514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::Finish]) << "ms\n"
7194514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("SuspendAll:")
7204514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::SuspendAll]) << "ms\n"
7214514f5e3Sopenharmony_ci        << STATS_DESCRIPTION_FORMAT("ResumeAll:")
7224514f5e3Sopenharmony_ci        << STATS_DATA_FORMAT(scopeDuration_[Scope::ScopeId::ResumeAll]) << "ms";
7234514f5e3Sopenharmony_ci}
7244514f5e3Sopenharmony_ci
7254514f5e3Sopenharmony_cisize_t SharedGCStats::GetAccumulatedAllocateSize()
7264514f5e3Sopenharmony_ci{
7274514f5e3Sopenharmony_ci    return accumulatedFreeSize_ + sHeap_->GetHeapObjectSize();
7284514f5e3Sopenharmony_ci}
7294514f5e3Sopenharmony_ci
7304514f5e3Sopenharmony_civoid SharedGCStats::RecordStatisticBeforeGC(TriggerGCType gcType, GCReason reason)
7314514f5e3Sopenharmony_ci{
7324514f5e3Sopenharmony_ci    size_t commitSize = sHeap_->GetCommittedSize();
7334514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_OBJ_SIZE, sHeap_->GetHeapObjectSize());
7344514f5e3Sopenharmony_ci    SetRecordData(RecordData::START_COMMIT_SIZE, commitSize);
7354514f5e3Sopenharmony_ci    SetRecordData(RecordData::SHARED_COMMIT_SIZE, commitSize);
7364514f5e3Sopenharmony_ci    IncreaseRecordData(RecordData::SHARED_TOTAL_COMMIT, commitSize);
7374514f5e3Sopenharmony_ci    gcType_ = GetGCType(gcType);
7384514f5e3Sopenharmony_ci    reason_ = reason;
7394514f5e3Sopenharmony_ci}
7404514f5e3Sopenharmony_ci
7414514f5e3Sopenharmony_civoid SharedGCStats::RecordStatisticAfterGC()
7424514f5e3Sopenharmony_ci{
7434514f5e3Sopenharmony_ci    SetRecordData(RecordData::END_OBJ_SIZE, sHeap_->GetHeapObjectSize());
7444514f5e3Sopenharmony_ci    SetRecordData(RecordData::END_COMMIT_SIZE, sHeap_->GetCommittedSize());
7454514f5e3Sopenharmony_ci
7464514f5e3Sopenharmony_ci    float duration = scopeDuration_[Scope::ScopeId::TotalGC];
7474514f5e3Sopenharmony_ci    if (GetRecordData(RecordData::SHARED_COUNT) == 0) {
7484514f5e3Sopenharmony_ci        SetRecordDuration(RecordDuration::SHARED_MIN_PAUSE, duration);
7494514f5e3Sopenharmony_ci        SetRecordDuration(RecordDuration::SHARED_MAX_PAUSE, duration);
7504514f5e3Sopenharmony_ci    } else {
7514514f5e3Sopenharmony_ci        SetRecordDuration(RecordDuration::SHARED_MIN_PAUSE,
7524514f5e3Sopenharmony_ci            std::min(GetRecordDuration(RecordDuration::SHARED_MIN_PAUSE), duration));
7534514f5e3Sopenharmony_ci        SetRecordDuration(RecordDuration::SHARED_MAX_PAUSE,
7544514f5e3Sopenharmony_ci            std::max(GetRecordDuration(RecordDuration::SHARED_MAX_PAUSE), duration));
7554514f5e3Sopenharmony_ci    }
7564514f5e3Sopenharmony_ci    IncreaseRecordData(RecordData::SHARED_COUNT);
7574514f5e3Sopenharmony_ci    IncreaseRecordDuration(RecordDuration::SHARED_TOTAL_PAUSE, duration);
7584514f5e3Sopenharmony_ci    size_t heapAliveSize = sHeap_->GetHeapObjectSize();
7594514f5e3Sopenharmony_ci    SetRecordData(RecordData::SHARED_ALIVE_SIZE, heapAliveSize);
7604514f5e3Sopenharmony_ci    IncreaseRecordData(RecordData::SHARED_TOTAL_ALIVE, heapAliveSize);
7614514f5e3Sopenharmony_ci
7624514f5e3Sopenharmony_ci    IncreaseTotalDuration(scopeDuration_[Scope::ScopeId::TotalGC]);
7634514f5e3Sopenharmony_ci    IncreaseAccumulatedFreeSize(GetRecordData(RecordData::START_OBJ_SIZE) -
7644514f5e3Sopenharmony_ci                                GetRecordData(RecordData::END_OBJ_SIZE));
7654514f5e3Sopenharmony_ci}
7664514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
767