casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HostInfoHpux.h
Go to the documentation of this file.
1 //# HostInfo_hpux.h: HP/UX specific memory, swap, and CPU code.
2 //# $Id$
3 
4  /*
5  ** This is a greatly MODIFIED version of a "top" machine dependent file.
6  ** The only resemblance it bears to the original is with respect to the
7  ** mechanics of finding various system details. The copyright details
8  ** follow.
9  **
10  ** --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
11  **
12  ** Top users/processes display for Unix
13  ** Version 3
14  **
15  ** This program may be freely redistributed,
16  ** but this entire comment MUST remain intact.
17  **
18  ** Copyright (c) 1984, 1989, William LeFebvre, Rice University
19  ** Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
20  ** Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
21  ** Copyright (c) 1996, William LeFebvre, Group sys Consulting
22  ** Copyright (c) 2002, Associated Universities Inc.
23  */
24 
25 #ifndef CASA_HOSTINFOHPUX_H
26 #define CASA_HOSTINFOHPUX_H
27 
28 # if defined(HOSTINFO_DO_IMPLEMENT)
29 
30 /*
31  * AUTHOR: Darrell Schiebel <drs@nrao.edu>
32  *
33  * ORIGINAL AUTHOR: John Haxby <john_haxby@hp.com>
34  * ORIGINAL CONTRIBUTORS: Rich Holland <holland@synopsys.com>
35  * Kevin Schmidt <kevin@mcl.ucsb.edu>
36  */
37 
38 #include <stdio.h>
39 #include <errno.h>
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <sys/param.h>
43 #include <sys/pstat.h>
44 
45 namespace casacore { //# NAMESPACE CASACORE - BEGIN
46 
47 // <summary>
48 // HostInfo for HP-UX machines.
49 // </summary>
50 
51 // <use visibility=local>
52 
53 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
54 // </reviewed>
55 
56 // <prerequisite>
57 // <li> <linkto class=HostInfo>HostInfo</linkto>
58 // </prerequisite>
59 
60 // <synopsis>
61 // This file provides the HP-UX specific functions for HostInfo.
62 // It is selectively included by HostInfo.cc.
63 // </synopsis>
64 //
65 // <group name="HostInfo">
66 
67 /* these are for getting the memory statistics */
68 
69 /* Log base 2 of 1024 is 10 (2^10 == 1024) */
70 #define LOG1024 10
71 
72 /* define pagetok in terms of pageshift */
73 #define pagetok(size) ((size) << pageshift)
74 
75 class HostMachineInfo {
76 friend class HostInfo;
77 
78  HostMachineInfo( );
79  void update_info( );
80 
81  int valid;
82  int cpus;
83 
84  ptrdiff_t swap_total;
85  ptrdiff_t swap_used;
86  ptrdiff_t swap_free;
87 
88  ptrdiff_t memory_total;
89  ptrdiff_t memory_used;
90  ptrdiff_t memory_free;
91 
92  int pageshift; /* log base 2 of the pagesize */
93 };
94 
95 // </group>
96 
97 
98 HostMachineInfo::HostMachineInfo( ) :valid(1) {
99 
100  struct pst_static info;
101  int pagesize;
102 
103  if (pstat_getstatic (&info, sizeof (info), 1, 0) < 0) {
104  perror ("pstat_getstatic");
105  valid = 0;
106  }
107 
108  /*
109  * Calculate pageshift -- the value needed to convert pages to Kbytes.
110  * This will usually be 2.
111  */
112  pageshift = 0;
113  for (pagesize = info.page_size; pagesize > 1; pagesize >>= 1)
114  pageshift += 1;
115  pageshift -= LOG1024;
116 
117  static struct pst_dynamic dynamic;
118 
119  pstat_getdynamic (&dynamic, sizeof (dynamic), 1, 0);
120  cpus = dynamic.psd_proc_cnt;
121  memory_total = pagetok (dynamic.psd_rm);
122 }
123 
124 void HostMachineInfo::update_info( ) {
125 
126  static struct pst_dynamic dynamic;
127 
128  pstat_getdynamic (&dynamic, sizeof (dynamic), 1, 0);
129  memory_used = pagetok (dynamic.psd_arm);
130  memory_free = memory_total - memory_used;
131  swap_total = pagetok (dynamic.psd_vm);
132  swap_used = pagetok (dynamic.psd_avm);
133  swap_free = swap_total - swap_used;
134 }
135 
136 # endif
137 
138 } //# NAMESPACE CASACORE - END
139 
140 #endif
static HostMachineInfo * info
Definition: HostInfo.h:150
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42