!53 update freeze_rules.xm & retPath, and add AddEventJson for freeze_detector

Merge pull request !53 from yantongguang/master
This commit is contained in:
openharmony_ci 2022-01-10 07:13:44 +00:00 committed by Gitee
commit 207e89e96d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 29 additions and 16 deletions

View File

@ -50,6 +50,23 @@ EventJsonParser::EventJsonParser(const std::string &path) : jsonRootValid(false)
EventJsonParser::~EventJsonParser() {}
bool EventJsonParser::AddEventJson(std::shared_ptr<SysEvent> &event) const
{
// convert JsonValue to the correct order by event->jsonExtraInfo_
std::string jsonStr = event->jsonExtraInfo_;
cJSON *cJsonArr = cJSON_Parse(jsonStr.c_str());
if (cJsonArr == NULL) {
return false;
}
// FreezeDetector needs to add
cJSON_AddStringToObject(cJsonArr, EventStore::EventCol::INFO.c_str(), "");
jsonStr = cJSON_PrintUnformatted(cJsonArr);
cJSON_Delete(cJsonArr);
event->jsonExtraInfo_ = jsonStr;
return true;
}
bool EventJsonParser::HandleEventJson(std::shared_ptr<SysEvent> &event) const
{
Json::Value eventJson;

View File

@ -29,6 +29,7 @@ public:
EventJsonParser(const std::string &path);
~EventJsonParser();
bool AddEventJson(std::shared_ptr<SysEvent> &event) const;
bool HandleEventJson(std::shared_ptr<SysEvent> &event) const;
bool CheckBaseInfo(const Json::Value &baseJson, Json::Value &eventJson) const;
bool CheckExtendInfo(const std::string &name, const Json::Value &sysEvent, const Json::Value &eventJson) const;
@ -40,4 +41,4 @@ private:
}; // SysEventDbMgr
} // namespace HiviewDFX
} // namespace OHOS
#endif
#endif

View File

@ -95,14 +95,8 @@ bool SysEventService::OnEvent(std::shared_ptr<Event>& event)
return false;
}
if (!sysEventParser_->HandleEventJson(sysEvent)) {
HIVIEW_LOGE("HandleEventJson fail");
sysEventStat_->AccumulateEvent(sysEvent->domain_, sysEvent->eventName_, false);
}
else {
sysEventStat_->AccumulateEvent(sysEvent->domain_, sysEvent->eventName_);
}
HIVIEW_LOGI("SysEvent Json String is %{}s.", sysEvent->jsonExtraInfo_.c_str());
sysEventParser_->AddEventJson(sysEvent);
sysEventStat_->AccumulateEvent(sysEvent->domain_, sysEvent->eventName_);
SysEventServiceAdapter::OnSysEvent(sysEvent);
sysEventDbMgr_->SaveToStore(sysEvent);

View File

@ -13,9 +13,9 @@
-->
<freeze version="1" >
<rules resolver="SysResolver">
<rule id="1" window="120" domain="KEY_PRESS" stringid="LONG_PRESS"> <!-- LONG_PRESS -->
<rule id="1" window="120" domain="KERNEL_VENDOR" stringid="LONG_PRESS"> <!-- LONG_PRESS -->
<links type="watchpoint">
<event domain="HUNGTASK" stringid="HUNGTASK"> <!-- HUNGTASK -->
<event domain="KERNEL_VENDOR" stringid="HUNGTASK"> <!-- HUNGTASK -->
<result code="1" scope="sys"/>
</event>
</links>

View File

@ -34,7 +34,8 @@ const std::vector<std::pair<std::string, std::string>> Vendor::applicationPairs_
};
const std::vector<std::pair<std::string, std::string>> Vendor::systemPairs_ = {
{"HUNGTASK", "HUNGTASK"},
{"KERNEL_VENDOR", "HUNGTASK"},
{"KERNEL_VENDOR", "LONG_PRESS"},
};
bool Vendor::IsFreezeEvent(const std::string& domain, const std::string& stringId) const
@ -204,7 +205,7 @@ std::string Vendor::MergeEventLog(
logName = APPFREEZE + HYPHEN + packageName + HYPHEN + std::to_string(uid) + HYPHEN + timestamp + POSTFIX;
}
else {
retPath = FAULT_LOGGER_PATH + SYSFREEZE + HYPHEN + packageName + HYPHEN + std::to_string(uid) + HYPHEN + timestamp;
retPath = FAULT_LOGGER_PATH + APPFREEZE + HYPHEN + packageName + HYPHEN + std::to_string(uid) + HYPHEN + timestamp;
logPath = FREEZE_DETECTOR_PATH + SYSFREEZE + HYPHEN + packageName + HYPHEN + std::to_string(uid) + HYPHEN + timestamp + POSTFIX;
logName = SYSFREEZE + HYPHEN + packageName + HYPHEN + std::to_string(uid) + HYPHEN + timestamp + POSTFIX;
}
@ -216,7 +217,7 @@ std::string Vendor::MergeEventLog(
std::ostringstream body;
for (auto node : list) {
std::string filePath = node.GetLogPath();
HIVIEW_LOGI("merging file:%{public}s.\n", filePath.c_str());
HIVIEW_LOGI("merging file:%{public}s.", filePath.c_str());
if (filePath == "" || filePath == "nolog" || FileUtil::FileExists(filePath) == false) {
HIVIEW_LOGI("only header, no content:[%{public}s, %{public}s]",
node.GetDomain().c_str(), node.GetStringId().c_str());
@ -226,7 +227,7 @@ std::string Vendor::MergeEventLog(
std::ifstream ifs(filePath, std::ios::in);
if (!ifs.is_open()) {
HIVIEW_LOGE("cannot open log file for reading:%{public}s.\n", filePath.c_str());
HIVIEW_LOGE("cannot open log file for reading:%{public}s.", filePath.c_str());
DumpEventInfo(body, HEADER, node);
continue;
}
@ -239,7 +240,7 @@ std::string Vendor::MergeEventLog(
int fd = logStore_->CreateLogFile(logName);
if (fd < 0) {
HIVIEW_LOGE("failed to create log file %{public}s.\n", logPath.c_str());
HIVIEW_LOGE("failed to create log file %{public}s.", logPath.c_str());
return "";
}
FileUtil::SaveStringToFd(fd, header.str());