From owner-freebsd-hackers Mon Apr 1 22:17:18 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from periodic.imeme.net (imeme.net [63.102.48.45]) by hub.freebsd.org (Postfix) with ESMTP id 024DA37B422 for ; Mon, 1 Apr 2002 22:17:03 -0800 (PST) Received: from gateway.bogus.com (imeme.net) [209.249.198.49] by periodic.imeme.net with asmtp (Exim 3.33 #1 (Debian)) id 16sHaL-000LZm-00; Tue, 02 Apr 2002 01:16:01 -0500 Message-ID: <3CA94CD9.6070805@imeme.net> Date: Tue, 02 Apr 2002 01:16:57 -0500 From: Jon Ringuette User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:0.9.9) Gecko/20020312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: diff of proposed top changes Content-Type: multipart/mixed; boundary="------------090801080508010405020304" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------090801080508010405020304 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit These changes will allow top to run in a jail, or proceed on even though certain stats can not be obtained. Unfortunatly you do loss some error messages when doing so. Ps. If I should be submitting these elsewhere please let me know. dff -c machine.c newmachine.c > machine.c.diff --------------090801080508010405020304 Content-Type: text/plain; name="machine.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="machine.c.diff" *** machine.c Tue Jul 31 16:27:05 2001 --- machine.c.new Tue Apr 2 01:11:03 2002 *************** *** 246,254 **** else if (namelength > 15) namelength = 15; ! if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) ! return -1; ! /* get the list of symbols we want to access in the kernel */ (void) kvm_nlist(kd, nlst); --- 246,255 ---- else if (namelength > 15) namelength = 15; ! /* Changed to be NULL instead of kvm_open for parm 5 so it will no longer display error messages if there was a ! problem reading and thus not obstructing the screen */ ! if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL) ! return -1; /* get the list of symbols we want to access in the kernel */ (void) kvm_nlist(kd, nlst); *************** *** 337,342 **** --- 338,344 ---- int mib[2]; struct timeval boottime; size_t bt_size; + int get_mem = 0; /* get the cp_time array */ (void) getkval(cp_time_offset, (int *)cp_time, sizeof(cp_time), *************** *** 380,401 **** static int swapavail = 0; static int swapfree = 0; static int bufspace = 0; ! ! (void) getkval(cnt_offset, (int *)(&sum), sizeof(sum), "_cnt"); (void) getkval(bufspace_offset, (int *)(&bufspace), sizeof(bufspace), "_bufspace"); ! /* convert memory stats to Kbytes */ ! memory_stats[0] = pagetok(sum.v_active_count); ! 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] = bufspace / 1024; ! memory_stats[5] = pagetok(sum.v_free_count); ! memory_stats[6] = -1; ! /* first interval */ if (swappgsin < 0) { swap_stats[4] = 0; swap_stats[5] = 0; --- 382,415 ---- static int swapavail = 0; static int swapfree = 0; static int bufspace = 0; ! ! get_mem = getkval(cnt_offset, (int *)(&sum), sizeof(sum), "_cnt"); (void) getkval(bufspace_offset, (int *)(&bufspace), sizeof(bufspace), "_bufspace"); ! if(get_mem!=2) // Check if we had a problem reading memory stats ! { /* convert memory stats to Kbytes */ ! memory_stats[0] = pagetok(sum.v_active_count); ! 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] = bufspace / 1024; ! memory_stats[5] = pagetok(sum.v_free_count); ! memory_stats[6] = -1; ! } ! else ! { ! memory_stats[0] = -1; ! memory_stats[1] = -1; ! memory_stats[2] = -1; ! memory_stats[3] = -1; ! memory_stats[4] = -1; ! memory_stats[5] = -1; ! memory_stats[6] = -1;//keep ! }; /* first interval */ + if (swappgsin < 0) { swap_stats[4] = 0; swap_stats[5] = 0; *************** *** 407,422 **** swap_stats[5] = pagetok(((sum.v_swappgsout - swappgsout))); } ! swappgsin = sum.v_swappgsin; ! swappgsout = sum.v_swappgsout; ! /* call CPU heavy swapmode() only for changes */ ! if (swap_stats[4] > 0 || swap_stats[5] > 0 || swap_delay == 0) { swap_stats[3] = swapmode(&swapavail, &swapfree); swap_stats[0] = swapavail; swap_stats[1] = swapavail - swapfree; swap_stats[2] = swapfree; } swap_delay = 1; swap_stats[6] = -1; } --- 421,454 ---- swap_stats[5] = pagetok(((sum.v_swappgsout - swappgsout))); } ! if(get_mem !=2) ! { ! swappgsin = sum.v_swappgsin; ! swappgsout = sum.v_swappgsout; ! } ! else ! { ! swappgsin=-1; ! swappgsout=-1; ! }; /* call CPU heavy swapmode() only for changes */ ! if (swap_stats[4] > 0 || swap_stats[5] > 0 || swap_delay == 0 && get_mem!=2) { swap_stats[3] = swapmode(&swapavail, &swapfree); swap_stats[0] = swapavail; swap_stats[1] = swapavail - swapfree; swap_stats[2] = swapfree; } + else + if(get_mem==2) // check if problem retrieving memory stats + { + swap_stats[4] = -1; + swap_stats[5] = -1; + swap_stats[3] = -1; + swap_stats[0] = -1; + swap_stats[1] = -1; + swap_stats[2] = -1; + }; + swap_delay = 1; swap_stats[6] = -1; } *************** *** 700,713 **** } else { ! fprintf(stderr, "top: kvm_read for %s: %s\n", ! refstr, strerror(errno)); ! quit(23); } } return(1); } - /* comparison routines for qsort */ /* --- 732,745 ---- } else { ! // fprintf(stderr, "top: kvm_read for %s: %s\n", ! // refstr, strerror(errno)); ! // quit(23); ! return(2); } } return(1); } /* comparison routines for qsort */ /* --------------090801080508010405020304-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message