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 void JankFrameRecord(int64_t timeStampNanos); 35 static void SetFrameJankFlag(JankFrameFlag flag); 36 static void ClearFrameJankFlag(JankFrameFlag flag); 37 static void StartRecord(const std::string& pageUrl); 38 static void FlushRecord(); 39 static void RecordFrameUpdate(); 40 static void ReportJSAnimation(); 41 static void JsAnimationToRsRecord(); 42 43 private: 44 static void ClearFrameJankRecord(); 45 static void ResetFrameJankClock(); 46 static void RecordPreviousEnd(); 47 static void RecordJankStatus(double jank); 48 49 static std::vector<uint16_t> frameJankRecord_; 50 static int32_t jankFrameCount_; 51 static int32_t prevFrameUpdateCount_; 52 static int32_t currentFrameUpdateCount_; 53 static JankFrameFlag recordStatus_; 54 static int64_t startTime_; 55 static int64_t prevEndTimeStamp_; 56 static int64_t refreshPeriod_; 57 static std::string pageUrl_; 58 static bool needReport_; 59 static bool hasJsAnimation_; 60 static int64_t animatorEndTime_; 61 static double jsAnimationDelayJank_; 62 }; 63 } // namespace OHOS::Ace 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_JANK_FRAME_REPORT_H 66