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