logcat: use stdio for free buffering.
In modes where we know we'll exit, we don't need to manually flush at
all, so we can avoid the current pathological behavior of one write per
line. This halves the time taken by, say, `logcat -d`.
We do this by moving android_log_printLogLine from a file descriptor to
a FILE* and cleaning up the callers.
This doesn't speed up "tail -f"-equivalent calls, but since they don't
exit until you kill them anyway, that probably matters less. It's not
obvious how to implement that anyway, though an option to pass
MSG_DONTWAIT to recvfrom() and then flush and call it again without that
flag whenever it returns EAGAIN seems like it might work? YAGNI.
As another optimization, explicitly mark the two large buffers as not
needing initialization, since we're about to write into them anyway.
This saves calls to memset().
Also fix copyright headers (there should only ever be the first year),
use the appropriate header file rather than re-define kernel ioctl
constants, switch from size_t to uint64_t to avoid some (incorrect)
hackery to try to deal with the case where a file is larger than 4GiB on
an LP32 system, and factor out the WriteFully-or-die repetition.
There are actually further savings to be had by using setbuffer() to get
a larger-than-default stdio buffer, but I wasn't quite convinced that's
worth the trouble. I didn't investigate whether using setbuffer() to
explicitly request line buffering for the blocking case was a saving, in
part because I felt that might also be a little too subtle, and at this
point it's the thousands of tiny recvs that are the remaining time sink,
not anything on the output side. Unless of course you use `-v printable`,
but that's a whole different festering boil...
Test: treehugger
Change-Id: I175b67484898d65461bc11a8fe47bdc599069c57
5 files changed