• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
46 private:
47     void ClearFrameJankRecord();
48     void ResetFrameJankClock();
49     void RecordPreviousEnd();
50     void RecordJankStatus(double jank);
51 
52     std::vector<uint16_t> frameJankRecord_;
53     int32_t jankFrameCount_;
54     int32_t prevFrameUpdateCount_;
55     int32_t currentFrameUpdateCount_;
56     JankFrameFlag recordStatus_;
57     int64_t startTime_;
58     int64_t prevEndTimeStamp_;
59     int64_t refreshPeriod_;
60     std::string pageUrl_;
61     bool needReport_;
62     bool hasJsAnimation_;
63     int64_t animatorEndTime_;
64     double jsAnimationDelayJank_;
65 };
66 } // namespace OHOS::Ace
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_JANK_FRAME_REPORT_H
69