diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /kcontrol/info/memory_linux.cpp | |
download | tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kcontrol/info/memory_linux.cpp')
-rw-r--r-- | kcontrol/info/memory_linux.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/kcontrol/info/memory_linux.cpp b/kcontrol/info/memory_linux.cpp new file mode 100644 index 000000000..c393c01e7 --- /dev/null +++ b/kcontrol/info/memory_linux.cpp @@ -0,0 +1,39 @@ +#include <sys/sysinfo.h> +#include <unistd.h> +#include <stdlib.h> +#include <qfile.h> + +void KMemoryWidget::update() +{ + struct sysinfo info; + + sysinfo(&info); /* Get Information from system... */ + + /* + * The sysinfo.mem_unit member variable is not available in older 2.4 kernels. + * If you have troubles compiling this code, set mem_unit to "1". + */ + + const int mem_unit = info.mem_unit; + + Memory_Info[TOTAL_MEM] = MEMORY(info.totalram) * mem_unit; // total physical memory (without swaps) + Memory_Info[FREE_MEM] = MEMORY(info.freeram) * mem_unit; // total free physical memory (without swaps) + Memory_Info[SHARED_MEM] = MEMORY(info.sharedram) * mem_unit; + Memory_Info[BUFFER_MEM] = MEMORY(info.bufferram) * mem_unit; + Memory_Info[SWAP_MEM] = MEMORY(info.totalswap) * mem_unit; // total size of all swap-partitions + Memory_Info[FREESWAP_MEM] = MEMORY(info.freeswap) * mem_unit; // free memory in swap-partitions + + QFile file("/proc/meminfo"); + if (file.open(IO_ReadOnly)) { + char buf[512]; + while (file.readLine(buf, sizeof(buf) - 1) > 0) { + if (strncmp(buf,"Cached:",7)==0) { + unsigned long v; + v = strtoul(&buf[7],NULL,10); + Memory_Info[CACHED_MEM] = MEMORY(v) * 1024; // Cached memory in RAM + } + } + file.close(); + } +} + |