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 "sysevent_listener.h" 17 18 #include "csv_utils.h" 19 #include "hisysevent.h" 20 #include "report.h" 21 22 namespace OHOS { 23 namespace WuKong { 24 using OHOS::HiviewDFX::HiSysEvent; 25 OnEvent(std::shared_ptr<HiviewDFX::HiSysEventRecord> sysEvent)26void SysEventListener::OnEvent(std::shared_ptr<HiviewDFX::HiSysEventRecord> sysEvent) 27 { 28 if (sysEvent == nullptr) { 29 return; 30 } 31 std::string domain = sysEvent->GetDomain(); 32 std::string eventName = sysEvent->GetEventName(); 33 OHOS::HiviewDFX::HiSysEvent::EventType eventType = sysEvent->GetEventType(); 34 TRACK_LOG("----------Exception caught----------"); 35 TRACK_LOG_STR("domain: %s", domain.c_str()); 36 TRACK_LOG_STR("eventName: %s", eventName.c_str()); 37 TRACK_LOG_STR("eventType: %d", eventType); 38 TRACK_LOG("------------------------------------"); 39 CsvUtils::OneLineData data; 40 data.domain = domain; 41 data.name = eventName; 42 switch (eventType) { 43 case HiSysEvent::EventType::FAULT: 44 data.type = "FAULT"; 45 break; 46 case HiSysEvent::EventType::STATISTIC: 47 data.type = "STATISTIC"; 48 break; 49 case HiSysEvent::EventType::SECURITY: 50 data.type = "SECURITY"; 51 break; 52 case HiSysEvent::EventType::BEHAVIOR: 53 data.type = "BEHAVIOR"; 54 break; 55 default: 56 data.type = "UNKNOWN"; 57 } 58 data.time = sysEvent->GetTime(); 59 data.timeZone = sysEvent->GetTimeZone(); 60 data.pid = static_cast<uint64_t>(sysEvent->GetPid()); 61 data.tid = static_cast<uint64_t>(sysEvent->GetTid()); 62 data.uid = static_cast<uint64_t>(sysEvent->GetUid()); 63 CsvUtils::WriteOneLine(csvFile, data); 64 } OnServiceDied()65void SysEventListener::OnServiceDied() 66 { 67 ERROR_LOG("Listener service Died"); 68 } 69 } // namespace WuKong 70 } // namespace OHOS 71