• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HIDUMPER_ZIDL_COMMON_UTILS_H
16 #define HIDUMPER_ZIDL_COMMON_UTILS_H
17 #include <string>
18 #include <vector>
19 namespace OHOS {
20 namespace HiviewDFX {
21 class DumpCommonUtils {
22 public:
23     struct CpuInfo {
24         int id_;
25     public:
26         CpuInfo();
27     };
28     // get all cpu information in device.
29     static bool GetCpuInfos(std::vector<CpuInfo> &infos);
30     struct PidInfo {
31         int pid_;
32         int ppid_;
33         int uid_;
34         int gid_;
35         std::string name_;
36         std::string cmdline_;
37     public:
38         PidInfo();
39         void Reset();
40     };
41     // get all process information in device.
42     static bool GetPidInfos(std::vector<PidInfo> &infos, bool all = false);
43     // get process name by pid.
44     static bool GetProcessNameByPid(int pid, std::string &name);
45     // get process information by pid.
46     static bool GetProcessInfo(int pid, PidInfo &info);
47     // check head of string.
48     static bool StartWith(const std::string& str, const std::string& head);
49     static bool GetUserPids(std::vector<int> &pids);
50     static bool IsUserPid(const std::string &pid);
51 private:
52     static bool GetLinesInFile(const std::string& file, std::vector<std::string>& lines);
53     static bool GetNamesInFolder(const std::string& folder, std::vector<std::string>& names);
54 };
55 } // namespace HiviewDFX
56 } // namespace OHOS
57 #endif // HIDUMPER_ZIDL_COMMON_UTILS_H
58