• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 #ifndef PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H
16 #define PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H
17 
18 #include <array>
19 
20 #include "runtime/include/mem/panda_containers.h"
21 #include "runtime/mem/mem_stats.h"
22 
23 namespace panda::mem {
24 
25 /**
26  * Implementation of MemStats with additional info about memory.
27  */
28 class MemStatsAdditionalInfo : public MemStats<MemStatsAdditionalInfo> {
29     enum STAT_TYPE { BYTES_ALLOCATED = 0, BYTES_FREED, MAX_FOOTPRINT, OBJECTS_ALLOCATED, STAT_TYPE_NUM };
30 
31 public:
32     NO_COPY_SEMANTIC(MemStatsAdditionalInfo);
33     NO_MOVE_SEMANTIC(MemStatsAdditionalInfo);
34 
35     MemStatsAdditionalInfo() = default;
36 
37     PandaString GetAdditionalStatistics(HeapManager *heap_manager);
38 
39     void RecordGCPhaseStart(GCPhase phase);
40     void RecordGCPhaseEnd();
41 
42     uint64_t GetMinGCPhaseTime(GCPhase phase);
43     uint64_t GetMaxGCPhaseTime(GCPhase phase);
44     uint64_t GetAverageGCPhaseTime(GCPhase phase);
45     uint64_t GetTotalGCPhaseTime(GCPhase phase);
46 
47     ~MemStatsAdditionalInfo() override = default;
48 
49 private:
50     clock::time_point phase_start_time_ = clock::now();
51     GCPhase current_phase_ = GCPhase::GC_PHASE_IDLE;
52     std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> min_phase_time_ = {};
53     std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> max_phase_time_ = {};
54     std::array<duration, ToIndex(GCPhase::GC_PHASE_LAST)> sum_phase_time_ = {};
55     std::array<uint64_t, ToIndex(GCPhase::GC_PHASE_LAST)> phase_count_ = {};
56     os::memory::Mutex phase_lock_;
57 };
58 
59 extern template class MemStats<MemStatsAdditionalInfo>;
60 }  // namespace panda::mem
61 #endif  // PANDA_RUNTIME_MEM_MEM_STATS_ADDITIONAL_INFO_H
62