• 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 SCENE_MONITOR_H
17 #define SCENE_MONITOR_H
18 
19 #include <map>
20 #include <mutex>
21 #include <vector>
22 #include "animator_monitor.h"
23 #include "perf_constants.h"
24 #include "perf_model.h"
25 #include "iremote_broker.h"
26 
27 #include "transaction/rs_render_service_client.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 
32 class SceneManager {
33 public:
34     void OnSceneStart(const SceneType& type);
35     void OnSceneStop(const SceneType& type);
36     void OnSceneStart(const SceneType& type, const std::string& sceneId);
37     void OnSceneStop(const SceneType& type, const std::string& sceneId);
38     SceneRecord* GetRecordByType(const SceneType& type);
39     uint64_t GetSceneTag();
40     uint64_t GetSceneTagByType(const SceneType& type);
41 private:
42     mutable std::mutex mMutex;
43     std::map<SceneType, SceneRecord*> sceneBoard;
44 };
45 
46 class SceneMonitor : public IAnimatorCallback, public ISceneCallback {
47 public:
48     static SceneMonitor& GetInstance();
49     SceneMonitor();
50     ~SceneMonitor();
51     void RegisterSceneCallback(ISceneCallback* cb);
52     void UnregisterSceneCallback(ISceneCallback* cb);
53     void OnSceneEvent(const SceneType& type, bool status) override;
54     void OnSceneEvent(const SceneType& type, bool status, const std::string& sceneId) override;
55     void OnSceneChanged(const SceneType& type, bool status);
56     void OnSceneChanged(const SceneType& type, bool status, const std::string& sceneId);
57     void OnAnimatorStart(const std::string& sceneId, PerfActionType type, const std::string& note) override;
58     void OnAnimatorStop(const std::string& sceneId, bool isRsRender) override;
59 
60     // outer interface for scene-info
61     void SetAppInfo(AceAppInfo& aceAppInfo);
62     void SetPageUrl(const std::string& pageUrl);
63     void SetPageName(const std::string& pageName);
64     void SetCurrentSceneId(const std::string& sceneId);
65 
66     // outer interface when scene-change
67     void SetAppForeground(bool isShow);
68     void SetAppStartStatus();
69 
70     // inner interface when scene-change
71     void SetAppGCStatus(const std::string& sceneId, int64_t value);
72     void SingleFrameSceneStop(const std::string& sceneId);
73 
74     // inner interface get scene-info
75     BaseInfo GetBaseInfo();
76     std::string GetPageUrl();
77     std::string GetPageName();
78     int32_t GetPid();
79     std::string GetCurrentSceneId();
80 
81     // innner interface when scene-change
82     bool IsScrollJank(const std::string& sceneId);
83     uint64_t GetNonexpFilterTag();
84 
85     // stats jank frame for app
86     void NotifyAppJankStatsBegin();
87     void NotifyAppJankStatsEnd();
88     void NotifyAppJankStatsReport(int64_t duration);
89     void NotifyScbJankStatsBegin(const std::string& sceneId);
90     void NotifyScbJankStatsEnd(const std::string& sceneId);
91     void SetJankFrameRecord(OHOS::Rosen::AppInfo& appInfo, int64_t startTime, int64_t endTime);
92     bool GetIsStats();
93     void SetStats(bool status);
94 
95     // inner interface for response time out
96     bool IsExceptResponseTime(int64_t time, const std::string& sceneId);
97 
98     // inner interface when non-experience scene
99     void SetVsyncLazyMode(uint64_t sceneTag);
100 
101     void SetSubHealthInfo(const SubHealthInfo& info);
102     void FlushSubHealthInfo();
103 
104 private:
105     void NotifyRsJankStatsBegin();
106     void NotifyRsJankStatsEnd(int64_t endTime);
107 private:
108     BaseInfo baseInfo;
109     std::string currentSceneId {""};
110     bool isStats {false};
111     mutable std::mutex mMutex;
112     SceneManager mNonexpManager;
113     std::vector<ISceneCallback*> sceneCallbacks;
114 
115     SubHealthInfo subHealthInfo;
116     bool isSubHealthScene = false;
117 };
118 
119 }
120 }
121 
122 #endif // SCENE_MONITOR_H