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 avaliableMem = 0; 45 uint64_t freeMem = 0; 46 uint64_t totalMem = 0; 47 }; 48 49 struct AppLaunchInfo : public BundleInfo, public ProcessInfo { 50 int32_t startType = 0; 51 uint64_t iconInputTime = 0; 52 uint64_t animationFinishTime = 0; 53 uint64_t extendTime = 0; 54 }; 55 56 struct ScrollJankInfo : public BundleInfo, public ProcessInfo, public AbilityInfo { 57 uint64_t beginTime = 0; 58 uint64_t duration = 0; 59 int32_t totalAppFrames = 0; 60 int32_t totalAppMissedFrames = 0; 61 uint64_t maxAppFrametime = 0; 62 int32_t maxAppSeqFrames = 0; 63 int32_t totalRenderFrames = 0; 64 int32_t totalRenderMissedFrames = 0; 65 uint64_t maxRenderFrametime = 0; 66 int32_t maxRenderSeqFrames = 0; 67 std::vector<std::string> externalLog; 68 bool logOverLimit = false; 69 }; 70 71 struct TimeInfo { 72 uint64_t time = 0; 73 uint64_t beginTime = 0; 74 uint64_t endTime = 0; 75 }; 76 77 struct ThreadInfo { 78 std::string name; 79 int32_t tid = 0; 80 double usage = 0; 81 friend std::ostream &operator<<(std::ostream &os, const ThreadInfo &p) 82 { 83 os << "{\"name\":\"" << p.name << "\",\"tid\":" << p.tid << ",\"usage\":" << p.usage << "}"; 84 return os; 85 } 86 }; 87 88 struct LogInfo { 89 std::string file; LogInfoLogInfo90 LogInfo(std::string file_) 91 { 92 file = file_; 93 } 94 friend std::ostream &operator<<(std::ostream &os, const LogInfo &f) 95 { 96 os << "\"" << f.file << "\""; 97 return os; 98 } 99 }; 100 101 struct CpuUsageHighInfo : public BundleInfo, public TimeInfo { 102 bool isForeground = false; 103 uint64_t usage = 0; 104 std::vector<ThreadInfo> threads; 105 std::vector<LogInfo> externalLog; 106 bool logOverLimit = false; 107 }; 108 109 struct UsageStatInfo { 110 std::vector<uint64_t> fgUsages = std::vector<uint64_t>(24); // 24 : statistics per hour, fg : foreground 111 std::vector<uint64_t> bgUsages = std::vector<uint64_t>(24); // 24 : statistics per hour, bg : background 112 }; 113 114 struct BatteryUsageInfo : public BundleInfo, public TimeInfo { 115 UsageStatInfo usage; 116 UsageStatInfo cpuEnergy; 117 UsageStatInfo gpuEnergy; 118 UsageStatInfo ddrEnergy; 119 UsageStatInfo displayEnergy; 120 UsageStatInfo audioEnergy; 121 UsageStatInfo modemEnergy; 122 UsageStatInfo romEnergy; 123 UsageStatInfo wifiEnergy; 124 UsageStatInfo othersEnergy; 125 }; 126 127 struct ResourceOverLimitInfo : public BundleInfo, public MemoryInfo { 128 int32_t pid = 0; 129 int32_t uid = 0; 130 std::string resourceType; 131 uint64_t limitSize = 0; 132 uint64_t liveobjectSize = 0; 133 uint32_t fdNum = 0; 134 std::string topFdType; 135 uint32_t topFdNum = 0; 136 uint32_t threadNum = 0; 137 std::vector<std::string> logPath; 138 }; 139 140 int PostEvent(const AppLaunchInfo& event); 141 int PostEvent(const ScrollJankInfo& event); 142 int PostEvent(const ResourceOverLimitInfo& event); 143 int PostEvent(const CpuUsageHighInfo& event); 144 int PostEvent(const BatteryUsageInfo& event); 145 }; 146 } // namespace HiviewDFX 147 } // namespace OHOS 148 149 #endif // HIVIEW_BASE_APP_EVENT_HANDLER_H