|
Packit Service |
407539 |
/*
|
|
Packit Service |
407539 |
This file is part of LibGTop 2.0.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is free software; you can redistribute it and/or modify it
|
|
Packit Service |
407539 |
under the terms of the GNU General Public License as published by
|
|
Packit Service |
407539 |
the Free Software Foundation; either version 2 of the License,
|
|
Packit Service |
407539 |
or (at your option) any later version.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
407539 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit Service |
407539 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit Service |
407539 |
for more details.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
407539 |
along with LibGTop; see the file COPYING. If not, write to the
|
|
Packit Service |
407539 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
407539 |
Boston, MA 02110-1301, USA.
|
|
Packit Service |
407539 |
*/
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <config.h>
|
|
Packit Service |
407539 |
#include <unistd.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glibtop.h>
|
|
Packit Service |
407539 |
#include <glibtop/error.h>
|
|
Packit Service |
407539 |
#include <glibtop/mem.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glibtop_suid.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <mach/mach_init.h>
|
|
Packit Service |
407539 |
#include <mach/mach_host.h>
|
|
Packit Service |
407539 |
#include <mach/host_info.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
static const unsigned long _glibtop_sysdeps_mem =
|
|
Packit Service |
407539 |
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
|
|
Packit Service |
407539 |
(1L << GLIBTOP_MEM_FREE);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Init function. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
void
|
|
Packit Service |
407539 |
_glibtop_init_mem_p (glibtop *server)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Provides information about memory usage. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
void
|
|
Packit Service |
407539 |
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
vm_statistics_data_t vm_info;
|
|
Packit Service |
407539 |
mach_msg_type_number_t info_count;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MEM), 0);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
memset (buf, 0, sizeof (glibtop_mem));
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
info_count = HOST_VM_INFO_COUNT;
|
|
Packit Service |
407539 |
if (host_statistics (mach_host_self (), HOST_VM_INFO,
|
|
Packit Service |
407539 |
(host_info_t)&vm_info, &info_count)) {
|
|
Packit Service |
407539 |
glibtop_warn_io_r (server, "host_statistics (vm_statistics)");
|
|
Packit Service |
407539 |
return;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
buf->total = (vm_info.active_count + vm_info.inactive_count +
|
|
Packit Service |
407539 |
vm_info.free_count + vm_info.wire_count) * vm_page_size;
|
|
Packit Service |
407539 |
buf->free = vm_info.free_count * vm_page_size;
|
|
Packit Service |
407539 |
buf->used = buf->total - buf->free;
|
|
Packit Service |
407539 |
buf->flags = _glibtop_sysdeps_mem;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|