2 * Copyright (c) 2003 Benjamin Reed <ranger@befunk.com>
4 * memory_osx.cpp is part of the KDE program kcminfo. Copied wholesale
5 * from memory_fbsd.cpp =)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <mach/mach_init.h>
26 #include <mach/mach_host.h>
27 #include <mach/host_info.h>
32 void KCMMemory::fetchValues()
35 vm_statistics_data_t vm_info
;
36 mach_msg_type_number_t info_count
;
41 info_count
= HOST_VM_INFO_COUNT
;
42 if (host_statistics(mach_host_self (), HOST_VM_INFO
, (host_info_t
)&vm_info
, &info_count
)) {
43 kDebug() << "could not get memory statistics";
47 memoryInfos
[TOTAL_MEM
] = MEMORY(vm_info
.active_count
+ vm_info
.inactive_count
+
48 vm_info
.free_count
+ vm_info
.wire_count
) * vm_page_size
;
49 memoryInfos
[FREE_MEM
] = MEMORY(vm_info
.free_count
) * vm_page_size
;
50 memoryInfos
[SHARED_MEM
] = NO_MEMORY_INFO
;
51 memoryInfos
[BUFFER_MEM
] = NO_MEMORY_INFO
;
52 memoryInfos
[CACHED_MEM
] = NO_MEMORY_INFO
;
54 dirp
= opendir("/private/var/vm");
56 kDebug() << "unable to open /private/var/vm";
62 while ((dp
= readdir (dirp
)) != NULL
) {
64 char fname
[MAXNAMLEN
];
66 if (strncmp (dp
->d_name
, "swapfile", 8))
69 strcpy (fname
, "/private/var/vm/");
70 strcat (fname
, dp
->d_name
);
71 if (stat (fname
, &sb
) < 0)
78 info_count
= HOST_VM_INFO_COUNT
;
79 if (host_statistics (mach_host_self (), HOST_VM_INFO
,
80 (host_info_t
) &vm_info
, &info_count
)) {
81 kDebug() << "unable to get VM info";
84 memoryInfos
[SWAP_MEM
] = total
;
85 // off_t used = (vm_info.pageouts - vm_info.pageins) * vm_page_size;
86 memoryInfos
[FREESWAP_MEM
] = NO_MEMORY_INFO
;
88 /* free = MEMORY(vm_info.free_count) * vm_page_size;
89 used = MEMORY(vm_info.active_count) * vm_page_size;
90 total = MEMORY(vm_info.active_count + vm_info.inactive_count +
91 vm_info.free_count + vm_info.wire_count) * vm_page_size; */