1 /* 2 * Copyright (c) 2023-2025 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_PLUGINS_UNIFIED_COLLECTOR_STORAGE_INCLUDE_CPU_COLLECTION_TASK_H 17 #define HIVIEW_PLUGINS_UNIFIED_COLLECTOR_STORAGE_INCLUDE_CPU_COLLECTION_TASK_H 18 19 #include <memory> 20 21 #include "cpu_collector.h" 22 #include "cpu_storage.h" 23 #include "cpu_perf_dump.h" 24 #include "dump_trace_controller.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class CpuCollectionTask { 29 public: 30 CpuCollectionTask(const std::string& workPath); 31 ~CpuCollectionTask() = default; 32 void Collect(); 33 34 private: 35 void InitCpuCollector(); 36 void InitCpuStorage(); 37 #ifdef HAS_HIPERF 38 void InitCpuPerfDump(); 39 #endif 40 void ReportCpuCollectionEvent(); 41 void CollectCpuData(); 42 #ifdef CATCH_TRACE_FOR_CPU_HIGH_LOAD 43 void InitDumpTraceController(); 44 std::shared_ptr<DumpTraceController> dumpTraceController_; 45 #endif 46 47 private: 48 std::string workPath_; 49 std::shared_ptr<UCollectUtil::CpuCollector> cpuCollector_; 50 std::shared_ptr<UCollectUtil::ThreadCpuCollector> threadCpuCollector_; 51 std::shared_ptr<CpuStorage> cpuStorage_; 52 #ifdef HAS_HIPERF 53 std::shared_ptr<CpuPerfDump> cpuPerfDump_; 54 #endif 55 }; // CpuCollectionTask 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 #endif // HIVIEW_PLUGINS_UNIFIED_COLLECTOR_STORAGE_INCLUDE_CPU_COLLECTION_TASK_H 59