casacore
Loading...
Searching...
No Matches
HostInfoBsd.h
Go to the documentation of this file.
1//# Copyright (C) 2009
2//# Associated Universities, Inc. Washington DC, USA.
3//#
4//# This library is free software; you can redistribute it and/or modify it
5//# under the terms of the GNU Library General Public License as published by
6//# the Free Software Foundation; either version 2 of the License, or (at your
7//# option) any later version.
8//#
9//# This library is distributed in the hope that it will be useful, but WITHOUT
10//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12//# License for more details.
13//#
14//# You should have received a copy of the GNU Library General Public License
15//# along with this library; if not, write to the Free Software Foundation,
16//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17//#
18//# Correspondence concerning AIPS++ should be addressed as follows:
19//# Internet email: casa-feedback@nrao.edu.
20//# Postal address: AIPS++ Project Office
21//# National Radio Astronomy Observatory
22//# 520 Edgemont Road
23//# Charlottesville, VA 22903-2475 USA
24/*
25** Author Tony Maher
26**
27** Based on HostInfoDarwin.h (just the scaffolding code).
28*/
29
30#ifndef CASA_HOSTINFOBSD_H
31#define CASA_HOSTINFOBSD_H
32
33# if defined(HOSTINFO_DO_IMPLEMENT)
34
35#include <sys/types.h>
36#include <sys/sysctl.h>
37#include <sys/vmmeter.h> // struct vmtotal
38
39#include <fcntl.h>
40#include <kvm.h>
41#include <paths.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <unistd.h>
45
46
47namespace casacore { //# NAMESPACE CASACORE - BEGIN
48
49// <summary>
50// HostInfo for BSD (FreeBSD) machines.
51// </summary>
52
53// <use visibility=local>
54
55// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
56// </reviewed>
57
58// <prerequisite>
59// <li> <linkto class=HostInfo>HostInfo</linkto>
60// </prerequisite>
61
62// <synopsis>
63// This file provides the BSD (FreeBSD) specific functions for HostInfo.
64// It is selectively included by HostInfo.cc.
65// </synopsis>
66//
67// <group name="HostInfo">
68
69// these are for getting the memory statistics
70static int pagesize;
71static int page_kb;
72
73class HostMachineInfo {
74friend class HostInfo;
75
76 HostMachineInfo( );
77 void update_info( );
78
79 int valid;
80 int cpus;
81
82 ptrdiff_t memory_total;
83 ptrdiff_t memory_used;
84 ptrdiff_t memory_free;
85
86 ptrdiff_t swap_total;
87 ptrdiff_t swap_used;
88 ptrdiff_t swap_free;
89};
90
91// </group>
92
93
94HostMachineInfo::HostMachineInfo( ) : valid(1) {
95 size_t len;
96
97 pagesize = getpagesize(); // size of page in bytes.
98 page_kb = pagesize / 1024; // in kilobytes.
99
100 len = sizeof(cpus);
101 if (sysctlbyname("hw.ncpu", &cpus, &len, NULL, 0) == -1)
102 perror("sysctl");
103
104 len = sizeof(memory_total);
105 if (sysctlbyname("hw.physmem", &memory_total, &len, NULL, 0) == -1)
106 perror("sysctl");
107 else
108 memory_total /= 1024; // in kilobytes
109}
110
111
112void HostMachineInfo::update_info( ) {
113 size_t len;
114 kvm_t *kd;
115 struct vmtotal total;
116 struct kvm_swap swapary[1];
117
118 // Memory and swap values are in pages.
119
120 len = sizeof(total);
121 if (sysctlbyname("vm.vmtotal", &total, &len, NULL, 0) == -1)
122 perror("sysctl");
123 else
124 memory_used = total.t_rm * page_kb;
125 memory_free = total.t_free * page_kb;
126
127 kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
128 if (kd != NULL) {
129 kvm_getswapinfo(kd, swapary, 1, 0);
130
131 swap_total = swapary[0].ksw_total * page_kb;
132 swap_used = swapary[0].ksw_used * page_kb;
133 swap_free = swap_total - swap_used;
134 }
135}
136
137
138} //# NAMESPACE CASACORE - END
139
140# endif
141#endif
this file contains all the compiler specific defines
Definition mainpage.dox:28