1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H_ 17 #define PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H_ 18 19 #include <array> 20 21 #include "runtime/include/mem/panda_containers.h" 22 #include "runtime/mem/mem_stats.h" 23 24 namespace panda { 25 class Class; 26 } // namespace panda 27 28 namespace panda::mem { 29 30 /** 31 * Implementation of MemStats with additional info about memory. 32 */ 33 class MemStatsAdditionalInfo : public MemStats<MemStatsAdditionalInfo> { 34 enum STAT_TYPE { BYTES_ALLOCATED = 0, BYTES_FREED, MAX_FOOTPRINT, OBJECTS_ALLOCATED, STAT_TYPE_NUM }; 35 36 public: 37 NO_COPY_SEMANTIC(MemStatsAdditionalInfo); 38 NO_MOVE_SEMANTIC(MemStatsAdditionalInfo); 39 40 MemStatsAdditionalInfo() = default; 41 42 PandaString GetAdditionalStatistics(HeapManager *heap_manager); 43 44 void RecordGCPhaseStart(GCPhase phase); 45 void RecordGCPhaseEnd(); 46 47 uint64_t GetMinGCPhaseTime(GCPhase phase); 48 uint64_t GetMaxGCPhaseTime(GCPhase phase); 49 uint64_t GetAverageGCPhaseTime(GCPhase phase); 50 uint64_t GetTotalGCPhaseTime(GCPhase phase); 51 52 ~MemStatsAdditionalInfo() override = default; 53 54 private: 55 clock::time_point phase_start_time_ = clock::now(); 56 GCPhase current_phase_ = GCPhase::GC_PHASE_IDLE; 57 std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> min_phase_time_ = {}; 58 std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> max_phase_time_ = {}; 59 std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> sum_phase_time_ = {}; 60 std::array<uint, ToIndex(GCPhase::GC_PHASE_LAST)> phase_count_ = {}; 61 os::memory::Mutex phase_lock_; 62 }; 63 64 extern template class MemStats<MemStatsAdditionalInfo>; 65 66 } // namespace panda::mem 67 68 #endif // PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H_ 69