1 // Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 2 // This Source Code Form is subject to the terms of the Mozilla Public 3 // License, v. 2.0. If a copy of the MPL was not distributed with this 4 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 #pragma once 7 8 #include <cstdint> 9 10 class cpu_load_measurer { 11 public: 12 cpu_load_measurer(std::uint32_t _pid); 13 virtual ~cpu_load_measurer(); 14 void start(); 15 void stop(); 16 void print_cpu_load() const; 17 double get_cpu_load() const; 18 19 private: 20 std::uint64_t read_proc_stat(std::uint64_t* _idle); 21 std::uint64_t read_proc_pid_stat(); 22 bool read_clock_ticks(); 23 private: 24 std::uint32_t pid_; 25 std::uint64_t jiffies_complete_start_; 26 std::uint64_t jiffies_idle_start_; 27 std::uint64_t jiffies_complete_stop_; 28 std::uint64_t jiffies_idle_stop_; 29 std::uint64_t clock_ticks_; 30 std::uint64_t jiffies_passed_pid_start_; 31 std::uint64_t jiffies_passed_pid_stop_; 32 double cpu_load_pid_; 33 double cpu_load_overall_; 34 double cpu_load_pid_wo_idle_; 35 }; 36