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 const int MILLISECOND = 1000; 33 static const int SYSTEM_RESULT_ID = 1; 34 static const int APPLICATION_RESULT_ID = 0; 35 static const inline std::string COLON = ":"; 36 static const inline std::string EVENT_DOMAIN = "DOMAIN"; 37 static const inline std::string EVENT_STRINGID = "STRINGID"; 38 static const inline std::string EVENT_TIMESTAMP = "TIMESTAMP"; 39 static const inline std::string EVENT_PID = "PID"; 40 static const inline std::string EVENT_TID = "TID"; 41 static const inline std::string EVENT_UID = "UID"; 42 static const inline std::string EVENT_PACKAGE_NAME = "PACKAGE_NAME"; 43 static const inline std::string EVENT_PROCESS_NAME = "PROCESS_NAME"; 44 static const inline std::string EVENT_MSG = "MSG"; 45 static const inline std::string FORE_GROUND = "FOREGROUND"; 46 static const inline std::string HIREACE_TIME = "HITRACE_TIME"; 47 static const inline std::string SYSRQ_TIME = "SYSRQ_TIME"; 48 static const inline std::string SYSEVENT_PIPELINE = "SysEventPipeline"; 49 static const inline std::string DISPLAY_POWER_INFO = "DisplayPowerInfo:"; 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 IsBetaVersion() const; 58 bool IsSystemEvent(const std::string& domain, const std::string& stringId) const; 59 bool IsSysWarningEvent(const std::string& domain, const std::string& stringId) const; 60 bool IsSystemResult(const FreezeResult& result) const; 61 bool IsSysWarningResult(const FreezeResult& result) const; 62 bool IsApplicationResult(const FreezeResult& result) const; 63 std::set<std::string> GetPrincipalStringIds() const; GetFreezeRuleCluster()64 std::shared_ptr<FreezeRuleCluster> GetFreezeRuleCluster() const 65 { 66 return freezeRuleCluster_; 67 } 68 static void WriteStartInfoToFd(int fd, const std::string& msg); 69 static void WriteEndInfoToFd(int fd, const std::string& msg); 70 71 private: 72 std::shared_ptr<FreezeRuleCluster> freezeRuleCluster_; 73 bool IsAssignedEvent(const std::string& domain, const std::string& stringId, int freezeId) const; 74 }; 75 } // namespace HiviewDFX 76 } // namespace OHOS 77 #endif // HIVIEWDFX_FREEZE_COMMON_H