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 #include "running_status_log_util.h" 17 18 #include "running_status_logger.h" 19 20 namespace OHOS { 21 namespace HiviewDFX { 22 namespace { 23 constexpr char LOG_DETAIL_CONCAT[] = " "; 24 constexpr char RULE_ITEM_CONCAT[] = ","; 25 } 26 LogTooManyQueryRules(const std::vector<SysEventQueryRule> & rules)27void RunningStatusLogUtil::LogTooManyQueryRules(const std::vector<SysEventQueryRule>& rules) 28 { 29 std::string info { "TOOMANYQUERYRULES " }; 30 info.append(std::to_string(rules.size())).append(LOG_DETAIL_CONCAT); 31 info.append("RULES=["); 32 for (auto& rule : rules) { 33 info.append("{"); 34 info.append(rule.domain).append(RULE_ITEM_CONCAT); 35 if (!rule.eventList.empty()) { 36 info.append("["); 37 for (auto& eventName : rule.eventList) { 38 info.append(eventName).append(RULE_ITEM_CONCAT); 39 } 40 info.erase(info.end() - 1); 41 info.append("]").append(RULE_ITEM_CONCAT); 42 } 43 info.append(std::to_string(rule.ruleType)); 44 info.append("}").append(RULE_ITEM_CONCAT); 45 } 46 info.erase(info.end() - 1); 47 info.append("]"); 48 LogDetail(info); 49 } 50 LogTooManyWatchRules(const std::vector<SysEventRule> & rules)51void RunningStatusLogUtil::LogTooManyWatchRules(const std::vector<SysEventRule>& rules) 52 { 53 std::string info { "TOOMANYWATCHRULES " }; 54 info.append(std::to_string(rules.size())).append(LOG_DETAIL_CONCAT); 55 info.append("RULES=["); 56 for (auto& rule : rules) { 57 info.append("{"); 58 info.append(rule.domain).append(RULE_ITEM_CONCAT); 59 info.append(rule.eventName).append(RULE_ITEM_CONCAT); 60 if (!rule.tag.empty()) { 61 info.append(rule.tag).append(RULE_ITEM_CONCAT); 62 } 63 info.append(std::to_string(rule.ruleType)); 64 info.append("}").append(RULE_ITEM_CONCAT); 65 } 66 info.erase(info.end() - 1); 67 info.append("]"); 68 LogDetail(info); 69 } 70 LogTooManyWatchers(const int limit)71void RunningStatusLogUtil::LogTooManyWatchers(const int limit) 72 { 73 std::string info { "TOOMANYWATCHERS COUNT > " }; 74 info.append(std::to_string(limit)); 75 LogDetail(info); 76 } 77 LogTooManyEvents(const int limit)78void RunningStatusLogUtil::LogTooManyEvents(const int limit) 79 { 80 std::string info{"TOOMANYEVENTS COUNT > "}; 81 info.append(std::to_string(limit)); 82 LogDetail(info); 83 } 84 LogDetail(const std::string & detail)85void RunningStatusLogUtil::LogDetail(const std::string& detail) 86 { 87 std::string info = RunningStatusLogger::GetInstance().FormatTimeStamp(); 88 info.append(LOG_DETAIL_CONCAT).append(detail); 89 RunningStatusLogger::GetInstance().Log(info); 90 } 91 } // namespace HiviewDFX 92 } // namespace OHOS 93