Re: Question about possibly additions to TOP

2002-04-02 Thread Jon Ringuette

>
>
>
>  PID USERNAME PRI NICE   SIZERES STATETIME   WCPUCPU COMMAND
>32652 root  960  1956K  1080K RUN  0:00  0.00%  0.00% top
>32650 root  200  1448K   996K pause0:00  0.00%  0.00% tcsh
>
>In general, new "features" for top go into the cross-platform vendor top
>code, but features to improve FreeBSD-specific information extraction go
>into our local tree.  What exactly does -j do?
>
>
>

Thank you for your information I was not actually aware that it was 
fixed in 5.0 . I went ahead and at the advise of Alfred Perlstein made 
it into a patch for just machine.c that will allow the 4.5 branch of top 
just fail out of kvm calls more gracefully and thus allowing it to run 
in a jailed environment or really any environment where it can not get 
all of its needed information.   I don't really want to clutter up 
everyones mailbox with sending another patch but I have throw in on web 
page if you can to take a look 
http://peoplearestrange.net/jon/machine.c.diff

-jon
iMeme



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



diff of proposed top changes

2002-04-01 Thread Jon Ringuette

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



*** 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;

Re: Question about possibly additions to TOP

2002-04-01 Thread Jon Ringuette

>
>
>
>That would be pretty cool, why don't you use the gnats:
>http://www.freebsd.org/send-pr.html
>or just "send-pr"
>
>to submit your changes?
>
>One idea would be to fail gracefully, when unable to read kvm and
>such and keep the -j flag idea you had.
>
Thats a great idea it didn't even cross my mind to just make it fail 
gracefully on the information it can not obtain in jails thanks!

-jon
iMeme




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Question about possibly additions to TOP

2002-04-01 Thread Jon Ringuette

Sorry to bother everyone here but I have a quick question (or I guess 
what I hope is a quick question).  I have made some modifications to 
src/usr.bin/machine.c to allow TOP to run in a jail (I have mostly just 
taken out kvm_read's ) and zero'd out alot of information that is not 
available to TOP in a jail  ie . Total memory usage / swap usage / cpu 
usage etc..  I would like to add an option -j to top and have it check 
for that option to do this (sort of a really lightweight top if this 
option is used).  Would this be of interest to anymore for me to submit 
a patch and if so how should I go about adding the -j option should I 
make a copy of the top.c into src/usr.bin/top or contact the auther of 
top to see about submitting it to him?  I'm not sure if this would be 
useful to anyone outside of the FreeBSD community is the reason I am a 
bit iffy about doing that.  If someone could point me in the right 
direction to do this the correct way I would be very grateful, I really 
want to code but I'm not sure where and how i should do it :)

-jon
iMeme



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message