1 /* 2 * Copyright (c) 2021 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 EBPF_BASE_H 16 #define EBPF_BASE_H 17 #include <string> 18 #include "double_map.h" 19 #include "ebpf_data_reader.h" 20 #include "ebpf_stdtype.h" 21 #include "event_parser_base.h" 22 #include "string_to_numerical.h" 23 #include "ts_common.h" 24 25 namespace SysTuning { 26 namespace TraceStreamer { 27 using namespace SysTuning::base; 28 using namespace SysTuning::EbpfStdtype; 29 30 class EbpfBase : virtual public EventParserBase { 31 public: 32 EbpfBase(TraceDataCache* dataCache, const TraceStreamerFilters* ctx); 33 ~EbpfBase(); 34 bool InitEbpfDataParser(EbpfDataReader* reader); 35 36 protected: 37 void ParseCallStackData(const uint64_t* userIpsAddr, uint16_t count, uint32_t pid, uint64_t callId); 38 DataIndex GetSymbolNameIndexFromSymVaddr(const ElfEventFixedHeader* elfHeaderAddr, uint64_t symVaddr); 39 SymbolAndFilePathIndex GetSymbolAndFilePathIndex(uint32_t pid, uint64_t ip); 40 SymbolAndFilePathIndex GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip); 41 DataIndex ConvertToHexTextIndex(uint64_t number); 42 43 ClockId clockId_ = INVALID_UINT32; 44 std::hash<std::string_view> hashFun_; 45 EbpfDataReader* reader_ = nullptr; 46 DoubleMap<uint32_t, uint64_t, SymbolAndFilePathIndex> pidAndIpToSymbolAndFilePathIndex_; 47 DoubleMap<uint32_t, uint64_t, uint64_t> pidAndipsToCallId_; 48 uint64_t callChainId_ = 0; 49 }; 50 } // namespace TraceStreamer 51 } // namespace SysTuning 52 #endif // EBPF_BASE_H 53