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 LoadTraceSwitch(); 52 static void OnFreezeDetectorParamChanged(const char* key, const char* value, void* context); 53 static void OnSwitchRecordTraceStateChanged(const char* key, const char* value, void* context); 54 void OnMainThreadJank(SysEvent& sysEvent); 55 #endif 56 #ifdef HIVIEW_LOW_MEM_THRESHOLD 57 void RunCacheMonitorLoop(); 58 void ExitCacheMonitorLoop(); 59 #endif 60 void CleanDataFiles(); 61 62 static void OnSwitchStateChanged(const char* key, const char* value, void* context); 63 64 private: 65 std::string workPath_; 66 std::shared_ptr<CpuCollectionTask> cpuCollectionTask_; 67 #ifdef UNIFIED_COLLECTOR_TRACE_ENABLE 68 std::shared_ptr<EventListener> telemetryListener_; 69 #endif 70 #ifdef HIVIEW_LOW_MEM_THRESHOLD 71 std::shared_ptr<TraceCacheMonitor> traceCacheMonitor_; 72 #endif 73 std::list<uint64_t> taskList_; 74 volatile bool isCpuTaskRunning_; 75 }; // UnifiedCollector 76 } // namespace HiviewDFX 77 } // namespace OHOS 78 #endif // HIVIEW_PLUGINS_UNIFIED_COLLECTOR_INCLUDE_UNIFIED_COLLECTOR_H 79