From owner-freebsd-ports Sun Jun 25 12:23:50 1995 Return-Path: ports-owner Received: (from majordom@localhost) by freefall.cdrom.com (8.6.10/8.6.6) id MAA03596 for ports-outgoing; Sun, 25 Jun 1995 12:23:50 -0700 Received: from haywire.DIALix.COM (peter@haywire.DIALix.COM [192.203.228.65]) by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id MAA03588 for ; Sun, 25 Jun 1995 12:23:38 -0700 Received: (from peter@localhost) by haywire.DIALix.COM (8.6.12/8.6.12/DIALix) id DAA07137; Mon, 26 Jun 1995 03:23:33 +0800 Date: Mon, 26 Jun 1995 03:23:31 +0800 (WST) From: Peter Wemm To: ports@freebsd.org Subject: enhancements for top-3.3 Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: ports-owner@freebsd.org Precedence: bulk Hi all.. I wasn't sure whether to send this to ports@freebsd.org, or send it via send-pr as a "change request".. Oh well here goes anyway... I made a change to top so that it would show the amount of data in the VM disk cache - because I was "informed" by a Linux user that Linux was obviously better than FreeBSD because Linux uses free memory for cache, and since FreeBSD is obviously so memory hungry that it only has 80K of free ram, then it can't be doing much caching at all, can it? It's not the first time I've seen that - the current flame wars in comp.unix.bsd.freebsd.misc have been through is a few times too. Anyway, I extended top to show the amount of space allocated to cache - only it made the line too long, and try as I might, it didn't fit well without tossing something useful, or looking UGLY, so I made a seperate Memory: line and added a "Swap:" line as well, just like the linux top. It this patch will make top look like this: [........] Memory: 15M Active, 224K Inact, 2736K Wired, 4724K Cache, 4648K Free Swap: 31M Total, 23M Free, 26% Inuse [xxxKin] [yyyKout] [.... rest of display ....] (I've just quit XFree86, and the cache is filling up again...) I think that makes it pretty obvious where the memory is, and fairly unambiguous. I sent a much smaller version of this in before while the code freeze was in place still - but that version wrapped around the memory line if paging started. Anyway, here's my utils/top/patches/patch-ac: diff -rc2 ../work/display.c ./display.c *** ../work/display.c Thu Jan 5 08:11:08 1995 --- ./display.c Mon Jun 26 00:17:14 1995 *************** *** 64,75 **** --- 64,78 ---- static char **cpustate_names; static char **memory_names; + static char **swap_names; static int num_procstates; static int num_cpustates; static int num_memory; + static int num_swap; static int *lprocstates; static int *lcpustates; static int *lmemory; + static int *lswap; static enum { OFF, ON, ERASE } header_status = ON; *************** *** 141,144 **** --- 144,151 ---- num_memory = string_count(memory_names); lmemory = (int *)malloc(num_memory * sizeof(int)); + + swap_names = statics->swap_names; + num_swap = string_count(swap_names); + lswap = (int *)malloc(num_swap * sizeof(int)); } *************** *** 448,451 **** --- 455,492 ---- summary_format(new, stats, memory_names); line_update(memory_buffer, new, x_mem, y_mem); + } + + /* + * *_swap(stats) - print "Swap: " followed by the swap summary string + * + * Assumptions: cursor is on "lastline" + * for i_swap ONLY: cursor is on the previous line + */ + + char swap_buffer[MAX_COLS]; + + i_swap(stats) + + int *stats; + + { + fputs("\nSwap: ", stdout); + lastline++; + + /* format and print the swap summary */ + summary_format(swap_buffer, stats, swap_names); + fputs(swap_buffer, stdout); + } + + u_swap(stats) + + int *stats; + + { + static char new[MAX_COLS]; + + /* format the new line */ + summary_format(new, stats, swap_names); + line_update(swap_buffer, new, x_swap, y_swap); } diff -rc2 ../work/layout.h ./layout.h *** ../work/layout.h Sun May 10 02:13:09 1992 --- ./layout.h Mon Jun 26 00:13:43 1995 *************** *** 18,27 **** #define x_mem 8 #define y_mem 3 ! #define y_message 4 #define x_header 0 ! #define y_header 5 #define x_idlecursor 0 ! #define y_idlecursor 4 ! #define y_procs 6 #define y_cpustates 2 --- 18,29 ---- #define x_mem 8 #define y_mem 3 ! #define x_swap 8 ! #define y_swap 4 ! #define y_message 5 #define x_header 0 ! #define y_header 6 #define x_idlecursor 0 ! #define y_idlecursor 5 ! #define y_procs 7 #define y_cpustates 2 diff -rc2 ../work/machine/m_freebsd20.c ./machine/m_freebsd20.c *** ../work/machine/m_freebsd20.c Mon Jun 26 01:40:28 1995 --- ./machine/m_freebsd20.c Mon Jun 26 02:53:28 1995 *************** *** 57,60 **** --- 57,61 ---- static int getkval __P((unsigned long, int *, int, char *)); extern char* printable __P((char *)); + int swapmode __P((int *retavail, int *retfree)); #include "top.h" *************** *** 209,213 **** /* these are for detailing the memory statistics */ ! int memory_stats[8]; char *memorynames[] = { #ifndef VM_REAL --- 210,214 ---- /* these are for detailing the memory statistics */ ! int memory_stats[6]; char *memorynames[] = { #ifndef VM_REAL *************** *** 219,224 **** "K/", "K SWIO", #else ! "K Act ", "K Inact ", "K Wired ", "K Free ", "% Swap, ", ! "Kin ", "Kout", #endif NULL --- 220,224 ---- "K/", "K SWIO", #else ! "K Active, ", "K Inact, ", "K Wired, ", "K Cache, ", "K Free", #endif NULL *************** *** 226,229 **** --- 226,237 ---- }; + int swap_stats[6]; + char *swapnames[] = { + /* 0 1 2 3 4 */ + "K Total, ", "K Free, ", "% Inuse ", "Kin ", "Kout", + NULL + }; + + /* these are for keeping track of the proc array */ *************** *** 320,323 **** --- 328,332 ---- statics->cpustate_names = cpustatenames; statics->memory_names = memorynames; + statics->swap_names = swapnames; /* all done! */ *************** *** 391,395 **** total = percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); ! /* sum memory statistics */ { --- 400,404 ---- total = percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); ! /* sum memory & swap statistics */ { *************** *** 413,420 **** memory_stats[6] = -1; memory_stats[7] = pagetok(total.t_free); - } #else struct vmmeter sum; static unsigned int swap_delay = 0; (void) getkval(cnt_offset, (int *)(&sum), sizeof(sum), --- 422,430 ---- memory_stats[6] = -1; memory_stats[7] = pagetok(total.t_free); #else struct vmmeter sum; static unsigned int swap_delay = 0; + static int swapavail = 0; + static int swapfree = 0; (void) getkval(cnt_offset, (int *)(&sum), sizeof(sum), *************** *** 425,456 **** memory_stats[1] = pagetok(sum.v_inactive_count); memory_stats[2] = pagetok(sum.v_wire_count); ! memory_stats[3] = pagetok(sum.v_free_count); if (swappgsin < 0) { ! memory_stats[5] = 0; ! memory_stats[6] = 0; } else { ! memory_stats[5] = pagetok(((sum.v_swappgsin - swappgsin))); ! memory_stats[6] = pagetok(((sum.v_swappgsout - swappgsout))); } swappgsin = sum.v_swappgsin; swappgsout = sum.v_swappgsout; #ifdef USE_SWAP ! if ((memory_stats[5] > 0 || memory_stats[6]) > 0 || swap_delay == 0) { ! memory_stats[4] = swapmode(); } ! swap_delay++; #else ! memory_stats[4] = 0; #endif ! ! ! memory_stats[7] = -1; ! } #endif /* set arrays and strings */ si->cpustates = cpu_states; si->memory = memory_stats; #ifdef LASTPID if(lastpid > 0) { --- 435,472 ---- memory_stats[1] = pagetok(sum.v_inactive_count); memory_stats[2] = pagetok(sum.v_wire_count); ! memory_stats[3] = pagetok(sum.v_cache_count); ! memory_stats[4] = pagetok(sum.v_free_count); ! memory_stats[5] = -1; if (swappgsin < 0) { ! swap_stats[3] = 0; ! swap_stats[4] = 0; } else { ! swap_stats[3] = pagetok(((sum.v_swappgsin - swappgsin))); ! swap_stats[4] = pagetok(((sum.v_swappgsout - swappgsout))); } + swappgsin = sum.v_swappgsin; swappgsout = sum.v_swappgsout; #ifdef USE_SWAP ! if (swap_stats[3] > 0 || swap_stats[4] > 0 || swap_delay == 0) { ! swap_stats[2] = swapmode(&swapavail, &swapfree); ! swap_stats[0] = swapavail; ! swap_stats[1] = swapfree; } ! swap_delay = 1; #else ! swap_stats[0] = 0; ! swap_stats[1] = 0; ! swap_stats[2] = 0; #endif ! swap_stats[5] = -1; #endif + } /* set arrays and strings */ si->cpustates = cpu_states; si->memory = memory_stats; + si->swap = swap_stats; #ifdef LASTPID if(lastpid > 0) { *************** *** 810,814 **** int ! swapmode() { char *header; --- 826,832 ---- int ! swapmode(retavail, retfree) ! int *retavail; ! int *retfree; { char *header; *************** *** 890,893 **** --- 908,913 ---- * need to bother with totals. */ + *retavail = avail / 2; + *retfree = nfree / 2; used = avail - nfree; free(sw); free(perdev); diff -rc2 ../work/machine.h ./machine.h *** ../work/machine.h Thu May 28 04:11:32 1992 --- ./machine.h Mon Jun 26 00:12:56 1995 *************** *** 13,16 **** --- 13,17 ---- char **cpustate_names; char **memory_names; + char **swap_names; }; *************** *** 28,31 **** --- 29,33 ---- int *cpustates; int *memory; + int *swap; }; diff -rc2 ../work/top.c ./top.c *** ../work/top.c Wed Feb 8 13:14:48 1995 --- ./top.c Mon Jun 26 00:20:19 1995 *************** *** 108,111 **** --- 108,113 ---- int i_memory(); int u_memory(); + int i_swap(); + int u_swap(); int i_message(); int u_message(); *************** *** 120,123 **** --- 122,126 ---- int (*d_cpustates)() = i_cpustates; int (*d_memory)() = i_memory; + int (*d_swap)() = i_swap; int (*d_message)() = i_message; int (*d_header)() = i_header; *************** *** 515,518 **** --- 518,524 ---- (*d_memory)(system_info.memory); + /* display swap stats */ + (*d_swap)(system_info.swap); + /* handle message area */ (*d_message)(); *************** *** 569,572 **** --- 575,579 ---- d_cpustates = u_cpustates; d_memory = u_memory; + d_swap = u_swap; d_message = u_message; d_header = u_header; *************** *** 831,834 **** --- 838,842 ---- d_cpustates = i_cpustates; d_memory = i_memory; + d_swap = i_swap; d_message = i_message; d_header = i_header; diff -rc2 ../work/top.h ./top.h *** ../work/top.h Tue Aug 31 02:36:18 1993 --- ./top.h Mon Jun 26 01:00:30 1995 *************** *** 9,13 **** /* Number of lines of header information on the standard screen */ ! #define Header_lines 6 /* Maximum number of columns allowed for display */ --- 9,13 ---- /* Number of lines of header information on the standard screen */ ! #define Header_lines 7 /* Maximum number of columns allowed for display */