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 FRAME_FILTER_H 17 #define FRAME_FILTER_H 18 #include <vector> 19 #include "common_types.h" 20 #include "double_map.h" 21 #include "filter_base.h" 22 #include "clock_filter_ex.h" 23 #include "trace_data_cache.h" 24 #include "trace_streamer_filters.h" 25 namespace SysTuning { 26 namespace TraceStreamer { 27 class FrameFilter : private FilterBase { 28 public: 29 FrameFilter(TraceDataCache *dataCache, const TraceStreamerFilters *filter); 30 ~FrameFilter() override; 31 void BeginVsyncEvent(const BytraceLine &line, 32 uint64_t expectStart, 33 uint64_t expectEnd, 34 uint32_t vsyncId, 35 uint32_t callStackSliceId); 36 bool MarkRSOnDoCompositionEvent(uint32_t itid); 37 bool BeginRSTransactionData(uint32_t currentThreadId, 38 uint32_t frameNum, 39 uint32_t mainThreadId, 40 uint64_t timeId = INVALID_UINT64); 41 typedef struct { 42 uint32_t sourceItid; 43 uint32_t frameNum; 44 } FrameMap; 45 bool BeginProcessCommandUni(uint32_t itid, const std::vector<FrameMap> &frame, uint32_t sliceIndex); 46 bool EndVsyncEvent(uint64_t ts, uint32_t itid); 47 bool StartFrameQueue(uint64_t ts, uint32_t itid); 48 bool EndFrameQueue(uint64_t ts, uint32_t itid); 49 bool UpdateVsyncId(const BytraceLine &line, uint32_t vsyncId, uint64_t timeId); 50 void BeginParallelTraceEvent(const BytraceLine &line, uint32_t callStackSliceId); 51 void Clear(); 52 void SetTraceType(TraceFileType traceType); UpdateReadySize()53 void UpdateReadySize() 54 { 55 UpdateFrameSliceReadySize(); 56 } 57 58 private: 59 bool UpdateFrameSliceReadySize(); 60 void SetMinFrameSliceRow(uint64_t &minFrameSliceRowToBeUpdated); 61 62 private: 63 class FrameSlice { 64 public: FrameSlice()65 FrameSlice() {} 66 uint64_t startTs_ = INVALID_UINT64; 67 // @deprecated it will be deleted later 68 uint64_t expectedStartTs_ = INVALID_UINT64; 69 // if a frame experience video lag, is depend on if the real end ts is later then the expected ts, rather then 70 // the dur. noted at 2023/4/6 71 uint64_t expectedEndTs_ = INVALID_UINT64; 72 // @deprecated it will be deleted later 73 uint64_t expectedDur_ = INVALID_UINT64; 74 uint64_t endTs_ = INVALID_UINT64; 75 bool gpuEnd_ = true; 76 TraceStdtype::FrameSlice::FrameSliceType frameType_ = TraceStdtype::FrameSlice::ACTURAL_SLICE; 77 uint32_t vsyncId_ = INVALID_UINT32; 78 uint64_t frameQueueStartTs_ = INVALID_UINT64; 79 bool vsyncEnd_ = false; 80 bool isRsMainThread_ = false; 81 uint32_t frameNum_ = INVALID_UINT32; 82 uint64_t callStackSliceId_ = INVALID_UINT64; 83 uint64_t frameSliceRow_ = INVALID_UINT64; 84 uint64_t frameExpectedSliceRow_ = INVALID_UINT64; 85 std::vector<uint64_t> sourceSlice_ = {}; 86 std::vector<uint64_t> sourceExpectedSlice_ = {}; 87 uint64_t dstFrameSliceId_ = INVALID_UINT64; 88 uint64_t dstExpectedFrameSliceId_ = INVALID_UINT64; 89 bool isEnd_ = false; 90 uint64_t nowId_ = INVALID_UINT64; 91 }; 92 std::unordered_map<uint32_t /* tid */, std::vector<std::shared_ptr<FrameSlice>>> vsyncRenderSlice_ = {}; 93 std::unordered_map<uint32_t /* tid */, std::unordered_map<uint32_t /* frameNum */, std::shared_ptr<FrameSlice>>> 94 dstRenderSlice_ = {}; 95 TraceFileType traceType_ = TRACE_FILETYPE_H_TRACE; 96 }; 97 } // namespace TraceStreamer 98 } // namespace SysTuning 99 #endif 100