diff --git a/src/AudioHost.cpp b/src/AudioHost.cpp index cf5f30e..99bcc9f 100644 --- a/src/AudioHost.cpp +++ b/src/AudioHost.cpp @@ -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) diff --git a/src/AudioHost.hpp b/src/AudioHost.hpp index 16a9fb3..f2e23ba 100644 --- a/src/AudioHost.hpp +++ b/src/AudioHost.hpp @@ -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; diff --git a/vite/src/pipedal/JackHostStatus.tsx b/vite/src/pipedal/JackHostStatus.tsx index 67239e9..fcccbea 100644 --- a/vite/src/pipedal/JackHostStatus.tsx +++ b/vite/src/pipedal/JackHostStatus.tsx @@ -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)}   + + + MEM: {cpuDisplay(status.memoryUsage)}   + + {tempDisplay(status.temperaturemC)}