• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #ifndef HIVIEW_PLUGINS_UNIFIED_COLLECTOR_INCLUDE_UNIFIED_COLLECTOR_H
16 #define HIVIEW_PLUGINS_UNIFIED_COLLECTOR_INCLUDE_UNIFIED_COLLECTOR_H
17 
18 #include <atomic>
19 #include <memory>
20 
21 #include "cpu_collection_task.h"
22 #include "plugin.h"
23 #include "sys_event.h"
24 #ifdef HIVIEW_LOW_MEM_THRESHOLD
25 #include "trace_cache_monitor.h"
26 #endif
27 #include "unified_collection_stat.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class UnifiedCollector : public Plugin {
32 public:
33     void OnLoad() override;
34     void OnUnload() override;
35 #ifdef UNIFIED_COLLECTOR_TRACE_ENABLE
36     bool OnEvent(std::shared_ptr<Event>& event) override;
37     void OnEventListeningCallback(const Event& event) override;
38     void Dump(int fd, const std::vector<std::string>& cmds) override;
39 #endif
40 
41 private:
42     void Init();
43     void InitWorkPath();
44     void RunCpuCollectionTask();
45     void CpuCollectionFfrtTask();
46     void RunIoCollectionTask();
47     void RunUCollectionStatTask();
48     void IoCollectionTask();
49     void UCollectionStatTask();
50 #ifdef UNIFIED_COLLECTOR_TRACE_ENABLE
51     void HandleTeleMetryStart(std::shared_ptr<Event>& event);
52     void HandleTeleMetryStop();
53     void HandleTeleMetryTimeout();
54     void LoadTraceSwitch();
55     static void OnFreezeDetectorParamChanged(const char* key, const char* value, void* context);
56     static void OnSwitchRecordTraceStateChanged(const char* key, const char* value, void* context);
57     void OnMainThreadJank(SysEvent& sysEvent);
58 #endif
59 #ifdef HIVIEW_LOW_MEM_THRESHOLD
60     void RunCacheMonitorLoop();
61     void ExitCacheMonitorLoop();
62 #endif
63     void CleanDataFiles();
64 
65     static void OnSwitchStateChanged(const char* key, const char* value, void* context);
66 
67 private:
68     std::string workPath_;
69     std::shared_ptr<CpuCollectionTask> cpuCollectionTask_;
70 #ifdef UNIFIED_COLLECTOR_TRACE_ENABLE
71     std::shared_ptr<EventListener> telemetryListener_;
72     std::vector<uint64_t> telemetryList_;
73 #endif
74 #ifdef HIVIEW_LOW_MEM_THRESHOLD
75     std::shared_ptr<TraceCacheMonitor> traceCacheMonitor_;
76 #endif
77     std::list<uint64_t> taskList_;
78     volatile bool isCpuTaskRunning_;
79 }; // UnifiedCollector
80 } // namespace HiviewDFX
81 } // namespace OHOS
82 #endif // HIVIEW_PLUGINS_UNIFIED_COLLECTOR_INCLUDE_UNIFIED_COLLECTOR_H
83