• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 JANK_FRAME_MONITOR_H
17 #define JANK_FRAME_MONITOR_H
18 
19 #include <map>
20 #include <mutex>
21 #include "perf_constants.h"
22 #include "perf_model.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 
27 class JankFrameMonitor : public IFrameCallback {
28 public:
29     static JankFrameMonitor& GetInstance();
30     JankFrameMonitor();
31     ~JankFrameMonitor();
32 
33     // outer interface for app frame observer
34     void RegisterFrameCallback(IFrameCallback* cb);
35     void UnregisterFrameCallback(IFrameCallback* cb);
36     void OnFrameEnd(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName);
37     void OnVsyncEvent(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName);
38 
39     // inner interface for app frame observer
40     void ProcessJank(int64_t vsyncTime, double jank, const std::string& windowName);
41     void JankFrameStatsRecord(double jank);
42 
43     // stats app jank frame
44     void InitJankFrameRecord();
45     void ClearJankFrameRecord();
46     void SetJankFrameRecordBeginTime(int64_t val);
47     int64_t GetJankFrameRecordBeginTime();
48     int32_t GetJankFrameTotalCount();
49     const std::vector<uint16_t>& GetJankFrameRecord();
50     bool JankFrameRecordIsEmpty();
51 
52 private:
53     uint32_t GetJankLimit(double jank);
54 private:
55     mutable std::mutex mMutex;
56     std::vector<IFrameCallback*> frameCallbacks;
57     std::vector<uint16_t> jankFrameRecord;
58     int64_t jankFrameRecordBeginTime {0};
59     int32_t jankFrameTotalCount {0};
60 };
61 
62 }
63 }
64 
65 #endif // JANK_FRAME_MONITOR_H