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 110 class FrameMaps : public CacheBase, public BatchCacheBase { 111 public: 112 size_t AppendNew(FrameSlice *frameSlice, uint64_t src, uint64_t dst); 113 const std::deque<uint64_t> &SrcIndexs() const; 114 const std::deque<uint64_t> &DstIndexs() const; ClearExportedData()115 void ClearExportedData() override 116 { 117 EraseElements(timeStamps_, ids_, srcs_, dsts_); 118 } 119 120 private: 121 std::deque<uint64_t> srcs_ = {}; 122 std::deque<uint64_t> dsts_ = {}; 123 }; 124 125 } // namespace TraceStdtype 126 } // namespace SysTuning 127 #endif // RENDER_SERVICE_STDTYPE_H 128