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 
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 
25 namespace OHOS {
26 namespace HiviewDFX {
27 class CpuCollectionTask {
28 public:
29     CpuCollectionTask(const std::string& workPath);
30     ~CpuCollectionTask() = default;
31     void Collect();
32 
33 private:
34     void InitCpuCollector();
35     void InitCpuStorage();
36 #ifdef HAS_HIPERF
37     void InitCpuPerfDump();
38 #endif
39     void ReportCpuCollectionEvent();
40     void CollectCpuData();
41     void CheckAndDumpTraceData();
42 
43 private:
44     std::string workPath_;
45     std::shared_ptr<UCollectUtil::CpuCollector> cpuCollector_;
46     std::shared_ptr<UCollectUtil::ThreadCpuCollector> threadCpuCollector_;
47     std::shared_ptr<CpuStorage> cpuStorage_;
48 #ifdef HAS_HIPERF
49     std::shared_ptr<CpuPerfDump> cpuPerfDump_;
50 #endif
51 }; // CpuCollectionTask
52 } // namespace HiviewDFX
53 } // namespace OHOS
54 #endif // HIVIEW_PLUGINS_UNIFIED_COLLECTOR_STORAGE_INCLUDE_CPU_COLLECTION_TASK_H
55