• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <algorithm>
18 #include <set>
19 #include <string>
20 #include "double_map.h"
21 #include "ebpf_data_reader.h"
22 #include "ebpf_data_structure.h"
23 #include "event_parser_base.h"
24 #include "string_help.h"
25 #include "string_to_numerical.h"
26 #include "symbols_file.h"
27 #include "ts_common.h"
28 
29 namespace SysTuning {
30 namespace TraceStreamer {
31 using namespace SysTuning::base;
32 using namespace SysTuning::EbpfStdtype;
33 using namespace OHOS::Developtools::HiPerf;
34 class EbpfBase : virtual public EventParserBase {
35 public:
36     EbpfBase(TraceDataCache* dataCache, const TraceStreamerFilters* ctx);
37     ~EbpfBase();
38     bool InitEbpfDataParser(EbpfDataReader* reader);
39     bool EBPFReloadElfSymbolTable(const std::vector<std::unique_ptr<SymbolsFile>>& symbolsFiles);
40 
41 protected:
42     void ParseCallStackData(const uint64_t* userIpsAddr, uint16_t count, uint32_t pid, uint32_t callId);
43     DataIndex GetSymbolNameIndexFromSymVaddr(const ElfEventFixedHeader* elfHeaderAddr, uint64_t symVaddr);
44     EbpfSymbolInfo GetEbpfSymbolInfo(uint32_t pid, uint64_t ip);
45     EbpfSymbolInfo GetSymbolNameIndexFromElfSym(uint32_t pid, uint64_t ip);
46     template <typename StartToMapsAddr>
47     void GetSymbolSave(EbpfSymbolInfo& ebpfSymbolInfo, StartToMapsAddr& startToMapsAddr, uint32_t pid, uint64_t ip);
48     void UpdateFilePathIndexToPidAndIpMap(DataIndex filePathIndex, uint32_t pid, uint64_t ip);
49     DataIndex ConvertToHexTextIndex(uint64_t number);
50     template <class T>
51     void UpdateFilePathIndexAndStValueToSymAddrMap(T* firstSymbolAddr, const int size, uint32_t filePathIndex);
52     template <class T>
53     void GetSymbolStartIndex(T* elfSym, uint32_t& symbolStart, uint64_t symVaddr);
54     ClockId clockId_ = INVALID_UINT32;
55     std::hash<std::string_view> hashFun_;
56     EbpfDataReader* reader_ = nullptr;
57     DoubleMap<uint32_t, uint64_t, EbpfSymbolInfo> pidAndIpToEbpfSymbolInfo_;
58     std::map<DataIndex, std::shared_ptr<std::set<std::tuple<uint32_t, uint64_t>>>> filePathIndexToPidAndIpMap_ = {};
59     std::map<DataIndex, uint64_t> ipStrIndexToIpMap_ = {};
60     std::map<uint32_t, uint32_t> callIdToPid_ = {};
61     DoubleMap<uint32_t, uint64_t, const uint8_t*> filePathIndexAndStValueToSymAddr_;
62     std::map<DataIndex, std::shared_ptr<ElfSymbolTable>> filePathIndexToImportSymbolTableMap_ = {};
63     DoubleMap<uint32_t, uint64_t, uint64_t> pidAndipsToCallId_;
64     uint64_t callChainId_ = 0;
65 
66 private:
67     std::unordered_map<DataIndex, std::shared_ptr<std::set<size_t>>> filePathIndexToCallStackRowMap_ = {};
68 };
69 } // namespace TraceStreamer
70 } // namespace SysTuning
71 #endif // EBPF_BASE_H
72