KySdkResource(3)
💖 KySdkResource 💖
okay bestie, so this is KySdkResource(3) from the System Resource Monitoring Library — yes that's the manual name, it's giving very "I monitor your whole computer and I'm not sorry" ✨
🌸 NAME 🌸
KySdkResource — the class that grabs your current system resource usage info. 获取当前系统资源占用信息类 💅
🎀 SYNOPSIS 🎀
#include <kysdkdbus.h>
🦋 DESCRIPTION 🦋
okay so KySdkResource is THE class for pulling system resource usage info, and it covers, like, all of this:
- the total physical memory size, its usage rate, and how much is actually being used
- the actually available and free physical memory sizes
- the total virtual memory all your apps have asked for
- the Swap partition total size, usage rate, and free size
- the CPU's instantaneous usage rate
- how long the OS has been up since boot
and no cap, this class inherits from QObject. slay. 👑
✨ PUBLIC SLOTS ✨
double getMemTotalKiB () const— grabs the total physical memory size in the system.
returns: a double — the physical memory size, in KiB units.
double getMemUsagePercent () const— grabs the physical memory usage rate.
returns: a double — the physical memory usage rate.
double getMemUsageKiB () const— grabs how much physical memory is used. heads up bestie: Buffer/Cache counts as used memory here, fr fr.
returns: a double — the physical memory usage amount, in KiB units.
double getMemAvailableKiB () const— grabs the actually available physical memory size. lowkey this number is roughly Free + Buffer + Cache.
returns: a double — the available physical memory size, in KiB units.
double getMemFreeKiB () const— grabs the actually free physical memory size. and again, warning: Buffer/Cache is counted as used memory 💀
returns: a double — the free physical memory size, in KiB units.
double getMemVirtAllocKiB () const— grabs the total virtual memory that every app has requested.
returns: a double — the total virtual memory allocation, in KiB units.
double getMemSwapTotalKiB () const— grabs the total size of the Swap partition in the system.
returns: a double — the Swap partition size, in KiB units.
double getMemSwapUsagePercent () const— grabs the Swap partition usage rate.
returns: a double — the Swap partition usage rate.
double getMemSwapUsageKiB () const— grabs how much Swap is being used.
returns: a double — the Swap partition usage amount, in KiB units.
double getMemSwapFreeKiB () const— grabs how much Swap is free.
returns: a double — the free Swap partition size, in KiB units.
double getCpuCurrentUsage () const— grabs the CPU's instantaneous usage rate.
returns: a double — the CPU instantaneous usage rate, and this value is < 1.00.
QString getUpTime () const— grabs how long the OS has been up.
returns: a QString — the uptime. ⏰
🌈 MEMORY USAGE EXPLANATION 🌈
the Linux system memory tea, explained:
MemTotal— the total system memory sizeMemFree— completely free memoryMemAvailable— the actually available memory (MemFree + Buffers + Cached)Buffers/Cache— memory used by kernel buffersSwap— disk space used when physical memory isn't enough
🍓 EXAMPLE USAGE 🍓
#include <kysdkdbus.h>
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
KySdkResource resource;
// 获取内存信息
double memTotal = resource.getMemTotalKiB();
double memUsage = resource.getMemUsagePercent();
double memAvailable = resource.getMemAvailableKiB();
// 获取 CPU 使用率
double cpuUsage = resource.getCpuCurrentUsage();
// 获取系统运行时间
QString uptime = resource.getUpTime();
qDebug() << "内存总量:" << memTotal << "KiB";
qDebug() << "内存使用率:" << (memUsage * 100) << "%";
qDebug() << "可用内存:" << memAvailable << "KiB";
qDebug() << "CPU 使用率:" << (cpuUsage * 100) << "%";
qDebug() << "系统运行时间:" << uptime;
return 0;
}
💜 NOTES 💜
- every memory size unit is KiB (
1024 bytes), periodt - the CPU usage rate return value is a decimal between
0.0and1.0 - when the memory usage rate gets calculated, Buffer/Cache is counted into used memory
MemAvailableis an estimate of the actually available memory
👑 SEE ALSO 👑
QObject(3qt5), D-Bus(1), proc(5), free(1), top(1)
🫶 AUTHOR 🫶
Generated automatically by Doxygen for kysdkdbus.h from the source code. (yes, it wrote itself, iconic behavior honestly)
okay that's the whole page bestie!! version 1.0, dated Wed Sep 20 2023 — mwah, go monitor some resources, you got this 💅✨💖
📦 where this page comes from
- arch rolling: libkysdk-system 3.0.1.4-1 · LGPL-3.0-or-later AND LGPL-2.1-only OR LGPL-3.0-only AND LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LGPL-3.0-only WITH Qt-LGPL-exception-1.1 AND MIT
- ubuntu resolute: libkysdk-system-dev 3.0.1.2-0ubuntu1 · LGPL-3.0-only
- ubuntu stonking: libkysdk-system-dev 3.0.1.3-0ubuntu1 · LGPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms