New file. Added definition of `proc_map'.

1998-08-10  Martin Baulig  <martin@home-of-linux.org>

	* include/glibtop/procmap.h (glibtop_proc_map): New file.
	* features.def: Added definition of `proc_map'.
This commit is contained in:
Martin Baulig
1998-08-10 16:57:44 +00:00
committed by Martin Baulig
parent b6885555c1
commit d9361d388c
24 changed files with 552 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ DEFS = @DEFS@
bin_PROGRAMS = first first_static second second_static \
mountlist mountlist_static \
procmap procmap_static \
@guile_examples@
EXTRA_PROGRAMS = third third_static
@@ -32,6 +33,18 @@ second_static_SOURCES = $(second_SOURCES)
second_static_LDADD = $(second_LDADD)
second_static_LDFLAGS = -static
procmap_SOURCES = procmap.c
procmap_LDADD = $(top_builddir)/lib/libgtop.la \
$(top_builddir)/sysdeps/common/libgtop_common.la \
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
procmap_static_SOURCES = $(procmap_SOURCES)
procmap_static_LDADD = $(procmap_LDADD)
procmap_static_LDFLAGS = -static
third_guile_names_LIBS = $(top_builddir)/sysdeps/guile/names/libgtop_guile_names.la
third_names_LIBS = $(top_builddir)/sysdeps/names/libgtop_names.la

View File

@@ -32,6 +32,7 @@
#include <glibtop/sysdeps.h>
#include <sys/resource.h>
#include <sys/mman.h>
#ifndef PROFILE_COUNT
#define PROFILE_COUNT 1
@@ -43,10 +44,12 @@ main (int argc, char *argv [])
glibtop_union data;
glibtop_sysdeps sysdeps;
unsigned c, method, count, port, i, *ptr;
char buffer [BUFSIZ];
char buffer [BUFSIZ], *mmap_ptr;
struct rlimit rlim;
struct rusage ru;
struct stat statb;
pid_t pid, ppid;
int fd;
count = PROFILE_COUNT;
@@ -74,6 +77,18 @@ main (int argc, char *argv [])
glibtop_init_r (&glibtop_global_server, 0, 0);
fd = open ("/COPYRIGHT", O_RDONLY);
if (!fd) glibtop_error_io ("open (/COPYRIGHT)");
if (stat ("/COPYRIGHT", &statb))
glibtop_error_io ("stat (/COPYRIGHT)");
mmap_ptr = mmap (NULL, statb.st_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE, fd, 0);
if (!mmap_ptr) glibtop_error_io ("mmap (/COPYRIGHT)");
fprintf (stderr, "MMAP: %p - %lu\n", mmap_ptr, statb.st_size);
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_cpu (&data.cpu);
@@ -247,6 +262,20 @@ main (int argc, char *argv [])
(unsigned long) rlim.rlim_max,
(unsigned long) ((1 << 63) - 1));
printf ("Proc_Mem PID %5u (0x%08lx): "
"%lu %lu %lu %lu %lu %lu\n", pid,
(unsigned long) data.proc_mem.flags,
(unsigned long) data.proc_mem.size,
(unsigned long) data.proc_mem.vsize,
(unsigned long) data.proc_mem.resident,
(unsigned long) data.proc_mem.share,
(unsigned long) data.proc_mem.rss,
(unsigned long) data.proc_mem.rss_rlim);
mmap_ptr [0] = 'M';
glibtop_get_proc_mem (&data.proc_mem, pid);
printf ("Proc_Mem PID %5u (0x%08lx): "
"%lu %lu %lu %lu %lu %lu\n", pid,
(unsigned long) data.proc_mem.flags,

96
examples/procmap.c Normal file
View File

@@ -0,0 +1,96 @@
/* $Id$ */
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the Gnome Top Library.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
The Gnome Top Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Top Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <locale.h>
#include <glibtop.h>
#include <glibtop/open.h>
#include <glibtop/close.h>
#include <glibtop/xmalloc.h>
#include <glibtop/parameter.h>
#include <glibtop/procmap.h>
#include <sys/resource.h>
#include <sys/mman.h>
#ifndef PROFILE_COUNT
#define PROFILE_COUNT 1
#endif
int
main (int argc, char *argv [])
{
glibtop_proc_map procmap;
glibtop_map_entry *maps;
unsigned method, count, port, i, *ptr;
char buffer [BUFSIZ];
pid_t pid;
count = PROFILE_COUNT;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, GTOPLOCALEDIR);
textdomain (PACKAGE);
glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);
glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));
printf ("Method = %d\n", method);
count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
buffer [count] = 0;
printf ("Command = '%s'\n", buffer);
count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
buffer [count] = 0;
glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));
printf ("Host = '%s' - %u\n\n", buffer, port);
glibtop_init_r (&glibtop_global_server, 0, 0);
if ((argc != 2) || (sscanf (argv [1], "%d", &pid) != 1))
glibtop_error ("Usage: %s pid", argv [0]);
fprintf (stderr, "Getting memory maps for pid %d.\n\n", pid);
maps = glibtop_get_proc_map (&procmap, pid);
for (i = 0; i < procmap.number; i++) {
fprintf (stderr, "%08x - %08x - %08lu - %08lu - '%s'\n",
(unsigned long) maps [i].start,
(unsigned long) maps [i].end,
(unsigned long) maps [i].device,
(unsigned long) maps [i].inode,
devname (maps [i].device, S_IFBLK));
}
glibtop_free (maps);
glibtop_close ();
exit (0);
}