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 ECMASCRIPT_PGO_PROFILER_H 17 #define ECMASCRIPT_PGO_PROFILER_H 18 19 #include <memory> 20 21 #include "ecmascript/ecma_vm.h" 22 #include "ecmascript/pgo_profiler/pgo_profiler_info.h" 23 24 namespace panda::ecmascript { 25 class PGOProfiler { 26 public: 27 NO_COPY_SEMANTIC(PGOProfiler); 28 NO_MOVE_SEMANTIC(PGOProfiler); 29 30 void Sample(JSTaggedType value, SampleMode mode = SampleMode::CALL_MODE); 31 private: 32 static constexpr uint32_t MERGED_EVERY_COUNT = 10; 33 PGOProfiler(EcmaVM * vm,bool isEnable)34 PGOProfiler([[maybe_unused]] EcmaVM *vm, bool isEnable) : isEnable_(isEnable) 35 { 36 if (isEnable_) { 37 recordInfos_ = std::make_unique<PGORecordDetailInfos>(0); 38 } 39 }; 40 ~PGOProfiler()41 virtual ~PGOProfiler() 42 { 43 Reset(false); 44 } 45 Reset(bool isEnable)46 void Reset(bool isEnable) 47 { 48 isEnable_ = isEnable; 49 methodCount_ = 0; 50 if (recordInfos_) { 51 recordInfos_->Clear(); 52 } else { 53 if (isEnable_) { 54 recordInfos_ = std::make_unique<PGORecordDetailInfos>(0); 55 } 56 } 57 } 58 59 bool isEnable_ {false}; 60 uint32_t methodCount_ {0}; 61 std::unique_ptr<PGORecordDetailInfos> recordInfos_; 62 friend class PGOProfilerManager; 63 }; 64 } // namespace panda::ecmascript 65 #endif // ECMASCRIPT_PGO_PROFILER_H 66