diff --git a/examples/ChangeLog b/examples/ChangeLog index ade9ce5a..48a2820c 100644 --- a/examples/ChangeLog +++ b/examples/ChangeLog @@ -1,3 +1,7 @@ +1998-11-02 Martin Baulig + + * sysdeps.c: New example. + 1998-10-26 Martin Baulig * netload.c: New file. Gets network load for the interface diff --git a/examples/Makefile.am b/examples/Makefile.am index f1ada8ec..daeb557b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -12,14 +12,13 @@ DEFS = @DEFS@ libgtopdir = $(libexecdir)/libgtop libgtop_PROGRAMS = first second\ - mountlist procmap netload \ - @static_targets@ \ - @guile_examples@ @smp_examples@ + mountlist procmap netload sysdeps\ + @static_targets@ @guile_examples@ @smp_examples@ EXTRA_PROGRAMS = first_static second_static \ mountlist_static procmap_static \ third third_static smp smp_static \ - netload_static + netload_static sysdeps_static first_SOURCES = first.c first_LDADD = $(top_builddir)/lib/libgtop.la \ @@ -63,7 +62,15 @@ netload_static_SOURCES = $(netload_SOURCES) netload_static_LDADD = $(netload_LDADD) netload_static_LDFLAGS = -static +sysdeps_SOURCES = sysdeps.c +sysdeps_LDADD = $(top_builddir)/lib/libgtop.la \ + $(top_builddir)/sysdeps/common/libgtop_common.la \ + $(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \ + @INTLLIBS@ @LIBSUPPORT@ +sysdeps_static_SOURCES = $(sysdeps_SOURCES) +sysdeps_static_LDADD = $(sysdeps_LDADD) +sysdeps_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 diff --git a/examples/first.c b/examples/first.c index 87b69a6f..9ad1ec5f 100644 --- a/examples/first.c +++ b/examples/first.c @@ -43,7 +43,8 @@ main (int argc, char *argv []) glibtop_union data; glibtop_sysdeps sysdeps; unsigned c, method, count, port, i, *ptr; - char buffer [BUFSIZ], *args; + char buffer [BUFSIZ]; + const char *args; pid_t pid, ppid; count = PROFILE_COUNT; @@ -186,7 +187,8 @@ main (int argc, char *argv []) glibtop_get_sysdeps (&sysdeps); printf ("Sysdeps (0x%08lx): %lu, %lu, %lu, %lu, %lu, " - "%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n", + "%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, " + "%lu, %lu, %lu, %lu, %lu, %lu\n", (unsigned long) sysdeps.flags, (unsigned long) sysdeps.cpu, (unsigned long) sysdeps.mem, @@ -203,7 +205,13 @@ main (int argc, char *argv []) (unsigned long) sysdeps.proc_time, (unsigned long) sysdeps.proc_signal, (unsigned long) sysdeps.proc_kernel, - (unsigned long) sysdeps.proc_segment); + (unsigned long) sysdeps.proc_segment, + (unsigned long) sysdeps.proc_args, + (unsigned long) sysdeps.proc_map, + (unsigned long) sysdeps.mountlist, + (unsigned long) sysdeps.fsusage, + (unsigned long) sysdeps.netload, + (unsigned long) sysdeps.ppp); printf ("\n"); diff --git a/examples/sysdeps.c b/examples/sysdeps.c new file mode 100644 index 00000000..8af1d58d --- /dev/null +++ b/examples/sysdeps.c @@ -0,0 +1,146 @@ +/* $Id$ */ + +/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the Gnome Top Library. + Contributed by Martin Baulig , 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 + +#include +#include +#include +#include + +#include + +#ifndef PROFILE_COUNT +#define PROFILE_COUNT 1 +#endif + +int +main (int argc, char *argv []) +{ + glibtop_sysdeps sysdeps; + unsigned method, count, port, i; + char buffer [BUFSIZ]; + + 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); + + glibtop_get_sysdeps (&sysdeps); + +#define FEATURE_CHECK(f) ((sysdeps.features & (1 << GLIBTOP_SYSDEPS_##f##)) ? 1 : 0) + + printf ("Sysdeps (0x%08lx):\n\n" + "\tfeatures:\t\t0x%08lx\n\n" + "\tcpu:\t\t%d\t0x%08lx\n" + "\tmem:\t\t%d\t0x%08lx\n" + "\tswap:\t\t%d\t0x%08lx\n\n" + "\tuptime:\t\t%d\t0x%08lx\n" + "\tloadavg:\t%d\t0x%08lx\n\n" + "\tshm_limits:\t%d\t0x%08lx\n" + "\tmsg_limits:\t%d\t0x%08lx\n" + "\tsem_limits:\t%d\t0x%08lx\n\n" + "\tproclist:\t%d\t0x%08lx\n\n" + "\tproc_state:\t%d\t0x%08lx\n" + "\tproc_uid:\t%d\t0x%08lx\n" + "\tproc_mem:\t%d\t0x%08lx\n" + "\tproc_time:\t%d\t0x%08lx\n" + "\tproc_signal:\t%d\t0x%08lx\n" + "\tproc_kernel:\t%d\t0x%08lx\n" + "\tproc_segment:\t%d\t0x%08lx\n\n" + "\tproc_args:\t%d\t0x%08lx\n" + "\tproc_map:\t%d\t0x%08lx\n\n" + "\tmountlist:\t%d\t0x%08lx\n" + "\tfsusage:\t%d\t0x%08lx\n\n" + "\tnetload:\t%d\t0x%08lx\n" + "\tppp:\t\t%d\t0x%08lx\n\n", + (unsigned long) sysdeps.flags, + (unsigned long) sysdeps.features, + FEATURE_CHECK(CPU), + (unsigned long) sysdeps.cpu, + FEATURE_CHECK(MEM), + (unsigned long) sysdeps.mem, + FEATURE_CHECK(SWAP), + (unsigned long) sysdeps.swap, + FEATURE_CHECK(UPTIME), + (unsigned long) sysdeps.uptime, + FEATURE_CHECK(LOADAVG), + (unsigned long) sysdeps.loadavg, + FEATURE_CHECK(SHM_LIMITS), + (unsigned long) sysdeps.shm_limits, + FEATURE_CHECK(MSG_LIMITS), + (unsigned long) sysdeps.msg_limits, + FEATURE_CHECK(SEM_LIMITS), + (unsigned long) sysdeps.sem_limits, + FEATURE_CHECK(PROCLIST), + (unsigned long) sysdeps.proclist, + FEATURE_CHECK(PROC_STATE), + (unsigned long) sysdeps.proc_state, + FEATURE_CHECK(PROC_UID), + (unsigned long) sysdeps.proc_uid, + FEATURE_CHECK(PROC_MEM), + (unsigned long) sysdeps.proc_mem, + FEATURE_CHECK(PROC_TIME), + (unsigned long) sysdeps.proc_time, + FEATURE_CHECK(PROC_SIGNAL), + (unsigned long) sysdeps.proc_signal, + FEATURE_CHECK(PROC_KERNEL), + (unsigned long) sysdeps.proc_kernel, + FEATURE_CHECK(PROC_SEGMENT), + (unsigned long) sysdeps.proc_segment, + FEATURE_CHECK(PROC_ARGS), + (unsigned long) sysdeps.proc_args, + FEATURE_CHECK(PROC_MAP), + (unsigned long) sysdeps.proc_map, + FEATURE_CHECK(MOUNTLIST), + (unsigned long) sysdeps.mountlist, + FEATURE_CHECK(FSUSAGE), + (unsigned long) sysdeps.fsusage, + FEATURE_CHECK(NETLOAD), + (unsigned long) sysdeps.netload, + FEATURE_CHECK(PPP), + (unsigned long) sysdeps.ppp); + + glibtop_close (); + + exit (0); +}