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 #ifndef RENDER_SERVICE_CLIENT_CORE_JANK_DETECTOR_RS_JANK_DETECTOR_H 16 #define RENDER_SERVICE_CLIENT_CORE_JANK_DETECTOR_RS_JANK_DETECTOR_H 17 18 #include <mutex> 19 #include <vector> 20 21 namespace OHOS { 22 namespace Rosen { 23 class RSJankDetector final { 24 public: 25 RSJankDetector() = default; ~RSJankDetector()26 ~RSJankDetector() {} 27 28 uint64_t GetSysTimeNs(); 29 void SetRefreshPeriod(uint64_t refreshPeriod); 30 uint64_t GetRefreshPeriod() const; 31 void UpdateUiDrawFrameMsg(uint64_t startTimeStamp, uint64_t endTimeStamp, const std::string& abilityName); 32 void CalculateSkippedFrame(uint64_t renderStartTimeStamp, uint64_t renderEndTimeStamp); 33 34 private: 35 struct UiDrawFrameMsg { 36 uint64_t startTimeStamp = 0; 37 uint64_t endTimeStamp = 0; 38 std::string abilityName; 39 }; 40 41 const int JANK_SKIPPED_THRESHOLD = 5; 42 const uint64_t NO_DRAW_THRESHOLD = 5000000000; // 5s 43 uint64_t refreshPeriod_ = 16666667; 44 std::vector<UiDrawFrameMsg> uiDrawFrames_; 45 }; 46 } // namespace Rosen 47 } // namespace OHOS 48 49 #endif // RENDER_SERVICE_CLIENT_CORE_JANK_DETECTOR_RS_JANK_DETECTOR_H 50