• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 HIVIEW_HICOLLIE_PLUGIN_H
17 #define HIVIEW_HICOLLIE_PLUGIN_H
18 
19 #include "event_source.h"
20 #include "plugin.h"
21 #include "sys_event.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 class HiCollieCollector : public EventListener, public EventSource {
26 public:
27     bool ReadyToLoad() override;
28     void OnLoad() override;
29     void OnUnload() override;
30     bool OnEvent(std::shared_ptr<Event> &event) override;
31     void OnUnorderedEvent(const Event &event) override;
32     bool CanProcessEvent(std::shared_ptr<Event> event) override;
Recycle(PipelineEvent * event)33     void Recycle(PipelineEvent* event) override {};
PauseDispatch(std::weak_ptr<Plugin> plugin)34     void PauseDispatch(std::weak_ptr<Plugin> plugin) override {};
35     std::string GetListenerName() override;
36 
37 private:
38     static const inline std::string FAULT_LOG_PATH = "/data/log/faultlog/faultlogger/";
39     static const inline std::string STRINGID_SERVICE_TIMEOUT = "SERVICE_TIMEOUT"; // timer
40     static const inline std::string STRINGID_SERVICE_BLOCK = "SERVICE_BLOCK"; // watchdog
41     static const inline std::string EVENT_PID = "PID";
42     static const inline std::string EVENT_TGID = "TGID";
43     static const inline std::string EVENT_MSG = "MSG";
44 
45     void ProcessHiCollieEvent(SysEvent &sysEvent);
46     std::string GetTimeString(unsigned long long timestamp) const;
47     std::string SelectEventFromDB(
48         int32_t pid, const std::string& processName, const std::string& moduleName) const;
49     void SaveToFile(SysEvent &sysEvent, int32_t pid, const std::string& processName,
50     const std::string& path, const std::string& desPath) const;
51     bool ShouldReportSysFreeze(const std::string& processName);
52     void ReportSysFreezeIfNeed(SysEvent &sysEvent, const std::string& timestamp, const std::string& processName,
53         const std::string& path);
54 };
55 } // namespace HiviewDFX
56 } // namespace OHOS
57 #endif // HIVIEW_HICOLLIE_PLUGIN_H
58