~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/memory/memory_hpux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
Copyright 1999  Helge Deller deller@gmx.de
 
4
 
 
5
This program is free software; you can redistribute it and/or
 
6
modify it under the terms of the GNU General Public License as
 
7
published by the Free Software Foundation; either version 2 of
 
8
the License or (at your option) version 3 or any later version
 
9
accepted by the membership of KDE e.V. (or its successor approved
 
10
by the membership of KDE e.V.), which shall act as a proxy 
 
11
defined in Section 14 of version 3 of the license.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <stdio.h>
 
23
#include <unistd.h>
 
24
#include <sys/param.h>
 
25
#include <sys/pstat.h>
 
26
 
 
27
 
 
28
#define MAX_SWAP_AREAS 16
 
29
 
 
30
void KCMMemory::fetchValues()
 
31
{
 
32
  int           page_size,i;
 
33
  unsigned long total_mem, total_free,
 
34
                total_physical, total_swap, free_physical,
 
35
                used_physical, used_swap, free_swap;
 
36
 
 
37
  struct        pst_static pststatic;
 
38
  struct        pst_dynamic stats;
 
39
  struct        pst_vminfo vmstats;
 
40
  unsigned long fields_[4];
 
41
  struct        pst_swapinfo swapinfo;
 
42
 
 
43
  pstat_getstatic( &pststatic, sizeof( struct pst_static ), (size_t)1, 0);
 
44
  total_physical = pststatic.physical_memory;
 
45
  page_size = (int)pststatic.page_size;
 
46
 
 
47
  pstat_getdynamic(&stats, sizeof( pst_dynamic ), (size_t)1, 0);
 
48
  pstat_getvminfo(&vmstats, sizeof(vmstats), (size_t)1, 0);
 
49
 
 
50
  fields_[0] = stats.psd_rmtxt + stats.psd_arm;  // TEXT
 
51
  fields_[1] = stats.psd_rm - stats.psd_rmtxt;   // USED
 
52
  fields_[2] = total_physical - fields_[0] - fields_[1] - stats.psd_free; //OTHER
 
53
  fields_[3] = stats.psd_free;  // FREE
 
54
 
 
55
  used_physical   = (total_physical - fields_[3]) * page_size;
 
56
  total_physical *= page_size;
 
57
  free_physical  = (total_physical - used_physical);
 
58
 
 
59
 
 
60
  /* Now check the SWAP-AREAS !! */
 
61
 
 
62
  total_swap = free_swap  = 0;
 
63
 
 
64
  for (i = 0 ; i < MAX_SWAP_AREAS ; i++)
 
65
  {
 
66
      pstat_getswap(&swapinfo, sizeof(swapinfo), (size_t)1, i);
 
67
      if (swapinfo.pss_idx == (unsigned)i)
 
68
      {
 
69
          swapinfo.pss_nfpgs *= 4;  // nfpgs is in 512 Byte Blocks....
 
70
          if (swapinfo.pss_nblksenabled == 0) // == 0 ??
 
71
              swapinfo.pss_nblksenabled = swapinfo.pss_nfpgs;
 
72
          total_swap += (((unsigned long)swapinfo.pss_nblksenabled) * 1024);
 
73
          free_swap  += (((unsigned long)swapinfo.pss_nfpgs       ) * 1024);
 
74
      }
 
75
  }
 
76
 
 
77
  used_swap = total_swap - free_swap;
 
78
 
 
79
 
 
80
  /* Now display the results */
 
81
 
 
82
  total_mem  = total_physical;                  // + total_swap;
 
83
  total_free = (total_physical - used_physical);// + free_swap;
 
84
 
 
85
  memoryInfos[TOTAL_MEM]    = MEMORY(total_mem); // total physical memory (without swaps)
 
86
  memoryInfos[FREE_MEM]     = MEMORY(total_free);// total free physical memory (without swaps)
 
87
  memoryInfos[SHARED_MEM]   = NO_MEMORY_INFO;               /* FIXME ?? */
 
88
  memoryInfos[BUFFER_MEM]   = MEMORY(fields_[2])*page_size; /* FIXME ?? */
 
89
  memoryInfos[SWAP_MEM]     = MEMORY(total_swap); // total size of all swap-partitions
 
90
  memoryInfos[FREESWAP_MEM] = MEMORY(free_swap);  // free memory in swap-partitions
 
91
#ifdef __GNUC__
 
92
#warning "FIXME: memoryInfos[CACHED_MEM]"
 
93
#endif
 
94
  memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
 
95
}