File indexing completed on 2024-05-12 17:00:15
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "backend.h" 0008 0009 #include <systemstats/AggregateSensor.h> 0010 #include <systemstats/SensorObject.h> 0011 #include <systemstats/SensorProperty.h> 0012 0013 #include <KLocalizedString> 0014 0015 MemoryBackend::MemoryBackend(KSysGuard::SensorContainer *container) 0016 { 0017 m_physicalObject = new KSysGuard::SensorObject(QStringLiteral("physical"), i18nc("@title", "Physical Memory"), container); 0018 m_swapObject = new KSysGuard::SensorObject(QStringLiteral("swap"), i18nc("@title", "Swap Memory"), container); 0019 } 0020 0021 void MemoryBackend::makeSensors() 0022 { 0023 m_total = new KSysGuard::SensorProperty(QStringLiteral("total"), m_physicalObject); 0024 m_used = new KSysGuard::SensorProperty(QStringLiteral("used"), m_physicalObject); 0025 m_free = new KSysGuard::SensorProperty(QStringLiteral("free"), m_physicalObject); 0026 m_application = new KSysGuard::SensorProperty(QStringLiteral("application"), m_physicalObject); 0027 m_cache = new KSysGuard::SensorProperty(QStringLiteral("cache"), m_physicalObject); 0028 m_buffer = new KSysGuard::SensorProperty(QStringLiteral("buffer"), m_physicalObject); 0029 0030 m_swapTotal = new KSysGuard::SensorProperty(QStringLiteral("total"), m_swapObject); 0031 m_swapUsed = new KSysGuard::SensorProperty(QStringLiteral("used"), m_swapObject); 0032 m_swapFree = new KSysGuard::SensorProperty(QStringLiteral("free"), m_swapObject); 0033 } 0034 0035 void MemoryBackend::initSensors() 0036 { 0037 makeSensors(); 0038 0039 m_total->setName(i18nc("@title", "Total Physical Memory")); 0040 m_total->setShortName(i18nc("@title, Short for 'Total Physical Memory'", "Total")); 0041 m_total->setUnit(KSysGuard::UnitByte); 0042 m_total->setVariantType(QVariant::ULongLong); 0043 0044 m_used->setName(i18nc("@title", "Used Physical Memory")); 0045 m_used->setShortName(i18nc("@title, Short for 'Used Physical Memory'", "Used")); 0046 m_used->setUnit(KSysGuard::UnitByte); 0047 m_used->setVariantType(QVariant::ULongLong); 0048 m_used->setMax(m_total); 0049 auto usedPercentage = new KSysGuard::PercentageSensor(m_physicalObject, QStringLiteral("usedPercent"), i18nc("@title", "Used Physical Memory Percentage")); 0050 usedPercentage->setShortName(m_used->info().shortName); 0051 usedPercentage->setBaseSensor(m_used); 0052 0053 m_free->setName(i18nc("@title", "Free Physical Memory")); 0054 m_free->setShortName(i18nc("@title, Short for 'Free Physical Memory'", "Free")); 0055 m_free->setUnit(KSysGuard::UnitByte); 0056 m_free->setVariantType(QVariant::ULongLong); 0057 m_free->setMax(m_total); 0058 auto freePercentage = new KSysGuard::PercentageSensor(m_physicalObject, QStringLiteral("freePercent"), i18nc("@title", "Free Physical Memory Percentage")); 0059 freePercentage->setShortName(m_free->info().shortName); 0060 freePercentage->setBaseSensor(m_free); 0061 0062 m_application->setName(i18nc("@title", "Application Memory")); 0063 m_application->setShortName(i18nc("@title, Short for 'Application Memory'", "Application")); 0064 m_application->setUnit(KSysGuard::UnitByte); 0065 m_application->setVariantType(QVariant::ULongLong); 0066 m_application->setMax(m_total); 0067 auto applicationPercentage = new KSysGuard::PercentageSensor(m_physicalObject, QStringLiteral("applicationPercent"), i18nc("@title", "Application Memory Percentage")); 0068 applicationPercentage->setShortName(m_application->info().shortName); 0069 applicationPercentage->setBaseSensor(m_application); 0070 0071 m_cache->setName(i18nc("@title", "Cache Memory")); 0072 m_cache->setShortName(i18nc("@title, Short for 'Cache Memory'", "Cache")); 0073 m_cache->setUnit(KSysGuard::UnitByte); 0074 m_cache->setVariantType(QVariant::ULongLong); 0075 m_cache->setMax(m_total); 0076 auto cachePercentage = new KSysGuard::PercentageSensor(m_physicalObject, QStringLiteral("cachePercent"), i18nc("@title", "Cache Memory Percentage")); 0077 cachePercentage->setShortName(m_cache->info().shortName); 0078 cachePercentage->setBaseSensor(m_cache); 0079 0080 m_buffer->setName(i18nc("@title", "Buffer Memory")); 0081 m_buffer->setShortName(i18nc("@title, Short for 'Buffer Memory'", "Buffer")); 0082 m_buffer->setDescription(i18n("Amount of memory used for caching disk blocks")); 0083 m_buffer->setUnit(KSysGuard::UnitByte); 0084 m_buffer->setVariantType(QVariant::ULongLong); 0085 m_buffer->setMax(m_total); 0086 auto bufferPercentage = new KSysGuard::PercentageSensor(m_physicalObject, QStringLiteral("bufferPercent"), i18nc("@title", "Buffer Memory Percentage")); 0087 bufferPercentage->setShortName(m_buffer->info().shortName); 0088 bufferPercentage->setBaseSensor(m_buffer); 0089 0090 m_swapTotal->setName(i18nc("@title", "Total Swap Memory")); 0091 m_swapTotal->setShortName(i18nc("@title, Short for 'Total Swap Memory'", "Total")); 0092 m_swapTotal->setUnit(KSysGuard::UnitByte); 0093 m_swapTotal->setVariantType(QVariant::ULongLong); 0094 0095 m_swapUsed->setName(i18nc("@title", "Used Swap Memory")); 0096 m_swapUsed->setShortName(i18nc("@title, Short for 'Used Swap Memory'", "Used")); 0097 m_swapUsed->setUnit(KSysGuard::UnitByte); 0098 m_swapUsed->setVariantType(QVariant::ULongLong); 0099 m_swapUsed->setMax(m_swapTotal); 0100 auto usedSwapPercentage = new KSysGuard::PercentageSensor(m_swapObject, QStringLiteral("usedPercent"), i18nc("@title", "Used Swap Memory Percentage")); 0101 usedSwapPercentage->setShortName(m_swapUsed->info().shortName); 0102 usedSwapPercentage->setBaseSensor(m_swapUsed); 0103 0104 m_swapFree->setName(i18nc("@title", "Free Swap Memory")); 0105 m_swapFree->setShortName(i18nc("@title, Short for 'Free Swap Memory'", "Free")); 0106 m_swapFree->setUnit(KSysGuard::UnitByte); 0107 m_swapFree->setVariantType(QVariant::ULongLong); 0108 m_swapFree->setMax(m_swapTotal); 0109 auto freeSwapPercentage = new KSysGuard::PercentageSensor(m_swapObject, QStringLiteral("freePercent"), i18nc("@title", "Free Swap Memory Percentage")); 0110 freeSwapPercentage->setShortName(m_swapFree->info().shortName); 0111 freeSwapPercentage->setBaseSensor(m_swapFree); 0112 }