~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/info/memory_linux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <sys/sysinfo.h>
2
 
#include <unistd.h>
3
 
#include <stdlib.h>
4
 
#include <qfile.h>
5
 
 
6
 
void KMemoryWidget::update()
7
 
{
8
 
  struct sysinfo info;
9
 
  
10
 
  sysinfo(&info);       /* Get Information from system... */
11
 
  
12
 
  /* 
13
 
   * The sysinfo.mem_unit member variable is not available in older 2.4 kernels.
14
 
   * If you have troubles compiling this code, set mem_unit to "1".
15
 
   */
16
 
    
17
 
  const int mem_unit = info.mem_unit;
18
 
 
19
 
  Memory_Info[TOTAL_MEM]    = MEMORY(info.totalram)  * mem_unit; // total physical memory (without swaps)
20
 
  Memory_Info[FREE_MEM]     = MEMORY(info.freeram)   * mem_unit; // total free physical memory (without swaps)
21
 
  Memory_Info[SHARED_MEM]   = MEMORY(info.sharedram) * mem_unit; 
22
 
  Memory_Info[BUFFER_MEM]   = MEMORY(info.bufferram) * mem_unit; 
23
 
  Memory_Info[SWAP_MEM]     = MEMORY(info.totalswap) * mem_unit; // total size of all swap-partitions
24
 
  Memory_Info[FREESWAP_MEM] = MEMORY(info.freeswap)  * mem_unit; // free memory in swap-partitions
25
 
  
26
 
  QFile file("/proc/meminfo");
27
 
  if (file.open(IO_ReadOnly)) {
28
 
        char buf[512];
29
 
        while (file.readLine(buf, sizeof(buf) - 1) > 0) {
30
 
                if (strncmp(buf,"Cached:",7)==0) {
31
 
                        unsigned long v;
32
 
                        v = strtoul(&buf[7],NULL,10);                   
33
 
                        Memory_Info[CACHED_MEM] = MEMORY(v) * 1024; // Cached memory in RAM
34
 
                }
35
 
        }
36
 
        file.close();
37
 
  }
38
 
}
39