• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2023-2024 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_MEM_GC_G1_G1_ANALYTICS_H
17 #define PANDA_MEM_GC_G1_G1_ANALYTICS_H
18 
19 #include <atomic>
20 #include "runtime/include/gc_task.h"
21 #include "runtime/mem/gc/g1/g1_predictions.h"
22 #include "runtime/mem/gc/g1/collection_set.h"
23 
24 namespace ark::mem {
25 class G1Analytics {
26 public:
27     explicit G1Analytics(uint64_t now);
28 
29     void ReportCollectionStart(uint64_t time);
30     void ReportCollectionEnd(GCTaskCause gcCause, uint64_t endTime, const CollectionSet &collectionSet,
31                              bool dump = false);
32 
33     void ReportEvacuatedBytes(size_t bytes);
34     void ReportRemsetSize(size_t remsetSize, size_t remsetRefsCount);
35     void ReportScanDirtyCardsStart(uint64_t time);
36     void ReportScanDirtyCardsEnd(uint64_t time, size_t dirtyCardsCount);
37     void ReportMarkingStart(uint64_t time);
38     void ReportMarkingEnd(uint64_t time, size_t remsetRefsCount);
39     void ReportEvacuationStart(uint64_t time);
40     void ReportEvacuationEnd(uint64_t time);
41     void ReportUpdateRefsStart(uint64_t time);
42     void ReportUpdateRefsEnd(uint64_t time);
43     void ReportPromotedRegion();
44     void ReportLiveObjects(size_t num);
45     void ReportSurvivedBytesRatio(const CollectionSet &collectionSet);
46     double PredictAllocationRate() const;
47     uint64_t PredictYoungCollectionTimeInMicros(size_t edenLength) const;
48     uint64_t PredictYoungCollectionTimeInMicros(const CollectionSet &collectionSet) const;
49     uint64_t PredictOldCollectionTimeInMicros(size_t remsetSize, size_t liveBytes, size_t liveObjects) const;
50     uint64_t PredictOldCollectionTimeInMicros(Region *region) const;
51     uint64_t PredictScanDirtyCardsTime(size_t dirtyCardsCount) const;
52     double PredictSurvivedBytesRatio() const;
53 
ReportPredictedMixedPause(uint64_t time)54     void ReportPredictedMixedPause(uint64_t time)
55     {
56         predictedMixedPause_ = time;
57     }
58 
59 private:
60     size_t GetPromotedRegions() const;
61     size_t GetEvacuatedBytes() const;
62     double PredictPromotedRegions(size_t edenLength) const;
63     uint64_t EstimatePromotionTimeInMicros(size_t promotedRegions) const;
64     uint64_t PredictUpdateRefsTimeInMicros(size_t liveObjects, size_t remsetRefsCount) const;
65     uint64_t PredictMarkingTimeInMicros(size_t liveObjects, size_t remsetRefsCount) const;
66     uint64_t PredictCopyingTimeInMicros(size_t copiedBytes) const;
67     size_t PredictRemsetRefsCount(size_t remsetSize) const;
68 
PredictTime(size_t volume,ark::Sequence rateSeq)69     uint64_t PredictTime(size_t volume, ark::Sequence rateSeq) const
70     {
71         auto ratePrediction = predictor_.Predict(rateSeq);
72         return ratePrediction == 0 ? 0 : volume / ratePrediction;
73     }
74 
75     void DumpMetrics(const CollectionSet &collectionSet, uint64_t pauseTime, double allocationRate) const;
76 
77     static constexpr uint64_t DEFAULT_PROMOTION_COST = 50;
78     const uint64_t promotionCost_ {DEFAULT_PROMOTION_COST};
79     uint64_t previousYoungCollectionEnd_;
80     uint64_t currentYoungCollectionStart_ {0};
81     size_t remsetSize_ {0};
82     size_t remsetRefsCount_ {0};
83     size_t totalRemsetRefsCount_ {0};
84     size_t dirtyCardsCount_ {0};
85     uint64_t markingStart_ {0};
86     uint64_t markingEnd_ {0};
87     uint64_t evacuationStart_ {0};
88     uint64_t evacuationEnd_ {0};
89     uint64_t updateRefsStart_ {0};
90     uint64_t updateRefsEnd_ {0};
91     uint64_t scanDirtyCardsStart_ {0};
92     uint64_t scanDirtyCardsEnd_ {0};
93     uint64_t predictedMixedPause_ {0};
94     ark::Sequence allocationRateSeq_;
95     ark::Sequence copiedBytesSeq_;
96     ark::Sequence copyingBytesRateSeq_;
97     ark::Sequence remsetRefsSeq_;
98     ark::Sequence remsetRefsPerChunkSeq_;
99     ark::Sequence liveObjecstSeq_;
100     ark::Sequence markingRateSeq_;
101     ark::Sequence updateRefsRateSeq_;
102     ark::Sequence promotionSeq_;
103     ark::Sequence otherSeq_;
104     ark::Sequence liveObjectsSeq_;
105     ark::Sequence scanDirtyCardsRateSeq_;
106     ark::Sequence survivedBytesRatioSeq_;
107     static constexpr double DEFAULT_CONFIDENCE_FACTOR = 0.5;
108     G1Predictor predictor_ {DEFAULT_CONFIDENCE_FACTOR};
109     std::atomic<size_t> copiedBytes_ {0};
110     std::atomic<size_t> promotedRegions_ {0};
111     std::atomic<size_t> liveObjects_ {0};
112 };
113 }  // namespace ark::mem
114 #endif
115