1/*
2 * Copyright (C) 2021 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 CPU_H
16#define CPU_H
17#include <iostream>
18#include <vector>
19#include "sp_profiler.h"
20namespace OHOS {
21namespace SmartPerf {
22struct CpuFreqs {
23    uint32_t cpuId = 0;
24    uint32_t curFreq = 0;
25};
26struct CpuUsageInfos {
27    std::string cpuId;
28    double userUsage = 0;
29    double niceUsage = 0;
30    double systemUsage = 0;
31    double idleUsage = 0;
32    double ioWaitUsage = 0;
33    double irqUsage = 0;
34    double softIrqUsage = 0;
35};
36
37class CPU : public SpProfiler {
38public:
39    static CPU &GetInstance()
40    {
41        static CPU instance;
42        return instance;
43    }
44    std::map<std::string, std::string> ItemData() override;
45    std::vector<CpuFreqs> GetCpuFreq();
46    std::vector<CpuUsageInfos> GetCpuUsage();
47    std::map<std::string, std::string> GetSysProcessCpuLoad() const;
48    void SetPackageName(const std::string &pName);
49    void SetProcessId(const std::string &pid);
50    void IsFindHap();
51
52private:
53    CPU() {};
54    CPU(const CPU &);
55    CPU &operator = (const CPU &);
56    std::string packageName = "";
57    std::string processId = "";
58    bool hapFlag = false;
59    const std::string cpustr = "cpu";
60    const std::string totalcpu = "Totalcpu";
61};
62}
63}
64#endif