• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)26 void 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     CsvUtils::OneLineData data;
35     data.domain = domain;
36     data.name = eventName;
37     switch (eventType) {
38         case HiSysEvent::EventType::FAULT:
39             data.type = "FAULT";
40             break;
41         case HiSysEvent::EventType::STATISTIC:
42             data.type = "STATISTIC";
43             break;
44         case HiSysEvent::EventType::SECURITY:
45             data.type = "SECURITY";
46             break;
47         case HiSysEvent::EventType::BEHAVIOR:
48             data.type = "BEHAVIOR";
49             break;
50         default:
51             data.type = "UNKNOWN";
52     }
53     data.time = sysEvent->GetTime();
54     data.timeZone = sysEvent->GetTimeZone();
55     data.pid = static_cast<uint64_t>(sysEvent->GetPid());
56     data.tid = static_cast<uint64_t>(sysEvent->GetTid());
57     data.uid = static_cast<uint64_t>(sysEvent->GetUid());
58     CsvUtils::WriteOneLine(csvFile, data);
59 }
OnServiceDied()60 void SysEventListener::OnServiceDied()
61 {
62     ERROR_LOG("Listener service Died");
63 }
64 }  // namespace WuKong
65 }  // namespace OHOS
66