• 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 XPERF_MODEL_H
17 #define XPERF_MODEL_H
18 
19 #include <map>
20 #include <string>
21 #include "perf_constants.h"
22 #include "iremote_broker.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 enum PerfActionType {
27     UNKNOWN_ACTION = -1,
28     LAST_DOWN = 0,
29     LAST_UP = 1,
30     FIRST_MOVE = 2
31 };
32 
33 enum PerfSourceType {
34     UNKNOWN_SOURCE = -1,
35     PERF_TOUCH_EVENT = 0,
36     PERF_MOUSE_EVENT = 1,
37     PERF_TOUCH_PAD = 2,
38     PERF_JOY_STICK = 3,
39     PERF_KEY_EVENT = 4
40 };
41 
42 enum PerfEventType {
43     UNKNOWN_EVENT = -1,
44     EVENT_RESPONSE = 0,
45     EVENT_COMPLETE = 1,
46     EVENT_JANK_FRAME = 2
47 };
48 
49 struct AceAppInfo {
50     int32_t pid {-1};
51     int32_t versionCode {0};
52     std::string versionName {""};
53     std::string bundleName {""};
54     std::string processName {""};
55     std::string abilityName {""};
56 };
57 
58 struct SubHealthInfo {
59     std::string info {""};
60     std::string subHealthReason {""};
61     int32_t subHealthTime {0};
62 };
63 
64 struct BaseInfo {
65     int32_t pid {-1};
66     int32_t versionCode {0};
67     std::string versionName {""};
68     std::string bundleName {""};
69     std::string processName {""};
70     std::string abilityName {""};
71     std::string pageUrl {""};
72     std::string pageName {""};
73     std::string note {""};
74     SubHealthInfo subHealthInfo;
75 };
76 
77 struct DataBase {
78     std::string sceneId {""};
79     int32_t maxSuccessiveFrames {0};
80     int32_t totalMissed {0};
81     int32_t totalFrames {0};
82     int64_t inputTime {0};
83     int64_t beginVsyncTime {0};
84     int64_t endVsyncTime {0};
85     int64_t maxFrameTime {0};
86     int64_t maxFrameTimeSinceStart {0};
87     int64_t maxHitchTime {0};
88     int64_t maxHitchTimeSinceStart {0};
89     bool needReportRs {false};
90     bool isDisplayAnimator {false};
91     PerfSourceType sourceType {UNKNOWN_SOURCE};
92     PerfActionType actionType {UNKNOWN_ACTION};
93     PerfEventType eventType {UNKNOWN_EVENT};
94     BaseInfo baseInfo;
95 };
96 
97 struct JankInfo {
98     int64_t skippedFrameTime {0};
99     std::string windowName {""};
100     std::string sceneId {""};
101     uint64_t sceneTag {0};
102     int64_t realSkippedFrameTime {0};
103     int64_t vsyncTime {0};
104     BaseInfo baseInfo;
105 };
106 
107 struct ImageLoadInfo {
108     int64_t id {0}; //无障碍id
109     std::string imageType;
110     int width {0};
111     int height {0};
112     uint64_t loadStartTime{0};
113     uint64_t loadEndTime{0};
114     int loadState {0}; //图片load状态 0-失败/1-成功
115 };
116 
117 struct ImageLoadStat {
118     uint64_t startTime{0};
119     uint64_t endTime{0};
120     int totalNum {0};
121     int failedNum {0};
122     int64_t totalSize {0};
123     int64_t failedSize {0};
124     std::string typeDetails;
125 };
126 
127 struct SurfaceInfo {
128     int64_t uniqueId{0};
129     std::string surfaceName;
130     std::string componentName;
131     std::string bundleName;
132     int32_t pid{0};
133 };
134 
135 class AnimatorRecord {
136 public:
137     void InitRecord(const std::string& sId, PerfActionType aType, PerfSourceType sType, const std::string& nt,
138         int64_t time);
139     void RecordFrame(int64_t vsyncTime, int64_t duration, int32_t skippedFrames);
140     void Report(const std::string& sceneId, int64_t vsyncTime, bool isRsRender);
141     bool IsTimeOut(int64_t nowTime);
142     bool IsFirstFrame();
143     bool IsDisplayAnimator(const std::string& sceneId);
144     void Reset();
145 public:
146     int64_t inputTime {0};
147     int64_t beginVsyncTime {0};
148     int64_t endVsyncTime {0};
149     int64_t maxFrameTime {0};
150     int64_t maxFrameTimeSinceStart {0};
151     int64_t maxHitchTime {0};
152     int64_t maxHitchTimeSinceStart {0};
153     int32_t maxSuccessiveFrames {0};
154     int32_t totalMissed {0};
155     int32_t totalFrames {0};
156     int32_t seqMissFrames {0};
157     bool isSuccessive {false};
158     bool isFirstFrame {false};
159     bool needReportRs {false};
160     bool isDisplayAnimator {false};
161     std::string sceneId {""};
162     PerfActionType actionType {UNKNOWN_ACTION};
163     PerfSourceType sourceType {UNKNOWN_SOURCE};
164     std::string note {""};
165 };
166 
167 enum SceneType {
168     APP_FOREGROUND = 0,
169     NON_EXPERIENCE_ANIMATOR,
170     NON_EXPERIENCE_WINDOW,
171     APP_START,
172     APP_RESPONSE,
173     APP_BACKGROUND,
174     PAGE_LOADING,
175     POWER_OFF,
176     ACCESSIBLE_FEATURE,
177     VIDEO_PLAYING
178 };
179 
180 class SceneRecord {
181 public:
182     virtual void StartRecord(const SceneType& sType);
183     virtual void StopRecord(const SceneType& sType);
184     virtual void StartRecord(const SceneType& sType, const std::string& sId);
185     virtual void StopRecord(const SceneType& sType, const std::string& sId);
186 public:
187     SceneType type{APP_FOREGROUND};
188     std::string sceneId;
189     bool status{false};
190     int64_t startTime{0};
191     int64_t duration{0};
192 };
193 
194 class NonExperienceAnimator : public SceneRecord {
195 public:
196     void StartRecord(const SceneType& sType, const std::string& sId) override;
197     void StopRecord(const SceneType& sType, const std::string& sId) override;
198 public:
199     bool IsNonExperienceWhiteList(const std::string& sceneId);
200 };
201 
202 class NonExperienceWindow : public NonExperienceAnimator {
203 public:
204     void StartRecord(const SceneType& sType, const std::string& sId);
205     void StopRecord(const SceneType& sType, const std::string& sId);
206     bool IsNonExperienceWhiteList(const std::string& windowName);
207 };
208 
209 class NonExperienceAppStart : public SceneRecord {
210 public:
211     void StartRecord(const SceneType& sType) override;
212     void StopRecord(const SceneType& sType) override;
213     bool IsInStartAppStatus();
214 };
215 
216 class NonExperiencePageLoading : public SceneRecord {
217 public:
218     void StartRecord(const SceneType& sType, const std::string& sId) override;
219     void StopRecord(const SceneType& sType) override;
220     bool IsNonExperienceWhiteList(const std::string& sceneId);
221 };
222 
223 class IFrameCallback : public IRemoteBroker {
224 public:
225     virtual void OnVsyncEvent(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName) = 0;
AsObject()226     virtual sptr<IRemoteObject> AsObject() { return nullptr;}
227 public:
228     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.HiviewDFX.IFrameCallback");
229 };
230 
231 class IAnimatorCallback : public IRemoteBroker {
232 public:
233     virtual void OnAnimatorStart(const std::string& sceneId, PerfActionType type, const std::string& note) = 0;
234     virtual void OnAnimatorStop(const std::string& sceneId, bool isRsRender) = 0;
AsObject()235     virtual sptr<IRemoteObject> AsObject() { return nullptr;}
236 public:
237     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.HiviewDFX.IAnimatorCallback");
238 };
239 
240 class ISceneCallback : public IRemoteBroker {
241 public:
242     virtual void OnSceneEvent(const SceneType& type, const bool status) = 0;
243     virtual void OnSceneEvent(const SceneType& type, const bool status, const std::string& sceneId) = 0;
AsObject()244     virtual sptr<IRemoteObject> AsObject() { return nullptr; }
245 public:
246     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.HiviewDFX.ISceneCallback");
247 };
248 } // namespace OHOS
249 } // namespace HiviewDFX
250 #endif // XPERF_MODEL_H
251