platform_system_core/base/include/android-base
Tom Cherry 953c0deadb base: reimagine line splitting in logger.cpp
Previously, we would split messages by line and call the logger
function for each line.  We would hold a lock during this, to ensure
that multiple threads would not interleave their messages.

There are a few problems with this approach:
1) Using a lock is not efficient and is not fork safe
2) With APEX, there is one lock per instance of libbase, so we must
   move the lock to a location where all instances can access it, or
   perform the line splitting in a way that does not require the lock.

To solve these issues, we reimagine line splitting.
1) We move the lock out of the LogMessage::~LogMessage() and make it
   the logger's responsibility to split lines, giving the logger the
   option to lock or not.
2) We do not need any locks at all for StderrLogger.
   Instead, we generate a single string that contains all of the lines
   with their appropriate log header.  A single write() call is used
   to output this at once.
3) Logd handles log messages with newlines correctly, however it only
   accepts up to a maximum size of log message.  Therefore we
   separate the incoming log message into chunks, delimited by new
   lines, up to that maximum size, and send each of those to logd.
   Note that this is the strategy used in
   android.util.Log.printlns().
   This should solve a majority of use cases, since the maximum size
   that logd accepts is nearly 4K, while remaining lock free.
   If interleaving messages absolutely must be avoided, a lock can
   still be used given 1) above.

Bug: 65062446
Bug: 153824050
Test: logging, particularly multi-line stack traces, show correctly
Test: existing and new unit tests
Change-Id: Id0cb5669bee7f912da1e17f7010f0ee4c93be1e3
(cherry picked from commit 36d31c530d)
2020-04-27 16:25:27 -07:00
..
chrono_utils.h libbase: switch to #pragma once. 2018-06-26 17:17:41 -07:00
cmsg.h Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
collections.h base: add helpers for sending/receiving file descriptors. 2019-02-13 13:21:54 -08:00
endian.h <android-base/endian.h>: fix interoperability issue 2019-09-18 13:06:45 +08:00
errno_restorer.h liblog: always restore errno in logging functions 2020-01-27 13:50:44 -08:00
errors.h libbase: switch to #pragma once. 2018-06-26 17:17:41 -07:00
expected.h expected.h - fix bugprone-forwarding-reference-overload warnings 2020-04-24 17:31:52 -07:00
file.h Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
format.h Include chrono.h 2019-08-27 20:38:14 +00:00
logging.h base: reimagine line splitting in logger.cpp 2020-04-27 16:25:27 -07:00
macros.h libbase: remove ARRAYSIZE_UNSAFE. 2018-10-24 14:34:52 -07:00
mapped_file.h Fix SEGV in libziparchive with malformed zip file. 2019-12-17 08:39:09 -08:00
memory.h libbase: switch to #pragma once. 2018-06-26 17:17:41 -07:00
no_destructor.h base: steal Chromium's NoDestructor. 2019-12-06 13:23:05 -08:00
off64_t.h libbase: a slightly cleaner solution to libbase's off64_t problem. 2018-10-25 16:29:02 -07:00
parsebool.h Expose ParseBool from libbase 2019-11-19 13:31:50 -08:00
parsedouble.h ParseFloat/ParseDouble, also take std::string 2018-08-09 10:49:45 -07:00
parseint.h Assert that ParseInt/ParseUint are only used with signed/unsigned numbers respectively 2018-10-05 14:30:39 -07:00
parsenetaddress.h libbase: switch to #pragma once. 2018-06-26 17:17:41 -07:00
process.h Add android::base::GetPids() function to return all pids 2019-07-01 13:55:46 -07:00
properties.h base: add CachedProperty. 2020-02-28 15:20:29 -08:00
result.h result.h - fix bugprone-suspicious-semicolon warning 2020-04-24 17:32:00 -07:00
scopeguard.h Add noexcept to move constructors and assignment operators. 2018-10-05 16:43:47 +00:00
stringprintf.h libbase: switch to #pragma once. 2018-06-26 17:17:41 -07:00
strings.h Add absl-like StringReplace. 2019-11-18 16:02:31 -08:00
test_utils.h base: avoid evaluating macro argument multiple times. 2019-12-12 14:25:45 -08:00
thread_annotations.h base: add ScopedLockAssertion. 2019-02-12 16:32:35 -08:00
threads.h Move libbacktrace off cutils. 2018-07-11 13:55:07 -07:00
unique_fd.h Add unique_fd::operator{==,!=} overloads that take a unique_fd. 2020-01-13 18:44:11 -08:00
utf8.h Add sys/types.h in utf8.h 2018-09-21 10:46:35 -07:00