diff options
author | John Baldwin <jhb@FreeBSD.org> | 2011-07-18 21:15:47 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2011-07-18 21:15:47 +0000 |
commit | fcc3d62fa50d0433048a71d54e385ef75ec06011 (patch) | |
tree | 51cdc1a8e25efa9aaf2fc32d7b692e155c57606c | |
parent | 834377fe2ded06485f80a727846e990622f56f71 (diff) | |
download | src-fcc3d62fa50d0433048a71d54e385ef75ec06011.tar.gz src-fcc3d62fa50d0433048a71d54e385ef75ec06011.zip |
Notes
-rw-r--r-- | contrib/top/display.c | 16 | ||||
-rw-r--r-- | contrib/top/top.c | 2 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 8 |
3 files changed, 18 insertions, 8 deletions
diff --git a/contrib/top/display.c b/contrib/top/display.c index a5a4e9e9f423..89795c05e4da 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -156,18 +156,30 @@ int display_updatecpus(statics) struct statics *statics; { + register int *lp; register int lines; register int i; /* call resize to do the dirty work */ lines = display_resize(); - num_cpus = statics->ncpus; + if (pcpu_stats) + num_cpus = statics->ncpus; + else + num_cpus = 1; cpustates_column = 5; /* CPU: */ if (num_cpus != 1) cpustates_column += 2; /* CPU 0: */ for (i = num_cpus; i > 9; i /= 10) cpustates_column++; + /* fill the "last" array with all -1s, to insure correct updating */ + lp = lcpustates; + i = num_cpustates * num_cpus; + while (--i >= 0) + { + *lp++ = -1; + } + return(lines); } @@ -197,7 +209,7 @@ struct statics *statics; num_swap = string_count(swap_names); lswap = (int *)malloc(num_swap * sizeof(int)); num_cpustates = string_count(cpustate_names); - lcpustates = (int *)malloc(num_cpustates * sizeof(int) * num_cpus); + lcpustates = (int *)malloc(num_cpustates * sizeof(int) * statics->ncpus); cpustate_columns = (int *)malloc(num_cpustates * sizeof(int)); memory_names = statics->memory_names; diff --git a/contrib/top/top.c b/contrib/top/top.c index 1a017a3cd20b..e7e27d54a978 100644 --- a/contrib/top/top.c +++ b/contrib/top/top.c @@ -1094,7 +1094,7 @@ restart: new_message(MT_standout | MT_delayed, " Displaying %sCPU statistics.", pcpu_stats ? "per-" : "global "); - toggle_pcpustats(&statics); + toggle_pcpustats(); max_topn = display_updatecpus(&statics); reset_display(); putchar('\r'); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 5e53d5b36ed8..b815ffc67e70 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -241,7 +241,7 @@ static void getsysctl(const char *name, void *ptr, size_t len); static int swapmode(int *retavail, int *retfree); void -toggle_pcpustats(struct statics *statics) +toggle_pcpustats(void) { if (ncpus == 1) @@ -256,7 +256,6 @@ toggle_pcpustats(struct statics *statics) y_header += ncpus - 1; /* 6 */ y_procs += ncpus - 1; /* 7 */ Header_lines += ncpus - 1; /* 7 */ - statics->ncpus = ncpus; } else { y_mem = 3; y_swap = 4; @@ -265,7 +264,6 @@ toggle_pcpustats(struct statics *statics) y_header = 6; y_procs = 7; Header_lines = 7; - statics->ncpus = 1; } } @@ -356,10 +354,10 @@ machine_init(struct statics *statics, char do_unames) pcpu_cp_old = calloc(1, size); pcpu_cp_diff = calloc(1, size); pcpu_cpu_states = calloc(1, size); - statics->ncpus = 1; + statics->ncpus = ncpus; if (pcpu_stats) - toggle_pcpustats(statics); + toggle_pcpustats(); /* all done! */ return (0); |