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#ifndef DFX_INSTR_STATISTIC_H 16#define DFX_INSTR_STATISTIC_H 17 18#include <cstdint> 19#include <string> 20#include <unordered_map> 21#include <vector> 22 23#ifdef INSTR_STATISTIC_ENABLE 24#define INSTR_STATISTIC_ELF(elf) \ 25 OHOS::HiviewDFX::DfxInstrStatistic::GetInstance().SetCurrentStatLib(elf) 26#define INSTR_STATISTIC(Type, Arg1, Arg2) \ 27 OHOS::HiviewDFX::DfxInstrStatistic::GetInstance().AddInstrStatistic(Type, (uint64_t)Arg1, (uint64_t)Arg2) 28#else 29#define INSTR_STATISTIC_ELF(elf) 30#define INSTR_STATISTIC(Type, Arg1, Arg2) 31#endif 32 33namespace OHOS { 34namespace HiviewDFX { 35enum InstrStatisticType : uint32_t { 36 InstructionEntriesArmExidx = 0, 37 InstructionEntriesEhFrame, 38 InstructionEntriesDebugFrame, 39 40 UnsupportedArmExidx = 10, 41 UnsupportedDwarfOp_Reg, 42 UnsupportedDwarfOp_Regx, 43 UnsupportedDwarfOp_Breg, 44 UnsupportedDwarfOp_Bregx, 45 UnsupportedDwCfaOffset, 46 UnsupportedDwCfaValOffset, 47 UnsupportedDwCfaRegister, 48 UnsupportedDwCfaExpr, 49 UnsupportedDwCfaValExpr, 50 UnsupportedDwCfaRestore, 51 UnsupportedDwCfaUndefined, 52 UnsupportedDwCfaSame, 53 UnsupportedDefCfa, 54}; 55 56class DfxInstrStatistic { 57public: 58 typedef std::unordered_map<uint32_t, std::shared_ptr<std::vector<std::pair<uint64_t, uint64_t>>>> STAT_INFO_MAP; 59 static DfxInstrStatistic &GetInstance(); 60 virtual ~DfxInstrStatistic() { statisticInfo_.clear(); } 61 62 void SetCurrentStatLib(const std::string soName); 63 void AddInstrStatistic(InstrStatisticType type, uint64_t val, uint64_t err); 64 void DumpInstrStatResult(std::vector<std::pair<uint32_t, uint32_t>> &result); 65private: 66 DfxInstrStatistic() = default; 67 std::string soName_; 68 STAT_INFO_MAP statisticInfo_; 69}; 70} // namespace HiviewDFX 71} // namespace OHOS 72#endif