• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef HIVIEW_BASE_APP_EVENT_HANDLER_H
16 #define HIVIEW_BASE_APP_EVENT_HANDLER_H
17 
18 #include <cstdint>
19 #include <ostream>
20 #include <string>
21 #include <vector>
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 class AppEventHandler {
26 public:
27     struct BundleInfo {
28         std::string bundleName;
29         std::string bundleVersion;
30     };
31 
32     struct ProcessInfo {
33         std::string processName;
34     };
35 
36     struct AbilityInfo {
37         std::string abilityName;
38     };
39 
40     struct MemoryInfo {
41         uint64_t pss = 0;
42         uint64_t rss = 0;
43         uint64_t vss = 0;
44         uint64_t gpu = 0;
45         uint64_t ion = 0;
46         uint64_t avaliableMem = 0;
47         uint64_t freeMem = 0;
48         uint64_t totalMem = 0;
49     };
50 
51     struct AppLaunchInfo : public BundleInfo, public ProcessInfo {
52         int32_t startType = 0;
53         uint64_t iconInputTime = 0;
54         uint64_t animationFinishTime = 0;
55         uint64_t extendTime = 0;
56         uint64_t responseLatency = 0;
57         uint64_t launToStartAbilityDur = 0;
58         uint64_t startAbilityProcessStartDur = 0;
59         uint64_t processStartToAppAttachDur = 0;
60         uint64_t appAttachToAppForegroundDur = 0;
61         uint64_t startAbilityAppForegroundDur = 0;
62         uint64_t appForegrAbilityOnForegrDur = 0;
63         uint64_t abilityOnForegStartWindowDur = 0;
64     };
65 
66     struct ScrollJankInfo : public BundleInfo, public ProcessInfo, public AbilityInfo {
67         uint64_t beginTime = 0;
68         uint64_t duration = 0;
69         int32_t totalAppFrames = 0;
70         int32_t totalAppMissedFrames = 0;
71         uint64_t maxAppFrametime = 0;
72         int32_t maxAppSeqFrames = 0;
73         int32_t totalRenderFrames = 0;
74         int32_t totalRenderMissedFrames = 0;
75         uint64_t maxRenderFrametime = 0;
76         int32_t maxRenderSeqFrames = 0;
77         std::vector<std::string> externalLog;
78         bool logOverLimit = false;
79     };
80 
81     struct TimeInfo {
82         uint64_t time = 0;
83         uint64_t beginTime = 0;
84         uint64_t endTime = 0;
85     };
86 
87     struct ThreadInfo {
88         std::string name;
89         int32_t tid = 0;
90         double usage = 0;
91         friend std::ostream &operator<<(std::ostream &os, const ThreadInfo &p)
92         {
93             os << "{\"name\":\"" << p.name << "\",\"tid\":" << p.tid << ",\"usage\":" << p.usage << "}";
94             return os;
95         }
96     };
97 
98     struct LogInfo {
99         std::string file;
LogInfoLogInfo100         LogInfo(std::string file_)
101         {
102             file = file_;
103         }
104         friend std::ostream &operator<<(std::ostream &os, const LogInfo &f)
105         {
106             os << "\"" << f.file << "\"";
107             return os;
108         }
109     };
110 
111     struct CpuUsageHighInfo : public BundleInfo, public TimeInfo {
112         bool isForeground = false;
113         uint64_t usage = 0;
114         std::vector<ThreadInfo> threads;
115         std::vector<LogInfo> externalLog;
116         bool logOverLimit = false;
117         int32_t faultType = 0;
118     };
119 
120     struct UsageStatInfo {
121         std::vector<uint64_t> fgUsages = std::vector<uint64_t>(24); // 24 : statistics per hour, fg : foreground
122         std::vector<uint64_t> bgUsages = std::vector<uint64_t>(24); // 24 : statistics per hour, bg : background
123     };
124 
125     struct BatteryUsageInfo : public BundleInfo, public TimeInfo {
126         UsageStatInfo usage;
127         UsageStatInfo cpuEnergy;
128         UsageStatInfo gpuEnergy;
129         UsageStatInfo ddrEnergy;
130         UsageStatInfo displayEnergy;
131         UsageStatInfo audioEnergy;
132         UsageStatInfo modemEnergy;
133         UsageStatInfo romEnergy;
134         UsageStatInfo wifiEnergy;
135         UsageStatInfo othersEnergy;
136     };
137 
138     struct ResourceOverLimitInfo : public BundleInfo, public MemoryInfo {
139         int32_t pid = 0;
140         int32_t uid = 0;
141         std::string resourceType;
142         uint64_t limitSize = 0;
143         uint64_t liveobjectSize = 0;
144         uint32_t fdNum = 0;
145         std::string topFdType;
146         uint32_t topFdNum = 0;
147         uint32_t threadNum = 0;
148         std::string appRunningUniqueId;
149         std::vector<std::string> logPath;
150     };
151 
152     struct AppKilledInfo : public BundleInfo, public TimeInfo {
153         std::string reason;
154         int32_t uid = 0;
155         bool isForeground = false;
156     };
157 
158     int PostEvent(const AppLaunchInfo& event);
159     int PostEvent(const ScrollJankInfo& event);
160     int PostEvent(const ResourceOverLimitInfo& event);
161     int PostEvent(const CpuUsageHighInfo& event);
162     int PostEvent(const BatteryUsageInfo& event);
163     int PostEvent(const AppKilledInfo& event);
164     bool IsAppListenedEvent(int32_t uid, const std::string& eventName);
165 };
166 } // namespace HiviewDFX
167 } // namespace OHOS
168 #endif // HIVIEW_BASE_APP_EVENT_HANDLER_H
169