1 /** 2 * Copyright (c) 2023 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/mem/gc/g1/g1_predictions.h" 21 #include "runtime/mem/gc/g1/collection_set.h" 22 23 namespace panda::mem { 24 class G1Analytics { 25 public: 26 explicit G1Analytics(uint64_t now); 27 28 void ReportCollectionStart(uint64_t time); 29 void ReportCollectionEnd(uint64_t endTime, const CollectionSet &collectionSet); 30 31 void ReportEvacuatedBytes(size_t bytes); 32 void ReportScanRemsetStart(uint64_t time); 33 void ReportScanRemsetEnd(uint64_t time); 34 void ReportMarkingStart(uint64_t time); 35 void ReportMarkingEnd(uint64_t time); 36 void ReportEvacuationStart(uint64_t time); 37 void ReportEvacuationEnd(uint64_t time); 38 void ReportUpdateRefsStart(uint64_t time); 39 void ReportUpdateRefsEnd(uint64_t time); 40 void ReportPromotedRegion(); 41 void ReportLiveObjects(size_t num); 42 43 double PredictAllocationRate() const; 44 int64_t PredictYoungCollectionTimeInMicros(size_t edenLength) const; 45 int64_t EstimatePredictionErrorInMicros() const; 46 int64_t PredictOldCollectionTimeInMicros(size_t liveBytes, size_t liveObjects) const; 47 int64_t PredictOldCollectionTimeInMicros(Region *region) const; 48 49 private: 50 double PredictPromotedRegions(size_t edenLength) const; 51 size_t EstimatePromotionTimeInMicros(size_t promotedRegions) const; 52 53 static constexpr uint64_t DEFAULT_PROMOTION_COST = 50; 54 const uint64_t promotionCost_ {DEFAULT_PROMOTION_COST}; 55 uint64_t previousYoungCollectionEnd_; 56 uint64_t currentYoungCollectionStart_ {0}; 57 uint64_t scanRemsetStart_ {0}; 58 uint64_t scanRemsetEnd_ {0}; 59 uint64_t markingStart_ {0}; 60 uint64_t markingEnd_ {0}; 61 uint64_t evacuationStart_ {0}; 62 uint64_t evacuationEnd_ {0}; 63 uint64_t updateRefsStart_ {0}; 64 uint64_t updateRefsEnd_ {0}; 65 panda::Sequence allocationRateSeq_; 66 panda::Sequence copiedBytesSeq_; 67 panda::Sequence copyingBytesRateSeq_; 68 panda::Sequence scanRemsetTimeSeq_; 69 panda::Sequence liveObjecstSeq_; 70 panda::Sequence markingRateSeq_; 71 panda::Sequence updateRefsTimeSeq_; 72 panda::Sequence promotionSeq_; 73 panda::Sequence predictionErrorSeq_; 74 panda::Sequence liveObjectsSeq_; 75 static constexpr double DEFAULT_CONFIDENCE_FACTOR = 0.5; 76 G1Predictor predictor_ {DEFAULT_CONFIDENCE_FACTOR}; 77 std::atomic<size_t> copiedBytes_ {0}; 78 std::atomic<size_t> promotedRegions_ {0}; 79 std::atomic<size_t> liveObjects_ {0}; 80 }; 81 } // namespace panda::mem 82 #endif 83