linux_process_load.hpp
Go to the documentation of this file.
1 /**
2  * @author: Daniel Fuchs
3  * @contact: fuxeysolutions@gmail.com
4  *
5  * distributed under the MIT License (MIT).
6  * Copyright (c) Daniel Fuchs
7  *
8  */
9 #pragma once
10 
11 
12 #include <cstdint>
13 #include <map>
14 #include <string>
15 #include <tuple>
16 #include <unordered_map>
17 
19 
20 public:
21  /**
22  * @brief get a map of [pid] which contains the cpu load between two calls.
23  * function needs to be called regularly (e.g.: 5s.) to get the cpu load per process
24  * @return const map[pid][cpuload]
25  */
26  std::map<std::string, double> getProcessCpuLoad();
27 
28 
29 
30 private:
31  void parseProcess(const std::string& pid);
32  void findProcesses();
33  void calculateProcessLoad();
34  std::map<std::string, double> procCPUUsage;
35  std::tuple<uint64_t, uint64_t, uint64_t, uint64_t> oldCpuTimes;
36  std::tuple<uint64_t, uint64_t, uint64_t, uint64_t> CpuTimes;
37  std::map<std::string,std::unordered_map<std::string, std::string>> processStat;
38  std::map<std::string,std::unordered_map<std::string, std::string>> oldProcessStat;
39 };
40 
41 
linuxProcessLoad
Definition: linux_process_load.hpp:18
linuxProcessLoad::getProcessCpuLoad
std::map< std::string, double > getProcessCpuLoad()
get a map of [pid] which contains the cpu load between two calls.
Definition: linux_process_load.cpp:73