1 /* 2 * Copyright (c) 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 ECMASCRIPT_PGO_INFO_H 17 #define ECMASCRIPT_PGO_INFO_H 18 19 #include <cstdint> 20 #include <memory> 21 22 #include "libpandabase/macros.h" 23 24 #include "ecmascript/mem/c_string.h" 25 #include "ecmascript/pgo_profiler/pgo_utils.h" 26 #include "ecmascript/platform/mutex.h" 27 28 namespace panda::ecmascript::pgo { 29 class PGOProfilerHeader; 30 class PGOPandaFileInfos; 31 class PGOAbcFilePool; 32 class PGORecordDetailInfos; 33 class SaveTask; 34 class PGOProfilerDecoder; 35 36 class PGOInfo { 37 public: 38 explicit PGOInfo(uint32_t hotnessThreshold = 0); 39 ~PGOInfo(); 40 41 NO_COPY_SEMANTIC(PGOInfo); 42 NO_MOVE_SEMANTIC(PGOInfo); 43 44 PGOProfilerHeader& GetHeader() const; 45 PGOProfilerHeader* GetHeaderPtr() const; 46 void SetHeader(PGOProfilerHeader* header); 47 PGOPandaFileInfos& GetPandaFileInfos() const; 48 void SetPandaFileInfos(std::unique_ptr<PGOPandaFileInfos> pandaFileInfos); 49 PGOAbcFilePool& GetAbcFilePool() const; 50 std::shared_ptr<PGOAbcFilePool> GetAbcFilePoolPtr() const; 51 void SetAbcFilePool(std::shared_ptr<PGOAbcFilePool> abcFilePool); 52 PGORecordDetailInfos& GetRecordDetailInfos() const; 53 std::shared_ptr<PGORecordDetailInfos> GetRecordDetailInfosPtr() const; 54 void SetRecordDetailInfos(std::shared_ptr<PGORecordDetailInfos> recordDetailInfos); 55 void Clear(); 56 void SetHotnessThreshold(uint32_t threshold); 57 uint32_t GetHotnessThreshold() const; 58 void SamplePandaFileInfoSafe(uint32_t checksum, const CString& abcName); 59 void MergeWithExistProfile(PGOInfo& other, PGOProfilerDecoder& decoder, const SaveTask* task); 60 bool GetPandaFileIdSafe(const CString& abcName, ApEntityId& entryId); 61 bool GetPandaFileDescSafe(ApEntityId abcId, CString& desc); 62 void MergeSafe(const PGORecordDetailInfos& recordInfos); 63 void MergeSafe(const PGOPandaFileInfos& pandaFileInfos); 64 void MergeSafe(const PGOInfo& other); 65 bool VerifyPandaFileMatched(const PGOPandaFileInfos& pandaFileInfos, 66 const std::string& base, 67 const std::string& incoming) const; 68 void ProcessToBinary(std::fstream& fileStream, PGOProfilerHeader* header); 69 Mutex& GetSampleMutexLock(); 70 ConcurrentGuardValue& GetConcurrentGuardValue(); 71 72 private: 73 uint32_t hotnessThreshold_ {0}; 74 PGOProfilerHeader* header_; 75 std::unique_ptr<PGOPandaFileInfos> pandaFileInfos_; 76 std::shared_ptr<PGOAbcFilePool> abcFilePool_; 77 std::shared_ptr<PGORecordDetailInfos> recordDetailInfos_; 78 Mutex sampleMutexLock_; 79 ConcurrentGuardValue v_; 80 }; 81 } // namespace panda::ecmascript::pgo 82 #endif // ECMASCRIPT_PGO_INFO_H