pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/sysutils/top Add DragonFly support based on base version.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2a132429a7ff
branches:  trunk
changeset: 513687:2a132429a7ff
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Jun 01 21:55:28 2006 +0000

description:
Add DragonFly support based on base version.

diffstat:

 sysutils/top/Makefile            |    5 +-
 sysutils/top/distinfo            |    8 +-
 sysutils/top/files/m_dragonfly.c |  879 +++++++++++++++++++++++++++++++++++++++
 sysutils/top/patches/patch-aa    |   13 +
 sysutils/top/patches/patch-ab    |   10 +
 sysutils/top/patches/patch-aj    |    5 +-
 sysutils/top/patches/patch-ak    |    5 +-
 7 files changed, 917 insertions(+), 8 deletions(-)

diffs (truncated from 994 to 300 lines):

diff -r f9bbc88e718d -r 2a132429a7ff sysutils/top/Makefile
--- a/sysutils/top/Makefile     Thu Jun 01 21:16:40 2006 +0000
+++ b/sysutils/top/Makefile     Thu Jun 01 21:55:28 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.31 2005/03/24 21:13:01 wiz Exp $
+# $NetBSD: Makefile,v 1.32 2006/06/01 21:55:28 joerg Exp $
 
 DISTNAME=       top-3.6alpha7
 PKGNAME=       top-3.6a7
@@ -11,4 +11,7 @@
 
 GNU_CONFIGURE=         yes
 
+post-extract:
+       ${CP} ${FILESDIR}/m_dragonfly.c ${WRKSRC}/machine
+
 .include "../../mk/bsd.pkg.mk"
diff -r f9bbc88e718d -r 2a132429a7ff sysutils/top/distinfo
--- a/sysutils/top/distinfo     Thu Jun 01 21:16:40 2006 +0000
+++ b/sysutils/top/distinfo     Thu Jun 01 21:55:28 2006 +0000
@@ -1,10 +1,12 @@
-$NetBSD: distinfo,v 1.10 2005/02/24 13:40:58 agc Exp $
+$NetBSD: distinfo,v 1.11 2006/06/01 21:55:28 joerg Exp $
 
 SHA1 (top-3.6alpha7.tar.gz) = b0336ddc2482b6a52f5345855bf46e0de7d8438a
 RMD160 (top-3.6alpha7.tar.gz) = b5750b2e1c0c5487fa3798b3246984748c836ed2
 Size (top-3.6alpha7.tar.gz) = 295433 bytes
-SHA1 (patch-aj) = 0a15ee8d2581e6150bfdc6c893971147d30cb914
-SHA1 (patch-ak) = 899d1263df15d8389c9391d173369141170ab7ea
+SHA1 (patch-aa) = 2356a4c3a5436750881fb8dff32b6f8bed8ce3bd
+SHA1 (patch-ab) = c9474fb14620202fc641b55189bc11a04e5c8fea
+SHA1 (patch-aj) = aa4b608ad88a9c056a4a4b1b623da4f05eef49dc
+SHA1 (patch-ak) = a845058a1ff3c964f8015263dbbde0356c10eb96
 SHA1 (patch-al) = e9619f30350d9357a2a20a1d509a69eadf2b287e
 SHA1 (patch-am) = 565aa4a0dda8d0171f3f11d4edde79a53677a436
 SHA1 (patch-an) = aa2abb6a2e656ae3a7b379cc5a1867fe673e51e5
