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 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 class FrameSlice : public CacheBase, public BatchCacheBase { 27 public: 28 size_t AppendFrame(uint64_t ts, uint32_t ipid, uint32_t itid, uint32_t vsyncId, uint64_t callStackSliceId); 29 size_t AppendFrame(uint64_t ts, 30 uint32_t ipid, 31 uint32_t itid, 32 uint32_t vsyncId, 33 uint64_t callStackSliceId, 34 uint64_t end, 35 uint8_t type); 36 void SetEndTime(uint64_t row, uint64_t end); 37 void SetType(uint64_t row, uint8_t type); 38 void SetDst(uint64_t row, uint64_t dst); 39 void SetSrcs(uint64_t row, const std::vector<uint64_t>& fromSlices); 40 void SetFlags(uint64_t row, const uint32_t flags); 41 void UpdateDepth(); 42 const std::deque<uint32_t> Ipids() const; 43 const std::deque<uint32_t> VsyncIds() const; 44 const std::deque<uint64_t> CallStackIds() const; 45 const std::deque<uint64_t> EndTss() const; 46 const std::deque<uint64_t> Dsts() const; 47 const std::deque<uint64_t> Durs() const; 48 const std::deque<uint8_t> Types() const; 49 const std::deque<uint8_t> Flags() const; 50 const std::deque<uint8_t> Depths() const; 51 const std::deque<uint32_t> FrameNos() const; 52 const std::deque<std::string>& Srcs() const; 53 void UpdateCallStackSliceId(uint64_t row, uint64_t callStackSliceId); 54 void SetEndTimeAndFlag(uint64_t row, uint64_t ts, uint64_t expectDur, uint64_t expectEnd); 55 void Erase(uint64_t row); GetAbnormalStartEndTimeState()56 static uint32_t GetAbnormalStartEndTimeState() 57 { 58 return abnormalStartEndTimeState_; 59 } ClearExportedData()60 void ClearExportedData() override 61 { 62 EraseElements(internalTids_, timeStamps_, ids_, ipids_, dsts_, srcs_, vsyncIds_, callStackIds_, endTss_, durs_, 63 types_, flags_, depths_, frameNos_); 64 } 65 66 public: 67 typedef enum FrameSliceType { ACTURAL_SLICE, EXPECT_SLICE } FrameSliceType; 68 69 private: 70 std::deque<uint32_t> ipids_ = {}; 71 std::deque<uint64_t> dsts_ = {}; 72 std::deque<std::string> srcs_ = {}; 73 std::deque<uint32_t> vsyncIds_ = {}; 74 std::deque<uint64_t> callStackIds_ = {}; 75 std::deque<uint64_t> endTss_ = {}; 76 std::deque<uint64_t> durs_ = {}; 77 std::deque<uint8_t> types_ = {}; 78 std::deque<uint8_t> flags_ = {}; 79 std::deque<uint8_t> depths_ = {}; 80 std::deque<uint32_t> frameNos_ = {}; 81 const uint32_t invalidRow_ = 2; 82 static const uint32_t abnormalStartEndTimeState_ = 3; 83 const uint8_t flagValue_ = 2; 84 }; 85 86 class GPUSlice : public BatchCacheBase { 87 public: 88 size_t AppendNew(uint32_t frameRow, uint64_t dur); 89 const std::deque<uint32_t>& FrameRows() const; 90 const std::deque<uint64_t>& Durs() const; 91 size_t Size() const; ClearExportedData()92 void ClearExportedData() override 93 { 94 EraseElements(frameRows_, durs_); 95 } 96 97 private: 98 std::deque<uint32_t> frameRows_ = {}; 99 std::deque<uint64_t> durs_ = {}; 100 }; 101 102 class FrameMaps : public CacheBase { 103 public: 104 size_t AppendNew(FrameSlice* frameSlice, uint64_t src, uint64_t dst); 105 const std::deque<uint64_t>& SrcIndexs() const; 106 const std::deque<uint64_t>& DstIndexs() const; 107 108 private: 109 std::deque<uint64_t> srcs_ = {}; 110 std::deque<uint64_t> dsts_ = {}; 111 }; 112 113 } // namespace TraceStdtype 114 } // namespace SysTuning 115 #endif // RENDER_SERVICE_STDTYPE_H 116