[Toybox] New toy: vmstat

Elie De Brauwer eliedebrauwer at gmail.com
Tue Apr 10 23:13:54 PDT 2012


On 04/11/2012 04:13 AM, Rob Landley wrote:
> On 04/09/2012 11:59 AM, Georgi Chorbadzhiyski wrote:
>> On 4/9/12 2:39 PM, Elie De Brauwer wrote:
>>> In attachment you can find a no-nonsense vmstat implementation.
>>> Meaning most of the special things (which I personally never bothered
>>> to use) are dropped. (vmstat -d however is still under consideration,
>>> please shout if you're waiting for a vmstat -d or any other options).
>>> +        if(first_run || (!(loop_num % 22)&&   !no_header)) {
>>
>> That 22 - 3 is terminal lines, right? You should probably use
>> terminal_size()
>> function from lib.c and adjust the check on each loop.
>
>
> I note that something I implemented for BusyBox way back when is ascii
> probing for terminal size.  If all else fails and you can't figure out
> how big your screen is (which happens on serial consoles, for example),
> it sends an ansi probe sequence that the tty responds to with a reply
> sequence.
>
> Blog entry about it here:
>
> http://landley.net/notes-2011.html#15-11-2011
>
> Which refers to an earlier blog entry from 2007 (which is about when I
> submitted the code to busybox, I think).
>
> It's relevant here  because querying terminal size every line probably
> wouldn't be a good idea if it goes through the ascii probe again, for
> reasons explained in the blog entry. You want to call the function once
> and remember the value.
>

I actually gave the real vmstat a spin, and on my pc it obeys and only 
prints the headers once per number of lines. However on my embedded 
target through a serial console, it just uses 22. Personally the 22 
behavior doesn't bother me (it would be more annoying if something like 
top wouldn't be terminal size aware than something like vmstat).

One sidenote with the query of the height though, how I frequently use 
vmstat is just redirect the output to a file, and use some scripts to do 
some datamining on it later (any spikes in cpu usage/interrupts/how is 
memory usage evolving over time ? ...) I think that using terminal 
escape sequences (you'd need to do these things periodically, not per se 
every loop) would break this approach ?

But i'll first take a look at the buffer/whitespace cleanup, which is 
imho more important.

gr
E.
-- 
Elie De Brauwer




More information about the Toybox mailing list