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
21public:
22 /**
23 * @brief get a map of [pid] which contains the cpu load between two calls.
24 * function needs to be called regularly (e.g.: 5s.) to get the cpu load per process
25 * @return const map[pid][cpuload]
26 */
27 std::map<std::string, double> getProcessCpuLoad();
28
29
30private:
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};
std::map< std::string, double > getProcessCpuLoad()
get a map of [pid] which contains the cpu load between two calls.