Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/top On MP systems, print a line for each cpu describ...
details: https://anonhg.NetBSD.org/src/rev/b0c471659687
branches: trunk
changeset: 552800:b0c471659687
user: christos <christos%NetBSD.org@localhost>
date: Fri Oct 03 15:32:06 2003 +0000
description:
On MP systems, print a line for each cpu describing cpustate.
diffstat:
usr.bin/top/display.c | 127 ++++++++++++++++++++------------------
usr.bin/top/layout.h | 14 ++--
usr.bin/top/machine.h | 3 +-
usr.bin/top/machine/m_netbsd15.c | 61 +++++++++++++++---
usr.bin/top/top.c | 8 +-
usr.bin/top/top.h | 4 +-
6 files changed, 133 insertions(+), 84 deletions(-)
diffs (truncated from 460 to 300 lines):
diff -r 5ccf63e10fbb -r b0c471659687 usr.bin/top/display.c
--- a/usr.bin/top/display.c Fri Oct 03 14:54:20 2003 +0000
+++ b/usr.bin/top/display.c Fri Oct 03 15:32:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: display.c,v 1.10 2003/06/23 13:05:52 agc Exp $ */
+/* $NetBSD: display.c,v 1.11 2003/10/03 15:32:06 christos Exp $ */
/*
* Top users/processes display for Unix
@@ -47,7 +47,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: display.c,v 1.10 2003/06/23 13:05:52 agc Exp $");
+__RCSID("$NetBSD: display.c,v 1.11 2003/10/03 15:32:06 christos Exp $");
#endif
#include "os.h"
@@ -75,6 +75,7 @@
static int last_hi = 0; /* used in u_process and u_endscreen */
static int lastline = 0;
static int display_width = MAX_COLS;
+static int ncpu = 0;
#define lineindex(l) ((l)*display_width)
@@ -154,6 +155,7 @@
register int *ip;
register int i;
+ ncpu = statics->ncpu;
/* call resize to do the dirty work */
lines = display_resize();
@@ -167,7 +169,7 @@
cpustate_names = statics->cpustate_names;
num_cpustates = string_count(cpustate_names);
- lcpustates = (int *)malloc(num_cpustates * sizeof(int));
+ lcpustates = (int *)malloc(num_cpustates * sizeof(int) * ncpu);
cpustate_columns = (int *)malloc(num_cpustates * sizeof(int));
memory_names = statics->memory_names;
@@ -403,12 +405,13 @@
{
register char *use;
- static char *short_tag = "CPU: ";
- static char *long_tag = "CPU states: ";
+ char *short_tag = ncpu > 1 ? "\nCPU%d: " : "\nCPU: ";
+ char *long_tag = ncpu > 1 ? "\nCPU%d states: " : "\nCPU states: ";
/* if length + strlen(long_tag) >= screen_width, then we have to
use the shorter tag (we subtract 2 to account for ": ") */
- if (cpustate_total_length + (int)strlen(long_tag) - 2 >= screen_width)
+ if (cpustate_total_length + (int)strlen(long_tag) -
+ (ncpu > 1 ? 5 : 2) >= screen_width)
{
use = short_tag;
}
@@ -418,7 +421,7 @@
}
/* set cpustates_column accordingly then return result */
- cpustates_column = strlen(use);
+ cpustates_column = strlen(use) - (ncpu > 1 ? 2 : 1);
return(use);
}
@@ -428,33 +431,35 @@
register int *states;
{
- register int i = 0;
+ register int i, c;
register int value;
register char **names = cpustate_names;
register char *thisname;
- /* print tag and bump lastline */
- printf("\n%s", cpustates_tag());
- lastline++;
+ /* copy over values into "last" array */
+ memcpy(lcpustates, states, num_cpustates * sizeof(int) * ncpu);
- /* now walk thru the names and print the line */
- while ((thisname = *names++) != NULL)
+ for (c = 0; c < ncpu; c++)
{
- if (*thisname != '\0')
+ /* print tag and bump lastline */
+ printf(cpustates_tag(), c);
+ lastline++;
+ /* now walk thru the names and print the line */
+ for (i = 0, names = cpustate_names; ((thisname = *names++) != NULL);)
{
- /* retrieve the value and remember it */
- value = *states++;
+ if (*thisname != '\0')
+ {
+ /* retrieve the value and remember it */
+ value = *states++;
- /* if percentage is >= 1000, print it as 100% */
- printf((value >= 1000 ? "%s%4.0f%% %s" : "%s%4.1f%% %s"),
- i++ == 0 ? "" : ", ",
- ((float)value)/10.,
- thisname);
+ /* if percentage is >= 1000, print it as 100% */
+ printf((value >= 1000 ? "%s%4.0f%% %s" : "%s%4.1f%% %s"),
+ i++ == 0 ? "" : ", ",
+ ((float)value)/10.,
+ thisname);
+ }
}
}
-
- /* copy over values into "last" array */
- memcpy(lcpustates, states, num_cpustates * sizeof(int));
}
void
@@ -464,44 +469,47 @@
{
register int value;
- register char **names = cpustate_names;
+ register char **names;
register char *thisname;
- register int *lp;
+ register int *lp = lcpustates;
register int *colp;
+ register int c;
Move_to(cpustates_column, y_cpustates);
lastline = y_cpustates;
- lp = lcpustates;
- colp = cpustate_columns;
- /* we could be much more optimal about this */
- while ((thisname = *names++) != NULL)
+ for (c = 0; c < ncpu; c++)
{
- if (*thisname != '\0')
+ colp = cpustate_columns;
+ /* we could be much more optimal about this */
+ for (names = cpustate_names; (thisname = *names++) != NULL;)
{
- /* did the value change since last time? */
- if (*lp != *states)
+ if (*thisname != '\0')
{
- /* yes, move and change */
- Move_to(cpustates_column + *colp, y_cpustates);
- lastline = y_cpustates;
+ /* did the value change since last time? */
+ if (*lp != *states)
+ {
+ /* yes, move and change */
+ lastline = y_cpustates + c;
+ Move_to(cpustates_column + *colp, lastline);
- /* retrieve value and remember it */
- value = *states;
+ /* retrieve value and remember it */
+ value = *states;
- /* if percentage is >= 1000, print it as 100% */
- printf((value >= 1000 ? "%4.0f" : "%4.1f"),
- ((double)value)/10.);
+ /* if percentage is >= 1000, print it as 100% */
+ printf((value >= 1000 ? "%4.0f" : "%4.1f"),
+ ((double)value)/10.);
- /* remember it for next time */
- *lp = value;
+ /* remember it for next time */
+ *lp = value;
+ }
}
- }
- /* increment and move on */
- lp++;
- states++;
- colp++;
+ /* increment and move on */
+ lp++;
+ states++;
+ colp++;
+ }
}
}
@@ -509,26 +517,27 @@
z_cpustates()
{
- register int i = 0;
+ register int i, c;
register char **names = cpustate_names;
register char *thisname;
- register int *lp;
-
- /* show tag and bump lastline */
- printf("\n%s", cpustates_tag());
- lastline++;
+ register int *lp = lcpustates;
- while ((thisname = *names++) != NULL)
+ for (c = 0; c < ncpu; c++)
{
- if (*thisname != '\0')
+ /* show tag and bump lastline */
+ printf(cpustates_tag(), c);
+ lastline++;
+ for (i = 0, names = cpustate_names; (thisname = *names++) != NULL;)
{
- printf("%s %% %s", i++ == 0 ? "" : ", ", thisname);
+ if (*thisname != '\0')
+ {
+ printf("%s %% %s", i++ == 0 ? "" : ", ", thisname);
+ }
}
}
/* fill the "last" array with all -1s, to insure correct updating */
- lp = lcpustates;
- i = num_cpustates;
+ i = num_cpustates * ncpu;
while (--i >= 0)
{
*lp++ = -1;
diff -r 5ccf63e10fbb -r b0c471659687 usr.bin/top/layout.h
--- a/usr.bin/top/layout.h Fri Oct 03 14:54:20 2003 +0000
+++ b/usr.bin/top/layout.h Fri Oct 03 15:32:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: layout.h,v 1.4 2002/07/16 00:40:51 itojun Exp $ */
+/* $NetBSD: layout.h,v 1.5 2003/10/03 15:32:06 christos Exp $ */
/*
* Top users/processes display for Unix
@@ -46,14 +46,14 @@
#define x_brkdn 15
#define y_brkdn 1
#define x_mem 8
-#define y_mem 3
+#define y_mem (2 + ncpu)
#define x_swap 6
-#define y_swap 4
-#define y_message 5
+#define y_swap (3 + ncpu)
+#define y_message (4 + ncpu)
#define x_header 0
-#define y_header 6
+#define y_header (5 + ncpu)
#define x_idlecursor 0
-#define y_idlecursor 5
-#define y_procs 7
+#define y_idlecursor (4 + ncpu)
+#define y_procs (6 + ncpu)
#define y_cpustates 2
diff -r 5ccf63e10fbb -r b0c471659687 usr.bin/top/machine.h
--- a/usr.bin/top/machine.h Fri Oct 03 14:54:20 2003 +0000
+++ b/usr.bin/top/machine.h Fri Oct 03 15:32:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machine.h,v 1.7 2002/07/16 00:40:51 itojun Exp $ */
+/* $NetBSD: machine.h,v 1.8 2003/10/03 15:32:06 christos Exp $ */
/*
* Top users/processes display for Unix
@@ -46,6 +46,7 @@
#ifdef ORDER
char **order_names;
#endif
+ int ncpu;
};
/*
diff -r 5ccf63e10fbb -r b0c471659687 usr.bin/top/machine/m_netbsd15.c
--- a/usr.bin/top/machine/m_netbsd15.c Fri Oct 03 14:54:20 2003 +0000
+++ b/usr.bin/top/machine/m_netbsd15.c Fri Oct 03 15:32:06 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: m_netbsd15.c,v 1.19 2003/07/26 20:34:14 salo Exp $ */
+/* $NetBSD: m_netbsd15.c,v 1.20 2003/10/03 15:32:06 christos Exp $ */
/*
* top - a top users display for Unix
@@ -16,9 +16,9 @@
* -
* This is the machine-dependent module for NetBSD-1.5 and later
* works for:
- * NetBSD-1.5ZC
+ * NetBSD-1.6ZC
* and should work for:
- * NetBSD-1.6 (when released)
+ * NetBSD-2.0 (when released)
* -
* top does not need to be installed setuid or setgid with this module.
Home |
Main Index |
Thread Index |
Old Index