feat: first working set

This commit is contained in:
Tobias Schmidl 2025-06-16 21:22:22 +02:00
parent cccebf674a
commit bed7360063
5 changed files with 59 additions and 42 deletions

View file

@ -3,7 +3,25 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include <glimpses/glimpses.hpp>
#include <sched.h>
#include <thread>
#include <unistd.h>
using namespace glimpses;
Glimpses::Glimpses() {}
Glimpses::Glimpses()
{
}
Glimpses::CPUSet Glimpses::getCPUCount() const
{
cpu_set_t cpuset;
auto minmax = [](int64_t min, int64_t value, int64_t max) -> CPUCount {
return std::min(std::max(value, min), max);
};
sched_getaffinity(0, sizeof(cpuset), &cpuset);
return CPUSet{{"configured", minmax(0, sysconf(_SC_NPROCESSORS_CONF), MAX_CPU_COUNT)},
{"logical", minmax(0, std::thread::hardware_concurrency(), MAX_CPU_COUNT)},
{"online", minmax(0, sysconf(_SC_NPROCESSORS_ONLN), MAX_CPU_COUNT)},
{"allowed", minmax(0, CPU_COUNT(&cpuset), MAX_CPU_COUNT)}};
}