2022-12-21 16:47:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <fstream>
|
|
|
|
#include <numeric>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-04-13 23:25:13 +00:00
|
|
|
#include "ALabel.hpp"
|
2022-12-21 16:47:06 +00:00
|
|
|
#include "util/sleeper_thread.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules {
|
|
|
|
|
2023-04-13 23:25:13 +00:00
|
|
|
class CpuUsage : public ALabel {
|
2022-12-21 16:47:06 +00:00
|
|
|
public:
|
|
|
|
CpuUsage(const std::string&, const Json::Value&);
|
2023-07-29 12:52:59 +00:00
|
|
|
virtual ~CpuUsage() = default;
|
|
|
|
auto update() -> void override;
|
2022-12-21 16:47:06 +00:00
|
|
|
|
2023-07-29 13:56:51 +00:00
|
|
|
// This is a static member because it is also used by the cpu module.
|
2023-10-17 17:29:06 +00:00
|
|
|
static std::tuple<std::vector<uint16_t>, std::string> getCpuUsage(
|
|
|
|
std::vector<std::tuple<size_t, size_t>>&);
|
2023-07-29 13:56:51 +00:00
|
|
|
|
2022-12-21 16:47:06 +00:00
|
|
|
private:
|
2023-07-29 13:56:51 +00:00
|
|
|
static std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
2022-12-21 16:47:06 +00:00
|
|
|
|
|
|
|
std::vector<std::tuple<size_t, size_t>> prev_times_;
|
|
|
|
|
|
|
|
util::SleeperThread thread_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules
|