RAM usage +
Introduced a new field to track memory usage in the backend status structure, allowing the server to report memory utilization as a percentage Implemented a Linux-specific routine to read /proc/meminfo and calculate the memory usage percentage, and integrated this into the status query Added serialization for the memory usage field so it is included in JSON responses Updated the frontend class to deserialize and display memory usage alongside CPU usage on the status readout
This commit is contained in:
+33
-1
@@ -110,6 +110,36 @@ static void GetCpuFrequency(uint64_t *freqMin, uint64_t *freqMax)
|
||||
*freqMin = fMin;
|
||||
*freqMax = fMax;
|
||||
}
|
||||
static float GetMemoryUsagePercent()
|
||||
{
|
||||
try {
|
||||
std::ifstream f("/proc/meminfo");
|
||||
if (!f.is_open()) return 0.0f;
|
||||
std::string label;
|
||||
uint64_t memTotal = 0;
|
||||
uint64_t memAvailable = 0;
|
||||
while (f >> label)
|
||||
{
|
||||
if (label == "MemTotal:")
|
||||
{
|
||||
f >> memTotal;
|
||||
} else if (label == "MemAvailable:")
|
||||
{
|
||||
f >> memAvailable;
|
||||
} else {
|
||||
std::string rest;
|
||||
std::getline(f, rest);
|
||||
}
|
||||
if (memTotal && memAvailable) break;
|
||||
}
|
||||
if (memTotal == 0) return 0.0f;
|
||||
return (float)(memTotal - memAvailable) * 100.0f / (float)memTotal;
|
||||
} catch (const std::exception &)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetGovernor()
|
||||
{
|
||||
return pipedal::GetCpuGovernor();
|
||||
@@ -2119,12 +2149,13 @@ public:
|
||||
|
||||
if (this->audioDriver != nullptr)
|
||||
{
|
||||
result.cpuUsage_ = audioDriver->CpuUse();
|
||||
result.cpuUsage_ = audioDriver->CpuUse();
|
||||
if (!std::isfinite(result.cpuUsage_))
|
||||
{
|
||||
result.cpuUsage_ = 0.0f;
|
||||
}
|
||||
}
|
||||
result.memoryUsage_ = GetMemoryUsagePercent();
|
||||
GetCpuFrequency(&result.cpuFreqMin_, &result.cpuFreqMax_);
|
||||
result.hasCpuGovernor_ = HasCpuGovernor();
|
||||
if (result.hasCpuGovernor_)
|
||||
@@ -2324,6 +2355,7 @@ JSON_MAP_REFERENCE(JackHostStatus, errorMessage)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, restarting)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, underruns)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, cpuUsage)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, memoryUsage)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, msSinceLastUnderrun)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, temperaturemC)
|
||||
JSON_MAP_REFERENCE(JackHostStatus, cpuFreqMin)
|
||||
|
||||
@@ -191,6 +191,7 @@ namespace pipedal
|
||||
bool restarting_;
|
||||
uint64_t underruns_;
|
||||
float cpuUsage_ = 0;
|
||||
float memoryUsage_ = 0;
|
||||
uint64_t msSinceLastUnderrun_ = 0;
|
||||
int32_t temperaturemC_ = -100000;
|
||||
uint64_t cpuFreqMax_ = 0;
|
||||
|
||||
@@ -68,6 +68,7 @@ export default class JackHostStatus {
|
||||
this.errorMessage = input.errorMessage;
|
||||
this.underruns = input.underruns;
|
||||
this.cpuUsage = input.cpuUsage;
|
||||
this.memoryUsage = input.memoryUsage;
|
||||
this.msSinceLastUnderrun = input.msSinceLastUnderrun;
|
||||
this.temperaturemC = input.temperaturemC;
|
||||
this.cpuFreqMax = input.cpuFreqMax;
|
||||
@@ -84,6 +85,7 @@ export default class JackHostStatus {
|
||||
restarting: boolean = false;
|
||||
underruns: number = 0;
|
||||
cpuUsage: number = 0;
|
||||
memoryUsage: number = 0;
|
||||
msSinceLastUnderrun: number = -5000 * 1000;
|
||||
temperaturemC: number = -1000000;
|
||||
cpuFreqMax: number = 0;
|
||||
@@ -177,6 +179,11 @@ export default class JackHostStatus {
|
||||
CPU: {cpuDisplay(status.cpuUsage)}
|
||||
</Typography>
|
||||
</span>
|
||||
<span style={{ color: underrunError ? RED_COLOR : GREEN_COLOR }}>
|
||||
<Typography variant="caption" color="inherit">
|
||||
MEM: {cpuDisplay(status.memoryUsage)}
|
||||
</Typography>
|
||||
</span>
|
||||
|
||||
<span style={{ color: GREEN_COLOR }}>
|
||||
<Typography variant="caption" color="inherit">{tempDisplay(status.temperaturemC)}</Typography>
|
||||
|
||||
Reference in New Issue
Block a user