1 /* 2 * Copyright (c) 2022 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 UTILS_INCLUDE_SYNC_FENCE_TRACKER_H 17 #define UTILS_INCLUDE_SYNC_FENCE_TRACKER_H 18 19 #include <atomic> 20 #include <event_handler.h> 21 #include <queue> 22 #include "sync_fence.h" 23 24 namespace OHOS { 25 class SyncFenceTracker { 26 public: 27 explicit SyncFenceTracker(const std::string threadName); 28 29 SyncFenceTracker() = delete; 30 ~SyncFenceTracker() = default; 31 32 void TrackFence(const sptr<SyncFence>& fence, bool traceTag = true); 33 void SetBlurSize(int32_t blurSize); 34 void SetContainerNodeNum(int containerNodeNum); 35 36 private: 37 const uint32_t SYNC_TIME_OUT = 3000; 38 const int32_t GPU_SUBHEALTH_EVENT_LIMIT = 200; 39 const int32_t GPU_SUBHEALTH_EVENT_THRESHOLD = 12; 40 const uint32_t FRAME_QUEUE_SIZE_LIMIT = 4; 41 const int32_t FRAME_PERIOD = 1000; 42 const std::string threadName_; 43 bool isGpuFence_ = false; 44 bool isGpuEnable_ = false; 45 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ = nullptr; 46 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr; 47 std::atomic<uint32_t> fencesQueued_; 48 std::atomic<uint32_t> fencesSignaled_; 49 int32_t gpuSubhealthEventNum_ = 0; 50 int32_t gpuSubhealthEventDay_ = 0; 51 std::queue<int32_t> *frameStartTimes_ = new std::queue<int32_t>; 52 int processedNodeNum_ = 0; 53 void Loop(const sptr<SyncFence>& fence, bool traceTag); 54 int32_t WaitFence(const sptr<SyncFence>& fence); 55 bool CheckGpuSubhealthEventLimit(); 56 void ReportEventGpuSubhealth(int32_t duration); 57 inline void UpdateFrameQueue(int32_t startTime); 58 int32_t GetFrameRate(); 59 }; 60 } 61 #endif // UTILS_INCLUDE_SYNC_FENCE_TRACKER_H