1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 HIPERF_STDTYPE_H 17 #define HIPERF_STDTYPE_H 18 #include "base_stdtype.h" 19 20 namespace SysTuning { 21 namespace TraceStdtype { 22 23 struct PerfCallChainRow { 24 /* data */ 25 uint32_t callChainId = INVALID_UINT32; 26 uint32_t depth = INVALID_UINT32; 27 uint64_t ip = INVALID_UINT64; 28 uint64_t vaddrInFile = INVALID_UINT64; 29 uint64_t fileId = INVALID_UINT64; 30 uint64_t symbolId = INVALID_UINT64; 31 }; 32 33 class PerfCallChain : public CacheBase { 34 public: 35 size_t AppendNewPerfCallChain(const PerfCallChainRow &context); 36 const std::deque<uint32_t> &CallChainIds() const; 37 const std::deque<uint32_t> &Depths() const; 38 const std::deque<uint64_t> &Ips() const; 39 const std::deque<uint64_t> &VaddrInFiles() const; 40 const std::deque<uint64_t> &FileIds() const; 41 const std::deque<uint64_t> &SymbolIds() const; 42 const std::deque<DataIndex> &Names() const; 43 void SetName(uint64_t index, DataIndex name); 44 void UpdateSymbolId(size_t index, DataIndex symbolId); 45 void Clear() override; 46 void UpdateSymbolRelatedData(size_t index, uint64_t vaddrInFile, uint64_t symbolId, DataIndex nameIndex); 47 48 private: 49 std::deque<uint32_t> callChainIds_ = {}; 50 std::deque<uint32_t> depths_ = {}; 51 std::deque<uint64_t> ips_ = {}; 52 std::deque<uint64_t> vaddrInFiles_ = {}; 53 std::deque<uint64_t> fileIds_ = {}; 54 std::deque<uint64_t> symbolIds_ = {}; 55 std::deque<DataIndex> names_ = {}; 56 }; 57 58 class PerfFiles : public CacheBase { 59 public: 60 size_t AppendNewPerfFiles(uint64_t fileIds, uint32_t serial, DataIndex symbols, DataIndex filePath); 61 const std::deque<uint64_t> &FileIds() const; 62 const std::deque<DataIndex> &Symbols() const; 63 const std::deque<DataIndex> &FilePaths() const; 64 const std::deque<uint32_t> &Serials() const; 65 void Clear() override; 66 bool EraseFileIdSameData(uint64_t fileId); 67 68 private: 69 std::deque<uint64_t> fileIds_ = {}; 70 std::deque<uint32_t> serials_ = {}; 71 std::deque<DataIndex> symbols_ = {}; 72 std::deque<DataIndex> filePaths_ = {}; 73 }; 74 struct PerfSampleRow { 75 uint32_t sampleId = INVALID_UINT32; 76 uint64_t timeStamp = INVALID_UINT64; 77 uint32_t tid = INVALID_UINT32; 78 uint64_t eventCount = INVALID_UINT64; 79 uint64_t eventTypeId = INVALID_UINT64; 80 uint64_t timestampTrace = INVALID_UINT64; 81 uint64_t cpuId = INVALID_UINT64; 82 uint64_t threadState = INVALID_UINT64; 83 }; 84 class PerfSample : public CacheBase { 85 public: 86 size_t AppendNewPerfSample(const PerfSampleRow &perfSampleRow); 87 const std::deque<uint32_t> &SampleIds() const; 88 const std::deque<uint32_t> &Tids() const; 89 const std::deque<uint64_t> &EventCounts() const; 90 const std::deque<uint64_t> &EventTypeIds() const; 91 const std::deque<uint64_t> &TimestampTraces() const; 92 const std::deque<uint64_t> &CpuIds() const; 93 const std::deque<DataIndex> &ThreadStates() const; 94 void Clear() override; 95 96 private: 97 std::deque<uint32_t> sampleIds_ = {}; 98 std::deque<uint32_t> tids_ = {}; 99 std::deque<uint64_t> eventCounts_ = {}; 100 std::deque<uint64_t> eventTypeIds_ = {}; 101 std::deque<uint64_t> timestampTraces_ = {}; 102 std::deque<uint64_t> cpuIds_ = {}; 103 std::deque<DataIndex> threadStates_ = {}; 104 }; 105 106 class PerfThread : public CacheBase { 107 public: 108 size_t AppendNewPerfThread(uint32_t pid, uint32_t tid, DataIndex threadName); 109 const std::deque<uint32_t> &Pids() const; 110 const std::deque<uint32_t> &Tids() const; 111 const std::deque<DataIndex> &ThreadNames() const; 112 void Clear() override; 113 114 private: 115 std::deque<uint32_t> tids_ = {}; 116 std::deque<uint32_t> pids_ = {}; 117 std::deque<DataIndex> threadNames_ = {}; 118 }; 119 120 class PerfReport : public CacheBase { 121 public: 122 size_t AppendNewPerfReport(DataIndex type, DataIndex value); 123 const std::deque<DataIndex> &Types() const; 124 const std::deque<DataIndex> &Values() const; 125 126 private: 127 std::deque<DataIndex> types_ = {}; 128 std::deque<DataIndex> values_ = {}; 129 }; 130 131 struct PerfNapiAsyncRow { 132 uint64_t timeStamp = INVALID_UINT64; 133 DataIndex traceid = INVALID_UINT64; 134 uint8_t cpuId = INVALID_UINT8; 135 InternalTid threadId = INVALID_UINT32; 136 uint32_t processId = INVALID_UINT32; 137 uint32_t callerCallchainid = INVALID_UINT32; 138 uint32_t calleeCallchainid = INVALID_UINT32; 139 uint64_t perfSampleId = INVALID_UINT64; 140 uint64_t eventCount = 0; 141 uint64_t eventTypeId = 0; 142 }; 143 144 class PerfNapiAsync : public CacheBase { 145 public: 146 size_t AppendNewPerfNapiAsync(const PerfNapiAsyncRow &perfNapiAsyncRow); 147 const std::deque<DataIndex> &Traceids() const; 148 const std::deque<uint8_t> &CpuIds() const; 149 const std::deque<uint32_t> &ProcessIds() const; 150 const std::deque<uint32_t> &CallerCallchainids() const; 151 const std::deque<uint32_t> &CalleeCallchainids() const; 152 const std::deque<uint64_t> &PerfSampleIds() const; 153 const std::deque<uint64_t> &EventCounts() const; 154 const std::deque<uint64_t> &EventTypeIds() const; 155 void Clear() override; 156 157 private: 158 std::deque<DataIndex> traceids_ = {}; 159 std::deque<uint8_t> cpuIds_ = {}; 160 std::deque<uint32_t> processIds_ = {}; 161 std::deque<uint32_t> callerCallchainids_ = {}; 162 std::deque<uint32_t> calleeCallchainids_ = {}; 163 std::deque<uint64_t> perfSampleIds_ = {}; 164 std::deque<uint64_t> eventCounts_ = {}; 165 std::deque<uint64_t> eventTypeIds_ = {}; 166 }; 167 } // namespace TraceStdtype 168 } // namespace SysTuning 169 #endif // HIPERF_STDTYPE_H 170