• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PGOProfilerDecoder;
34 
35 class PGOInfo {
36 public:
37     explicit PGOInfo(uint32_t hotnessThreshold = 0);
38     ~PGOInfo();
39 
40     NO_COPY_SEMANTIC(PGOInfo);
41     NO_MOVE_SEMANTIC(PGOInfo);
42 
43     PGOProfilerHeader& GetHeader() const;
44     PGOProfilerHeader* GetHeaderPtr() const;
45     void SetHeader(PGOProfilerHeader* header);
46     PGOPandaFileInfos& GetPandaFileInfos() const;
47     void SetPandaFileInfos(std::unique_ptr<PGOPandaFileInfos> pandaFileInfos);
48     PGOAbcFilePool& GetAbcFilePool() const;
49     std::shared_ptr<PGOAbcFilePool> GetAbcFilePoolPtr() const;
50     void SetAbcFilePool(std::shared_ptr<PGOAbcFilePool> abcFilePool);
51     PGORecordDetailInfos& GetRecordDetailInfos() const;
52     std::shared_ptr<PGORecordDetailInfos> GetRecordDetailInfosPtr() const;
53     void SetRecordDetailInfos(std::shared_ptr<PGORecordDetailInfos> recordDetailInfos);
54     void Clear();
55     void SetHotnessThreshold(uint32_t threshold);
56     uint32_t GetHotnessThreshold() const;
57     void SamplePandaFileInfoSafe(uint32_t checksum, const CString& abcName);
58     void MergeWithExistProfile(PGOInfo& other, PGOProfilerDecoder& decoder);
59     bool GetPandaFileIdSafe(const CString& abcName, ApEntityId& entryId);
60     bool GetPandaFileDescSafe(ApEntityId abcId, CString& desc);
61     void MergeSafe(const PGORecordDetailInfos& recordInfos);
62     void MergeSafe(const PGOPandaFileInfos& pandaFileInfos);
63     void MergeSafe(const PGOInfo& other);
64     bool VerifyPandaFileMatched(const PGOPandaFileInfos& pandaFileInfos,
65                                 const std::string& base,
66                                 const std::string& incoming) const;
67     void ProcessToBinary(std::fstream& fileStream, PGOProfilerHeader* header);
68     Mutex& GetSampleMutexLock();
69     ConcurrentGuardValue& GetConcurrentGuardValue();
70 
71 private:
72     uint32_t hotnessThreshold_ {0};
73     PGOProfilerHeader* header_;
74     std::unique_ptr<PGOPandaFileInfos> pandaFileInfos_;
75     std::shared_ptr<PGOAbcFilePool> abcFilePool_;
76     std::shared_ptr<PGORecordDetailInfos> recordDetailInfos_;
77     Mutex sampleMutexLock_;
78     ConcurrentGuardValue v_;
79 };
80 } // namespace panda::ecmascript::pgo
81 #endif // ECMASCRIPT_PGO_INFO_H