1 /* 2 * Copyright (c) 2023 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_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_CPU_DECORATOR_H 17 #define HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_CPU_DECORATOR_H 18 19 #include "cpu_collector.h" 20 #include "decorator.h" 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 namespace UCollectUtil { 25 class CpuDecorator : public CpuCollector, public ThreadCpuCollector, public UCDecorator { 26 public: 27 CpuDecorator(std::shared_ptr<CpuCollector> collector, 28 std::shared_ptr<ThreadCpuCollector> threadCpuCollector = nullptr) : cpuCollector_(collector), 29 threadCpuCollector_(threadCpuCollector) {}; 30 virtual ~CpuDecorator() = default; 31 32 public: 33 virtual CollectResult<SysCpuLoad> CollectSysCpuLoad() override; 34 virtual CollectResult<SysCpuUsage> CollectSysCpuUsage(bool isNeedUpdate = false) override; 35 virtual CollectResult<double> GetSysCpuUsage() override; 36 virtual CollectResult<ProcessCpuStatInfo> CollectProcessCpuStatInfo(int32_t pid, 37 bool isNeedUpdate = false) override; 38 virtual CollectResult<std::vector<CpuFreq>> CollectCpuFrequency() override; 39 virtual CollectResult<std::vector<ProcessCpuStatInfo>> CollectProcessCpuStatInfos( 40 bool isNeedUpdate = false) override; 41 virtual std::shared_ptr<ThreadCpuCollector> CreateThreadCollector(int pid) override; 42 virtual CollectResult<std::vector<ThreadCpuStatInfo>> CollectThreadStatInfos(bool isNeedUpdate = false) override; 43 virtual int GetCollectPid() override; 44 static void SaveStatCommonInfo(); 45 static void ResetStatInfo(); 46 47 private: 48 std::shared_ptr<CpuCollector> cpuCollector_; 49 std::shared_ptr<ThreadCpuCollector> threadCpuCollector_; 50 static StatInfoWrapper statInfoWrapper_; 51 }; 52 } // namespace UCollectUtil 53 } // namespace HiviewDFX 54 } // namespace OHOS 55 #endif // HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_CPU_DECORATOR_H 56