1 /* 2 * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_BASE_JANK_FRAME_REPORT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_JANK_FRAME_REPORT_H 18 19 #include "base/utils/macros.h" 20 21 #include <string> 22 #include <vector> 23 24 namespace OHOS::Ace { 25 using JankFrameFlag = uint32_t; 26 27 inline constexpr JankFrameFlag JANK_IDLE = 0; 28 inline constexpr JankFrameFlag JANK_RUNNING_SCROLL = 1; 29 inline constexpr JankFrameFlag JANK_RUNNING_ANIMATOR = 1 << 1; 30 inline constexpr JankFrameFlag JANK_RUNNING_SWIPER = 1 << 2; 31 32 class ACE_FORCE_EXPORT JankFrameReport { 33 public: 34 static JankFrameReport& GetInstance(); 35 JankFrameReport(); 36 ~JankFrameReport() = default; 37 void JankFrameRecord(int64_t timeStampNanos, const std::string& windowName); 38 void SetFrameJankFlag(JankFrameFlag flag); 39 void ClearFrameJankFlag(JankFrameFlag flag); 40 void StartRecord(const std::string& pageUrl); 41 void FlushRecord(); 42 void RecordFrameUpdate(); 43 void ReportJSAnimation(); 44 void JsAnimationToRsRecord(); 45 void RecordAnimateEnd(); 46 47 private: 48 void ClearFrameJankRecord(); 49 void ResetFrameJankClock(); 50 void RecordPreviousEnd(); 51 void RecordJankStatus(double jank); 52 53 std::vector<uint16_t> frameJankRecord_; 54 int32_t jankFrameCount_; 55 int32_t prevFrameUpdateCount_; 56 int32_t currentFrameUpdateCount_; 57 JankFrameFlag recordStatus_; 58 int64_t startTime_; 59 int64_t prevEndTimeStamp_; 60 int64_t refreshPeriod_; 61 std::string pageUrl_; 62 bool needReport_; 63 bool hasJsAnimation_; 64 int64_t animatorEndTime_; 65 double jsAnimationDelayJank_; 66 }; 67 } // namespace OHOS::Ace 68 69 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_JANK_FRAME_REPORT_H 70