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