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 RENDER_SERVICE_STDTYPE_H 17 #define RENDER_SERVICE_STDTYPE_H 18 #include <memory> 19 #include <vector> 20 #include "base_stdtype.h" 21 #include "double_map.h" 22 23 namespace SysTuning { 24 namespace TraceStdtype { 25 using namespace SysTuning::TraceStreamer; 26 struct FrameSliceRow { 27 uint64_t ts = INVALID_UINT64; 28 uint32_t ipid = INVALID_UINT32; 29 uint32_t itid = INVALID_UINT32; 30 uint32_t vsyncId = INVALID_UINT32; 31 uint64_t callStackSliceId = INVALID_UINT64; 32 uint64_t end = INVALID_UINT64; 33 uint8_t type = INVALID_UINT8; 34 }; 35 class FrameSlice : public CacheBase, public BatchCacheBase { 36 public: 37 size_t AppendFrame(uint64_t ts, uint32_t ipid, uint32_t itid, uint32_t vsyncId, uint64_t callStackSliceId); 38 size_t AppendFrame(const FrameSliceRow &frameSliceRow); 39 void SetEndTime(uint64_t row, uint64_t end); 40 void SetType(uint64_t row, uint8_t type); 41 void SetDst(uint64_t row, uint64_t dst); 42 void SetSrcs(uint64_t row, const std::vector<uint64_t> &fromSlices); 43 void SetFlags(uint64_t row, const uint32_t flags); 44 void UpdateDepth(); 45 const std::deque<uint32_t> Ipids() const; 46 const std::deque<uint32_t> VsyncIds() const; 47 const std::deque<uint64_t> CallStackIds() const; 48 const std::deque<uint64_t> EndTss() const; 49 const std::deque<uint64_t> Dsts() const; 50 const std::deque<uint64_t> Durs() const; 51 const std::deque<uint8_t> Types() const; 52 const std::deque<uint8_t> Flags() const; 53 const std::deque<uint8_t> Depths() const; 54 const std::deque<uint32_t> FrameNos() const; 55 const std::deque<std::string> &Srcs() const; 56 void UpdateCallStackSliceId(uint64_t row, uint64_t callStackSliceId); 57 void SetEndTimeAndFlag(uint64_t row, uint64_t ts, uint64_t expectDur, uint64_t expectEnd); 58 void Erase(uint64_t row); GetAbnormalStartEndTimeState()59 static uint32_t GetAbnormalStartEndTimeState() 60 { 61 return abnormalStartEndTimeState_; 62 } ClearExportedData()63 void ClearExportedData() override 64 { 65 EraseElements(internalTids_, timeStamps_, ids_, ipids_, dsts_, srcs_, vsyncIds_, callStackIds_, endTss_, durs_, 66 types_, flags_, depths_, frameNos_); 67 } 68 69 public: 70 typedef enum FrameSliceType { ACTURAL_SLICE, EXPECT_SLICE } FrameSliceType; 71 72 private: 73 std::deque<uint32_t> ipids_ = {}; 74 std::deque<uint64_t> dsts_ = {}; 75 std::deque<std::string> srcs_ = {}; 76 std::deque<uint32_t> vsyncIds_ = {}; 77 std::deque<uint64_t> callStackIds_ = {}; 78 std::deque<uint64_t> endTss_ = {}; 79 std::deque<uint64_t> durs_ = {}; 80 std::deque<uint8_t> types_ = {}; 81 std::deque<uint8_t> flags_ = {}; 82 std::deque<uint8_t> depths_ = {}; 83 std::deque<uint32_t> frameNos_ = {}; 84 const uint32_t invalidRow_ = 2; 85 static const uint32_t abnormalStartEndTimeState_ = 3; 86 const uint8_t flagValue_ = 2; 87 }; 88 89 class GPUSlice : public CacheBase, public BatchCacheBase { 90 public: 91 size_t AppendNew(uint32_t frameRow, uint64_t dur); 92 const std::deque<uint32_t> &FrameRows() const; 93 const std::deque<uint64_t> &Durs() const; Clear()94 void Clear() override 95 { 96 CacheBase::Clear(); 97 frameRows_.clear(); 98 durs_.clear(); 99 } ClearExportedData()100 void ClearExportedData() override 101 { 102 EraseElements(ids_, frameRows_, durs_); 103 } 104 105 private: 106 std::deque<uint32_t> frameRows_ = {}; 107 std::deque<uint64_t> durs_ = {}; 108 }; 109 struct DmaFenceRow { 110 uint64_t timeStamp = INVALID_UINT64; 111 uint64_t duration = INVALID_UINT64; 112 DataIndex eventName = INVALID_DATAINDEX; 113 DataIndex driver = INVALID_DATAINDEX; 114 DataIndex timeline = INVALID_DATAINDEX; 115 uint32_t context = INVALID_UINT32; 116 uint32_t seqno = INVALID_UINT32; 117 }; 118 119 class DmaFence : public CacheBase { 120 public: 121 size_t AppendNew(const DmaFenceRow &dmaFenceRow); 122 const std::deque<uint64_t> &DursData() const; 123 const std::deque<DataIndex> &CatsData() const; 124 const std::deque<DataIndex> &DriversData() const; 125 const std::deque<DataIndex> &TimelinesData() const; 126 const std::deque<uint32_t> &ContextsData() const; 127 const std::deque<uint32_t> &SeqnosData() const; Clear()128 void Clear() override 129 { 130 CacheBase::Clear(); 131 durs_.clear(); 132 cats_.clear(); 133 drivers_.clear(); 134 timelines_.clear(); 135 contexts_.clear(); 136 seqnos_.clear(); 137 } 138 139 private: 140 std::deque<uint64_t> durs_ = {}; 141 std::deque<DataIndex> cats_ = {}; 142 std::deque<DataIndex> drivers_ = {}; 143 std::deque<DataIndex> timelines_ = {}; 144 std::deque<uint32_t> contexts_ = {}; 145 std::deque<uint32_t> seqnos_ = {}; 146 }; 147 148 class FrameMaps : public CacheBase, public BatchCacheBase { 149 public: 150 size_t AppendNew(FrameSlice *frameSlice, uint64_t src, uint64_t dst); 151 const std::deque<uint64_t> &SrcIndexs() const; 152 const std::deque<uint64_t> &DstIndexs() const; ClearExportedData()153 void ClearExportedData() override 154 { 155 EraseElements(timeStamps_, ids_, srcs_, dsts_); 156 } 157 158 private: 159 std::deque<uint64_t> srcs_ = {}; 160 std::deque<uint64_t> dsts_ = {}; 161 }; 162 163 } // namespace TraceStdtype 164 } // namespace SysTuning 165 #endif // RENDER_SERVICE_STDTYPE_H 166