• 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 ARKUI_PERF_MONITOR_H
17 #define ARKUI_PERF_MONITOR_H
18 
19 #include <mutex>
20 #include <string>
21 #include <map>
22 #include <vector>
23 #include <algorithm>
24 #include <memory>
25 
26 #include "base/utils/macros.h"
27 #include "base/utils/aps_monitor.h"
28 #include "core/common/window_animation_config.h"
29 
30 namespace OHOS::Ace {
31 constexpr int32_t US_TO_MS = 1000;
32 constexpr int32_t NS_TO_MS = 1000000;
33 constexpr int32_t NS_TO_S = 1000000000;
34 
35 enum PerfActionType {
36     UNKNOWN_ACTION = -1,
37     LAST_DOWN = 0,
38     LAST_UP = 1,
39     FIRST_MOVE = 2
40 };
41 
42 enum PerfSourceType {
43     UNKNOWN_SOURCE = -1,
44     PERF_TOUCH_EVENT = 0,
45     PERF_MOUSE_EVENT = 1,
46     PERF_TOUCH_PAD = 2,
47     PERF_JOY_STICK = 3,
48     PERF_KEY_EVENT = 4
49 };
50 
51 std::string ParsePageUrl(const std::string& pagePath);
52 
53 class ACE_FORCE_EXPORT PerfMonitor {
54 public:
55     void Start(const std::string& sceneId, PerfActionType type, const std::string& note);
56     void End(const std::string& sceneId, bool isRsRender);
57     void StartCommercial(const std::string& sceneId, PerfActionType type, const std::string& note);
58     void EndCommercial(const std::string& sceneId, bool isRsRender);
59     void RecordInputEvent(PerfActionType type, PerfSourceType sourceType, int64_t time);
60     int64_t GetInputTime(const std::string& sceneId, PerfActionType type, const std::string& note);
61     void SetFrameTime(int64_t vsyncTime, int64_t duration, double jank, const std::string& windowName);
62     void SetSubHealthInfo(const std::string& info, const std::string& reason, const int32_t duration);
63     void ReportJankFrameApp(double jank);
64     void SetPageUrl(const std::string& pageUrl);
65     std::string GetPageUrl();
66     void SetPageName(const std::string& pageName);
67     std::string GetPageName();
68     void SetAppForeground(bool isShow);
69     void SetAppStartStatus();
70     static PerfMonitor* GetPerfMonitor();
71     static PerfMonitor* pMonitor;
72     static std::once_flag initFlag;
73     static void InitInstance();
74     void SetApsMonitor(const std::shared_ptr<ApsMonitor>& apsMonitor);
75     void ReportPageShowMsg(const std::string& pageUrl, const std::string& bundleName,
76                            const std::string& pageName);
77     void RecordWindowRectResize(OHOS::Ace::WindowSizeChangeReason reason,
78                            const std::string& bundleName);
79     void NotifyAppJankStatsBegin();
80     void NotifyAppJankStatsEnd();
81     void SetApplicationInfo();
82 private:
83     std::shared_ptr<ApsMonitor> apsMonitor_ = nullptr;
84 };
85 } // namespace OHOS::Ace
86 #endif // ARKUI_PERF_MONITOR_H
87