Commit Graph

11 Commits

Author SHA1 Message Date
Tom Cherry 1a796bca57 logd: add a SerializedLogBuffer suitable for compression
Initial commit for a SerializedLogBuffer.  The intention here is for
the serialized data to be compressed (currently using zlib) to allow
for substantially longer logs in the same memory footprint.

Test: unit tests
Change-Id: I2528e4e1ff1cf3bc91130173a107f371f04d911a
2020-06-12 14:35:30 -07:00
Tom Cherry 8319bb40d0 logd: add a test for clearing logs with a reader present
Test that:
1) Logs are cleared
2) More logs can be added after clear
3) Well behaving blocking readers stay connected and can read new logs
after clear.

Test: this unit test
Change-Id: I8497896f5fb068b1e50ff0dcaab1cf79aebae2bb
2020-06-11 14:13:39 -07:00
Tom Cherry f93b4006e0 logd: use libbase logging
We can use libbase logging to output to the kernel log instead of the
'prdebug' function, so use that instead.

Bonus #1: we can now use CHECK().
Bonus #2: logging unit tests automatically output to stderr.
Bonus #3: We see dependent library's logs instead of losing them to
the void.

Test: logging unit tests
Test: logs show appropriately in dmesg / stderr
Test: CHECK() works
Change-Id: I92f8056b4820dc4998996cf46460568085299700
2020-06-03 16:29:48 -07:00
Tom Cherry b3e163399a logd: move leading_dropped logic into FlushTo()
This logic isn't generic, so it should not be in the generic
LogReaderThread.

Moreover, it's currently broken in essentially every case except when
filtering by UID, because it runs as in the filter functions before
the actual filtering by pid/etc takes place.  For example, when
filtering by pid, it's possible to get leading chatty messages.  The
newly added test was failing previously but is fixed by this change.

It's fundamentally broken in the tail case.  Take this example:
1: Normal message
2: Chatty message
3: Normal message
4: Normal message

If you read that log buffer with a tail value of 3, there are three
possible outcomes:
1) Messages #2-4, however this would include a leading chatty message,
   which is not allowed.
2) Messages #3-4, however this is only 2, not 3 messages.
3) Messages #1-4, however this is 4, more than the 3 requested
   messages.

This code chooses 2) as the correct solution, in this case, we don't
need to account for leading chatty messages when counting the total
logs in the buffer.  A test is added for this case as well.

Test: new unit test
Change-Id: Id02eb81a8e77390aba4f85aac659c6cab498dbcd
2020-06-02 13:26:48 -07:00
Tom Cherry 855c7c87a3 logd: create FlushToState class
ChattyLogBuffer::FlushTo() needs an array of pid_t's to differentiate
between deduplication and spam removal chatty messages, but that won't
be useful to other log buffers, so it doesn't deserve its own entry in
the abstruct LogBuffer::FlushTo() function.

Other log buffers may need their own data stored for each reader, so
we create an interface that the reader itself owns and passes to the
log buffer.  It uses a unique_ptr, such that the when the reader is
destroyed, so will this state.

FlushToState will additionally contain the start point, that it will
increment itself and the log mask, which LogBuffers can use to
efficiently keep track of the next elements that will be read during a
call to FlushTo().

Side benefit: this allows ChattyLogBufferTests to correctly report
'identical' instead of 'expired' lines the deduplication tests.

Side benefit #2: This updates LogReaderThread::start() more
aggressively, which should result in readers being disconnected less
often, particularly readers who read only a certain UID.

Test: logging unit tests
Change-Id: I969565eb2996afb1431f20e7ccaaa906fcb8f6d1
2020-06-01 14:45:02 -07:00
Tom Cherry 90e9ce0c28 logd: fix bug in FlushTo when requesting exact sequence number
SimpleLogBuffer::FlushTo() attempts to find the iterator matching a
given sequence number, but the logic is wrong and will always skip one
element forward.  This change fixes this and adds a test for the
situation.

This likely contributed to some test instability in the past, but was
identified because subsequent changes that track the start value
closer exacerbated this issue.

Test: existing and new unit tests
Change-Id: Iba2e654e94234693dba20d4747a60bc79d195673
2020-06-01 14:44:56 -07:00
Tom Cherry 8f613464b8 logd: create SimpleLogBuffer and implement ChattyLogBuffer in terms of it
Test: unit tests with SimpleLogBuffer
Change-Id: If6e29418645b5491df9b8aeef8f95bb786aeba93
2020-05-21 14:23:45 -07:00
Tom Cherry e18346d3d9 logd: separate Chatty only vs generic LogBufferTests
Separate these tests such that future log buffer implementations can
be run against the generic tests.  Use a parameterized fixture to
allow testing any number of log buffers.

Test: these unit tests
Change-Id: I6d90838e8efa019b934d08da25cab0c2405b66cd
2020-05-21 14:10:32 -07:00
Tom Cherry b398a7c85e logd: add tests for log deduplication
Fix a subtle bug that liblog event messages have a payload of int32_t,
not uint32_t, so they should only be summed to int32_t max.

Make a bunch of test improvements as well to support these.

Test: these tests
Change-Id: I4069cc546240bfffec5b19f34ebec913799674e8
2020-05-20 14:39:26 -07:00
Tom Cherry a515197266 logd: build liblogd and its test on host
Plus the various fixups needed for building on host.

Test: run these tests on host
Change-Id: I85e6c989068f80c5a80eaf5ad149fdad0a045c08
2020-05-18 15:54:06 -07:00
Tom Cherry 43f3f761f0 logd: add LogBufferTest.cpp
Add a standalone test of log buffers that does not interact with the
logd running on the device.

Test: this new test
Change-Id: Ie4ecc50289ef164aa47cc72ddeeb9b28e776db94
2020-05-18 15:51:08 -07:00