[Toybox] [PATCH] Add "time -v".

enh enh at google.com
Mon Nov 27 19:12:21 PST 2017


On Fri, Nov 24, 2017 at 6:40 AM, Rob Landley <rob at landley.net> wrote:
> On 11/17/2017 02:18 PM, enh wrote:
>> i'm not super convinced by this myself, so more of an RFC...
>> specifically this was wanted for the "max rss" line, but it's not
>> obviously a good way to measure that for anything but simple
>> single-threaded/no-forking code (because of children).
>
> Hmmm... there's no -v in ubuntu 14.04? Ah, stupid shell builtins, of
> _course_ the FSF implemented two incompatible versions.
>
> $ /usr/bin/time true
> 0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata
> 1708maxresident)k
> 0inputs+0outputs (0major+81minor)pagefaults 0swaps
>
> The whitespace is broken on that. Great.

that format mystifies me. awkward for humans *and* for machines? ship it!

> $ /usr/bin/time -v true
>         Command being timed: "true"
>         User time (seconds): 0.00
>         System time (seconds): 0.00
>         Percent of CPU this job got: 0%
>         Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
>         Average shared text size (kbytes): 0
>         Average unshared data size (kbytes): 0
>         Average stack size (kbytes): 0
>         Average total size (kbytes): 0
>         Maximum resident set size (kbytes): 1608
>         Average resident set size (kbytes): 0
>         Major (requiring I/O) page faults: 0
>         Minor (reclaiming a frame) page faults: 78
>         Voluntary context switches: 1
>         Involuntary context switches: 1
>         Swaps: 0
>         File system inputs: 0
>         File system outputs: 0
>         Socket messages sent: 0
>         Socket messages received: 0
>         Signals delivered: 0
>         Page size (bytes): 4096
>         Exit status: 0
>
> Why is all that indented? Where do you get _averages_ from?
>
> Hmmm... how is it harvesting half that data? Swaps? Socket messages
> sent? You'd want to get notified that the process was exiting, but fetch
> its /proc info while it was still a zombie (which sounds like a job for
> the ps/top infrastructure), but receiving the signal allows it to exit
> so the data goes away before you can read it. Are they doing something
> with ptrace? No, strace says it's getting all that data from wait4() and
> never opening /proc, and then of course it's doing 8 gazillion
> single-byte write() calls to produce output, because FSF.
>
> Sigh, this is the kind of thing I'd normally throw on the todo heap
> along with a toybox version of screen and "kill -r" (recursive: children
> and grandchildren and...), but as long as you're sending me a patch I'll
> assume you've already identified the interesting subset?

not so much "interesting" as "actually implemented by linux".
basically, the FSF version just dumps all the fields in struct rusage.
even the ones that Linux explicitly doesn't maintain. which seems
actively unhelpful. so my patch goes through the fields but skips the
always-0 ones.

i didn't actually expect you to want the patch, so i didn't bother
with the weird tabs, the "Command being timed" line, or the "Page
size" and "Exit status" lines, because those things are either already
available in other ways or -- in the case of page size -- not
per-process anyway. it did seem like there was some potential value to
having a way to dump the full contents of struct rusage though. you
know you're never going to have the time to write your strace
replacement anyway :-)

> Hmmm...
>
> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.



More information about the Toybox mailing list