1 /* 2 * Copyright (c) 2022 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 HIVIEWDFX_FREEZE_COMMON_H 17 #define HIVIEWDFX_FREEZE_COMMON_H 18 19 #include <list> 20 #include <memory> 21 #include <set> 22 #include <vector> 23 24 #include "rule_cluster.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 const std::string FREEZE_DETECTOR_PLUGIN_NAME = "FreezeDetector"; 29 const std::string FREEZE_DETECTOR_PLUGIN_VERSION = "1.0"; 30 class FreezeCommon { 31 public: 32 static constexpr const char* EVENT_PID = "PID"; 33 static constexpr const char* EVENT_TID = "TID"; 34 static constexpr const char* EVENT_UID = "UID"; 35 static constexpr const char* EVENT_PACKAGE_NAME = "PACKAGE_NAME"; 36 static constexpr const char* EVENT_PROCESS_NAME = "PROCESS_NAME"; 37 static constexpr const char* EVENT_MSG = "MSG"; 38 static constexpr const char* HITRACE_TIME = "HITRACE_TIME"; 39 static constexpr const char* SYSRQ_TIME = "SYSRQ_TIME"; 40 static constexpr const char* TERMINAL_THREAD_STACK = "TERMINAL_THREAD_STACK"; 41 static constexpr const char* TELEMETRY_ID = "TELEMETRY_ID"; 42 static constexpr const char* TRACE_NAME = "TRACE_NAME"; 43 static constexpr const char* PB_EVENTS[] = { 44 "UI_BLOCK_3S", "THREAD_BLOCK_3S", "BUSSNESS_THREAD_BLOCK_3S", "LIFECYCLE_HALF_TIMEOUT", 45 "LIFECYCLE_HALF_TIMEOUT_WARNING" 46 }; 47 static constexpr const char* EVENT_TRACE_ID = "HITRACE_ID"; 48 static constexpr const char* PROC_STATM = "PROC_STATM"; 49 static constexpr const char* HOST_RESOURCE_WARNING = "HOST_RESOURCE_WARNING"; 50 51 FreezeCommon(); 52 ~FreezeCommon(); 53 54 bool Init(); 55 bool IsFreezeEvent(const std::string& domain, const std::string& stringId) const; 56 bool IsApplicationEvent(const std::string& domain, const std::string& stringId) const; 57 bool IsSystemEvent(const std::string& domain, const std::string& stringId) const; 58 bool IsSysWarningEvent(const std::string& domain, const std::string& stringId) const; 59 std::set<std::string> GetPrincipalStringIds() const; 60 std::shared_ptr<FreezeRuleCluster> GetFreezeRuleCluster() const; 61 static void WriteTimeInfoToFd(int fd, const std::string& msg, bool isStart = true); 62 63 private: 64 std::shared_ptr<FreezeRuleCluster> freezeRuleCluster_; 65 bool IsAssignedEvent(const std::string& domain, const std::string& stringId, int freezeId) const; 66 }; 67 } // namespace HiviewDFX 68 } // namespace OHOS 69 #endif // HIVIEWDFX_FREEZE_COMMON_H