diff -r f9bbc88e718d -r 2a132429a7ff sysutils/top/files/m_dragonfly.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/top/files/m_dragonfly.c  Thu Jun 01 21:55:28 2006 +0000
@@ -0,0 +1,879 @@
+/*
+ * top - a top users display for Unix
+ *
+ * SYNOPSIS:  For DragonFly 1.2 and later
+ *
+ * DESCRIPTION:
+ * Originally written for BSD4.4 system by Christos Zoulas.
+ * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider
+ * Order support hacked in from top-3.5beta6/machine/m_aix41.c
+ *   by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/)
+ *
+ * LIBS: -lkvm
+ *
+ * AUTHOR:  Christos Zoulas <christos%ee.cornell.edu@localhost>
+ *          Steven Wallace  <swallace%freebsd.org@localhost>
+ *          Wolfram Schneider <wosch%FreeBSD.org@localhost>
+ *          Hiten Pandya <hmp%backplane.com@localhost>
+ *
+ * $FreeBSD: src/usr.bin/top/machine.c,v 1.29.2.2 2001/07/31 20:27:05 tmm Exp $
+ * $DragonFly: src/usr.bin/top/machine.c,v 1.18 2005/11/14 18:50:18 dillon Exp $
+ * $NetBSD: m_dragonfly.c,v 1.1 2006/06/01 21:55:28 joerg Exp $
+ */
+
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/signal.h>
+#include <sys/param.h>
+
+#include "os.h"
+#include <err.h>
+#include <kvm.h>
+#include <stdio.h>
+#include <math.h>
+#include <pwd.h>
+#include <sys/errno.h>
+#include <sys/sysctl.h>
+#include <sys/file.h>
+#include <sys/time.h>
+#include <sys/user.h>
+#include <sys/vmmeter.h>
+#include <sys/resource.h>
+#include <sys/rtprio.h>
+
+/* Swap */
+#include <stdlib.h>
+#include <sys/conf.h>
+
+#include <osreldate.h> /* for changes in kernel structures */
+
+#include <sys/kinfo.h>
+#include <kinfo.h>
+#include "top.h"
+#include "machine.h"
+
+static int check_nlist(struct nlist *);
+static int getkval(unsigned long, int *, int, char *);
+extern char* printable(char *);
+int swapmode(int *retavail, int *retfree);
+static int smpmode;
+static int namelength;
+static int cmdlength;
+
+/* get_process_info passes back a handle.  This is what it looks like: */
+
+struct handle
+{
+    struct kinfo_proc **next_proc;     /* points to next valid proc pointer */
+    int remaining;             /* number of pointers remaining */
+};
+
+/* declarations for load_avg */
+#include "loadavg.h"
+
+#define PP(pp, field) ((pp)->kp_proc . field)
+#define EP(pp, field) ((pp)->kp_eproc . field)
+#define TP(pp, field) ((pp)->kp_thread . field)
+#define VP(pp, field) ((pp)->kp_eproc.e_vm . field)
+
+/* define what weighted cpu is.  */
+#define weighted_cpu(pct, pp) (PP((pp), p_swtime) == 0 ? 0.0 : \
+                        ((pct) / (1.0 - exp(PP((pp), p_swtime) * logcpu))))
+
+/* what we consider to be process size: */
+#define PROCSIZE(pp) (VP((pp), vm_map.size) / 1024)
+
+/*
+ *  These definitions control the format of the per-process area
+ */
+
+static char smp_header[] =
+  "  PID %-*.*s PRI NICE  SIZE    RES STATE  C   TIME   WCPU    CPU COMMAND";
+
+#define smp_Proc_format \
+       "%5d %-*.*s %3d %3d%7s %6s %-6.6s %1x%7s %5.2f%% %5.2f%% %.*s"
+
+static char up_header[] =
+  "  PID %-*.*s PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND";
+
+#define up_Proc_format \
+       "%5d %-*.*s %3d %3d%7s %6s %-6.6s%.0d%7s %5.2f%% %5.2f%% %.*s"
+
+
+
+/* process state names for the "STATE" column of the display */
+/* the extra nulls in the string "run" are for adding a slash and
+   the processor number when needed */
+
+char *state_abbrev[] =
+{
+    "", "START", "RUN\0\0\0", "SLEEP", "STOP", "ZOMB",
+};
+
+
+static kvm_t *kd;
+
+/* values that we stash away in _init and use in later routines */
+
+static double logcpu;
+
+static long lastpid;
+static long cnt;
+static int ccpu;
+
+/* these are for calculating cpu state percentages */
+
+static struct kinfo_cputime cp_time, cp_old;
+
+/* these are for detailing the process states */
+
+int process_states[6];
+char *procstatenames[] = {
+    "", " starting, ", " running, ", " sleeping, ", " stopped, ",
+    " zombie, ",
+    NULL
+};
+
+/* these are for detailing the cpu states */
+#define CPU_STATES 5
+int cpu_states[CPU_STATES];
+char *cpustatenames[CPU_STATES + 1] = {
+    "user", "nice", "system", "interrupt", "idle", NULL
+};
+
+/* these are for detailing the memory statistics */
+
+int memory_stats[7];
+char *memorynames[] = {
+    "K Active, ", "K Inact, ", "K Wired, ", "K Cache, ", "K Buf, ", "K Free",
+    NULL
+};
+
+int swap_stats[7];
+char *swapnames[] = {
+/*   0           1            2           3            4       5 */
+    "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out",
+    NULL
+};
+
+
+/* these are for keeping track of the proc array */
+
+static int nproc;
+static int onproc = -1;
+static int pref_len;
+static struct kinfo_proc *pbase;
+static struct kinfo_proc **pref;
+
+/* these are for getting the memory statistics */
+
+static int pageshift;          /* log base 2 of the pagesize */
+
+/* define pagetok in terms of pageshift */
+
+#define pagetok(size) ((size) << pageshift)
+
+/* sorting orders. first is default */
+char *ordernames[] = {
+    "cpu", "size", "res", "time", "pri", NULL
+};
+
+/* compare routines */
+int proc_compare(), compare_size(), compare_res(), compare_time(), compare_prio();
+
+int (*proc_compares[])() = {
+    proc_compare,
+    compare_size,
+    compare_res,
+    compare_time,
+    compare_prio,
+    NULL
+};
+
+static void
+cputime_percentages(int out[CPU_STATES], struct kinfo_cputime *new,
+                   struct kinfo_cputime *old)
+{
+        struct kinfo_cputime diffs;
+        int i;
+       uint64_t total_change, half_total;
+
+        /* initialization */
+       total_change = 0;
+
+        diffs.cp_user = new->cp_user - old->cp_user;
+       diffs.cp_nice = new->cp_nice - old->cp_nice;
+       diffs.cp_sys = new->cp_sys - old->cp_sys;
+        diffs.cp_intr = new->cp_intr - old->cp_intr;
+        diffs.cp_idle = new->cp_idle - old->cp_idle;
+       total_change = diffs.cp_user + diffs.cp_nice + diffs.cp_sys +
+           diffs.cp_intr + diffs.cp_idle;
+        old->cp_user = new->cp_user;
+        old->cp_nice = new->cp_nice;
+        old->cp_sys = new->cp_sys;
+        old->cp_intr = new->cp_intr;
+       old->cp_idle = new->cp_idle;
+
+        /* avoid divide by zero potential */
+       if (total_change == 0)
+               total_change = 1;
+
+       /* calculate percentages based on overall change, rounding up */
+        half_total = total_change >> 1;
+
+       out[0] = ((diffs.cp_user * 1000LL + half_total) / total_change);
+        out[1] = ((diffs.cp_nice * 1000LL + half_total) / total_change);
+       out[2] = ((diffs.cp_sys * 1000LL + half_total) / total_change);
+        out[3] = ((diffs.cp_intr * 1000LL + half_total) / total_change);
+       out[4] = ((diffs.cp_idle * 1000LL + half_total) / total_change);
+}
+
+int
+machine_init(struct statics *statics)
+{
+    register int i = 0;
+    register int pagesize;
+    size_t modelen;
+    struct passwd *pw;
+    struct timeval boottime;
+    int mib[2];
+    size_t bt_size;
+
+    modelen = sizeof(smpmode);
+    if ((sysctlbyname("machdep.smp_active", &smpmode, &modelen, NULL, 0) < 0 &&
+         sysctlbyname("smp.smp_active", &smpmode, &modelen, NULL, 0) < 0) ||
+       modelen != sizeof(smpmode))
+           smpmode = 0;
+
+    while ((pw = getpwent()) != NULL) {
+       if (strlen(pw->pw_name) > namelength)
+           namelength = strlen(pw->pw_name);
+    }
+    if (namelength < 8)
+       namelength = 8;
+    if (smpmode && namelength > 13)
+       namelength = 13;
+    else if (namelength > 15)
+       namelength = 15;
+
+    if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)



Home | Main Index | Thread Index | Old Index