[PATCH] add nmeter applet

Rob Landley rob at landley.net
Fri Feb 10 19:28:04 UTC 2006


On Friday 10 February 2006 13:10, Michael S. Zick wrote:
> On Fri February 10 2006 13:02, Rob Landley wrote:
> > On Friday 10 February 2006 13:00, Rob Landley wrote:
> > > The naieve implementation of generic code would be something that fills
> > > out a system structure (free memory, load average, etc) a list of
> > > process structures.  In theory, this list of process structures could
> > > get darn long. In practice, we need the whole list in order to sort it,
> > > and we can't figure out what processes to display without sorting the
> > > list, so...
> >
> > Insertion sort!
>
> Divide and conquer,
>
> make it a tree structured, insertion sort,
> no long list walking.

Nah, no need to get that fancy.

The point is, we're only keeping X entries (however many we're going to 
display once we've gone through them all), and we know the length ahead of 
time thanks to get_terminal_width_height() which is cheap enough to query 
every time we display it.  So we can predefine an array of pointers to 
structures, compare with the last entry to see if we're going to insert it at 
all, and if so do a standard binary search to figure out where.  Then 
memcpy() on a pointer list isn't brain surgery, and figuring out whether to 
free the last one or re-use the structure for the new one we're inserting is 
an implementation detail.  (Basically do we have to fill out the structure 
before we have enough info to do the sort or not?  To be fully generic, the 
answer is probably yes.)

The reason for all this is if we're ever run on a machine with a million 
running processes we won't allocate a million instances of this structure 
before discarding most of them.  We have a cap on memory usage.

Hmmm, I wonder if the current busybox top is thread aware?

Rob
-- 
Steve Ballmer: Innovation!  Inigo Montoya: You keep using that word.
I do not think it means what you think it means.



More information about the busybox mailing list