Commit graph

17 commits

Author SHA1 Message Date
Tom Cherry
0efb410013 logging: Use more inclusive language.
Also generic syntax clean up and removing some unused aspects (sorting
the list and the TODO increasing performance based on this sorting).

Test: logging unit tests
Change-Id: I56bb3866c13cb4c28bd48665bf32ec620cf0278e
2020-06-16 14:31:31 -07:00
Tom Cherry
a863b1a04b logd: simplify Clear() + Prune() logic
Clear() and Prune() return a boolean indicating whether or not their
operations failed because the log buffer was 'busy'.  This means that
they return false upon success and true upon failure, which is not
intuitive.

This change inverts their return value to simply be true if they were
successful or false otherwise.  It also simplifies the return value of
ChattyLogBuffer::Prune() to true if the requested number of rows have
been pruned or if all rows in the log buffer have been pruned, and
otherwise return false.

Test: logging unit tests
Test: clearing works even under logging pressure
Change-Id: I346bb945496ef62bf8e973298f81c5163f49bc57
2020-06-11 07:59:01 -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
3dd3ec3514 logd: Drop the LogStatistics dependency on LogBufferElement
Other log buffers may not use LogBufferElement, so we should decouple
the two classes.  This uses an intermediate LogStatisticsElement
structs instead of passing a large number of parameters to each
function.

This additionally moves IsBinary() and the GetTag() functions out into
LogUtils.h since they can be used generically by other users.

Test: logging unit tests
Change-Id: I71f53257342c067bcccd5aa00bae47f714cd7c66
2020-06-02 16:02:56 -07:00
Tom Cherry
9787f9a054 logd: format LogBufferElement and LogStatistics correctly
Test: logging unit tests
Change-Id: If63be065e38f2a1c4cf2807ceaa9eea180b16c51
2020-06-02 11:38:44 -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
a3c5ff5d3f logd: move current sequence from LogBufferElement to LogBuffer
This is required for tests that are aware of sequence numbers to pass;
each new LogBuffer instance should start from sequence = 1, which
isn't the case if the current sequence number is a static.

Test: unit tests
Change-Id: Ie488f8ac5e22b946b7e6237d1d5caf14929c0ec3
2020-05-21 14:10:17 -07:00
Tom Cherry
1322472ad0 logd: use a std::list<> of values not pointers
This saves 4 or 8 bytes off of each log message for 32 bit or 64 bit
devices respectively.  In practice, this actually saves more, due to
avoiding heap fragmentation.

Averaging over 5 runs of the LogBufferTest.random_messages unit test
(32 bit), this change results in 8k less memory used when 1000 logs
are logged and results in 260k less memory used when 10000 logs are
logged.

Test: check memory usage during LogBufferTest.random_messages
Test: logging unit tests
Change-Id: Ia7953e3c4cb19631ef43bab1deb91bb336bc2520
2020-05-21 11:16:36 -07:00
Tom Cherry
a26f7dffe5 logd: refactor chatty deduplication logging
This code and comment is hard to follow, despite the operation being
simple, so refactor the code to be easier to follow.

Also, use std::unique_ptr instead of raw pointers as appropriate.

Test: logging unit tests
Change-Id: Id1f29f4deeca730d1e3b6856e1581d0b840f883e
2020-05-21 11:14:18 -07:00
Tom Cherry
0b01ff0f39 logd: use RAII locks and thread annotations
Test: unit tests
Change-Id: I38623130a96f17a47ed79753e24b25efa9e38279
2020-05-21 11:07:04 -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
bd80e5678f liblog: remove unused log_time functions, inline the others
One of the reasons that logcat and logd statically include liblog is
to access the symbols in log_time.cpp, which we do not expose
otherwise.  Except for strptime(), which will be handled in a separate
CL, these symbols are either small enough to inline in the header or
unused and can be removed.

Test: logging unit tests
Change-Id: I1f8cfbb779aef79fc7d5b6d0050438fe5f0e0e2c
2020-05-18 15:40:26 -07:00
Tom Cherry
e82dcdcdf0 Merge "logd: don't use libcutils properties" 2020-05-18 15:37:03 +00:00
Tom Cherry
a8c7f30651 logd: don't use libcutils properties
This is the only non-socket usage of libcutils.

Test: logging unit tests
Change-Id: Ia9877ddb32da4955a818299c109e5c639423a9fd
2020-05-15 10:26:09 -07:00
Tom Cherry
283c9a1c00 logd: remove SocketClient from LogBuffer and LogBufferElement
In the future, we'll want to be able to write to outputs that are not
necessarily a libsysutils SocketClient, for example host tests of
LogBuffer.  Therefore, we add a LogWriter class to be used instead of
SocketClient.

Test: logging unit tests
Change-Id: I4385be65e14e83a635691a7ba79e9bf060e49484
2020-05-14 19:53:45 -07:00
Tom Cherry
d5b3838dbc logd: make LogBuffer an interface
We may use different implementations of LogBuffer in the future, so we
make it interface and create a concrete ChattyLogBuffer class that
implements it.

Test: logging unit tests
Change-Id: I5731d6404640664c9acc26b7c677dff3110c6a11
2020-05-12 15:39:19 -07:00
Renamed from logd/LogBuffer.cpp (Browse further)