History log of /system/core/logd/LogBuffer.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
9decb90e8c445d775a908f9282b8e58fe3f5ae07 17-Apr-2017 Mark Salyzyn <salyzyn@google.com> logd: iterator corruption paranoia

(cherry pick from commit 3614a0c5d4aec84fbc5f6cbf1e919e8b3825b818)

Add checking for impossible(tm) scenarios within LogBuffer::flushTo:

1) When iterating through the log entries, check if the iterator
returns two identical element references and break out of the loop.
2) Cap the maximum number of log entries we will skip while holding
the iterator lock at 4194304, break out of the loop.

We print a message to the kernel logs if we hit these cases.

ToDo: Remove this paranoia at some future date.

Test: gTest liblog-unit-tests logcat-unit-tests and logd-unit-tests
Bug: 37378309
Change-Id: I789594649db14093238828b9f6d1daeca8b780c2
/system/core/logd/LogBuffer.cpp
912eb625957d92a1a68d1370bf8f73283554ff17 17-Apr-2017 Mark Salyzyn <salyzyn@google.com> logd: regression in handling watermark boundary.

(cherry pick from commit 5836379b2114f47c53485b42ab157104c29b2c4e)

Deal with a regression introduced in commit
5a34d6ea43d28f3b5d27bf6dd5b9fa31ec033531 (logd: drop mSequence from
LogBufferElement) where log_time was compared against nsec() time
miscalculating the watermark boundary. When dealing with logcat
-t/-T, or any tail reading, add a margin to prune to back off by a
period of 3 seconds (pruneMargin).

Test: gTest liblog-unit-tests logcat-unit-tests and logd-unit-tests
Bug: 37378309
Change-Id: I72ea858e4e7b5fa91741ea84c40d2e7c3c4aa031
/system/core/logd/LogBuffer.cpp
775cd222229d1916912ff2a004d5905430baf18f 04-Apr-2017 Mark Salyzyn <salyzyn@google.com> logd: cap out-of-order entry search

Reduce the period we are willing to look back at for out-of-order
entries. Cap the number of iterations we are willing to look back
for out-of-order entries to 300.

Test: gTest liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Bug: 36875387
Bug: 36874561
Bug: 36861142
Change-Id: Icee289dfc0a37ccab9912dc8ab40a10ef3967b7a
/system/core/logd/LogBuffer.cpp
b88ec1352f4e295d82d0c5947919f6700e3e9727 31-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: correctly label identical lines

Move lastTid array from local in LogBuffer::flushTo to per-reader
context in LogTimes::mLastTid and pass into LogBuffer::flushTo.

Replace NULL with nullptr in touched files.

Simplify LogTimeEntry::cleanSkip_Locked initialization of skipAhead
to memset, to match mLastTid memset initialization.

Test: gTest liblog-unit-tests, logd-unit-tests & logcat-unit-tests
Test: adb logcat -b all | grep chatty | grep -v identical
Bug: 36488201
Change-Id: I0c3887f220a57f80c0490be4b182657b9563aa3f
/system/core/logd/LogBuffer.cpp
02ce4262dc2dc14c16a49cc62dfae65e15043d03 28-Mar-2017 Mark Salyzyn <salyzyn@google.com> Merge changes I96998c4b,I161bf03b am: dd0cd8d88f am: f17500474a
am: 77a1fa9070

Change-Id: I5b296f6c1b01a8b2dc51c7ebbd44d599a3aa49c1
1f46716f1c3867580d131756a97269eadda13e0f 27-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: last iterator initialized incorrectly

last should start with mLogElements.end() and be updated as
we iterate to find a matching time entry in the list. Since
it is impossible(sic) for a newer start time to be supplied
than the list, the incorrect iterator initialization should
be inconsequential, but if it ever happens this change will
behave correctly and dump nothing.

Test: gTest liblog-unit-tests, logd-unit-tests and logcat-unit-tests
Bug: 36536248
Bug: 36608728
Change-Id: I96998c4b713258f29d5db2e24a83ae562ddf3420
/system/core/logd/LogBuffer.cpp
0484b3b5757594a43c6b646824b44643d2a007de 11-Aug-2016 Mark Salyzyn <salyzyn@google.com> logd: ASAN cleansing

A mixture of fixes and cleanup for LogKlog.cpp and friends.

- sscanf calls strlen. Check if the string is missing a nul
terminator, if it is, do not call sscanf.
- replace NULL with nullptr for stronger typechecking.
- pass by reference for simpler code.
- Use ssize_t where possible to check for negative values.
- fix FastCmp to add some validity checking since ASAN reports that
callers are not making sure pre-conditions are met.
- add fasticmp templates for completeness.
- if the buffer is too small to contain a meaningful time, do not
call down to log_time::strptime() because it does not limit its
accesses to the buffer boundaries, instead stopping at a
terminating nul or invalid match.
- move strnstr to LogUtils.h, drop size checking of needle and
clearly report the list of needles used with android::strnstr
- replace 'sizeof(static const char[]) - 1' with strlen.

Test: gTest liblog-unit-test, logd-unit-tests & logcat-unit-tests
Bug: 30792935
Bug: 36536248
Bug: 35468874
Bug: 34949125
Bug: 34606909
Bug: 36075298
Bug: 36608728
Change-Id: I161bf03ba029050e809b31cceef03f729d318866
/system/core/logd/LogBuffer.cpp
ea6bb2818a5389c79c78b62a70e672c909e0a852 17-Mar-2017 Mark Salyzyn <salyzyn@google.com> Merge changes I92cac83b,Ie897c40b am: 4278f71118 am: 898c8a6e51
am: 0508ebf9da

Change-Id: I3c639a37b5d5dfe2b7b5eac36ab0711fae0ae72d
09d663229fe253ec91b341c9f15ed7f2d22f931a 14-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: cap how far back in-place sort will go to 5 seconds

Add some deterministic behavior should the user change the hour
backwards when altering the device time, prevent sort-in-place
and cause the logger to land the new entries at the end.

Do not limit how far kernel logs can be sorted.

Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests
Bug: 35373582
Change-Id: Ie897c40b97adf1e3996687a0e28c1199c41e0d0c
/system/core/logd/LogBuffer.cpp
f883804b562143a3b158d0a89a8de2234bf580b5 16-Mar-2017 Mark Salyzyn <salyzyn@google.com> Merge changes I2a073293,Ia55ef8b9,I79a385fc am: 82b5c619b8 am: 5a0afe7d27
am: 9f8a97ed0b

Change-Id: Iae26c69eb4ffdfdc3b20b1a841bfc67d768f33f1
3b941d457b7071254a2e68e86db06edf86754ddf 10-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: continue search out-of-order entries timestamp tail

Regression from commit 8e8e8db549ffa6e692246abce6f5560c3a1e93c2

For liblogcat reader -t or -T <timestamp> tail requests, continue
search for pertinent out-of-order entries for an additional 30 seconds
back into logging history to find a more inclusive starting point.

For example, if you have an out of order landing like
[..., 3, 6, 1, 8, 2, 5] and ask for 3 you used to get only 5, and now
you get 3, 6, 8, 5 as 'expected'

Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests
Bug: 35373582
Change-Id: I2a0732933fa371aed383d49c8d48d01f33db2a79
/system/core/logd/LogBuffer.cpp
5a34d6ea43d28f3b5d27bf6dd5b9fa31ec033531 10-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: drop mSequence from LogBufferElement

Use getRealTime() instead and leverage private liblog log_time
comparison and math functions. This saves 8 bytes off each
element in the logging database.

Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests
Bug: 35373582
Change-Id: Ia55ef8b95cbb2a841ccb1dae9a24f314735b076a
/system/core/logd/LogBuffer.cpp
1d84f0b2afd36c4a6a367761c3d518789a424419 03-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: ensure LogBufferElement mSequence is monotonic

- Improves accuracy of -t/-T '<timestamp>' behavior when out of order
arrival of entries messes with mSequence as the list will now have
monotonic sequence numbers enforced.
- Out of order time entries still remain because of reader requiring
the ability to receive newly arrived old entries.
- -t/-T '<timestamp>' can still quit backward search prematurely
because an old entry lands later in the list.
- Adjust insert in place algorithm from two loops of scan placement
and then limit against watermark, into one that does all of that
plus iteratively swap update the sequence numbers to set
monotonicity. Side effect will be that the read lock (which is
actually the LogTimes lock) will be held longer while we search
for a placement above the youngest LogTimes watermark. We need
to hold the read (LogTimes) lock because we may be altering the
sequence numbers affecting -t/-T '<timestamp>' search.

Test: gTest logd-unit-tests liblog-unit-tests logcat-unit-tests
Bug: 35373582
Change-Id: I79a385fc149bac2179128b53d4c8f71e429181ae
/system/core/logd/LogBuffer.cpp
03fc2fedd7ce46f79a6a319c14a14d2250a4d9d9 14-Mar-2017 Evgenii Stepanov <eugenis@google.com> Fix heap-buffer-overflow detected by ASAN.

Bug: 34949125
Bug: 34606909
Test: Make sure Android boots when built with SANITIZE_TARGET='address'
Change-Id: I9c004e806f2025098aa72228284b05affd2c2802
/system/core/logd/LogBuffer.cpp
1598fe03b967439bf35ec1c3e9d5d9ea1828cef1 13-Mar-2017 Mark Salyzyn <salyzyn@google.com> Resolve merge conflicts of e40a08509 to master

Test: gTest liblog-unit-tests logd-unit-tests logcat-unit-tests
Bug: 35373582
Bug: 34949125
Bug: 34606909
Change-Id: If6f3f138974913039dd49f2451bad6e413d6e2e1
501c373916e292764400dbae735f44b33378400f 10-Mar-2017 Mark Salyzyn <salyzyn@google.com> logd: specify clang format

Switch _all_ file's coding style to match to ease all future changes.

SideEffects: None
Test: compile
Bug: 35373582
Change-Id: I470cb17f64fa48f14aafc02f574e296bffe3a3f3
/system/core/logd/LogBuffer.cpp
589f4e7a66629e4d7dab6e679af81ae633932686 15-Feb-2017 Alex Shlyapnikov <alekseys@google.com> Fix heap-buffer-overflow detected by ASAN.

Bug: 34949125
Bug: 34606909
Test: Make sure Android boots when built with SANITIZE_TARGET='address'
Change-Id: I9c004e806f2025098aa72228284b05affd2c2802
/system/core/logd/LogBuffer.cpp
a6754dd558c217cae363e8380efa325004cd4c82 16-Feb-2017 Greg Hartman <ghartman@google.com> Fix read past end of malloc block in logd

Bug: 35412453
Test: Local build
Change-Id: I0f9dee84ef689b042926b6b48abf0caeaa784add
/system/core/logd/LogBuffer.cpp
61e9ce6709a12cf39a9471476da3d50339efe466 12-Sep-2016 Mark Salyzyn <salyzyn@google.com> logd: add getEventTag command and service

Will register a new event tag by name and format, and return an
event-log-tags format response with the newly allocated tag.
If format is not specified, then nothing will be recorded, but
a pre-existing named entry will be listed. If name and format are
not specified, list all dynamic entries. If name=* list all
event log tag entries.

Stickiness through logd crash will be managed with the tmpfs file
/dev/event-log-tags and through a reboot with add_tag entries in
the pmsg last logcat event log. On debug builds we retain a
/data/misc/logd/event-log-tags file that aids stickiness and that
can be picked up by the bugreport.

If we detect truncation damage to /dev/event-log-tags, or to
/data/misc/logd/event-log-tags, rebuild file with a new first line
signature incorporating the time so mmap'd readers of the file can
detect the possible change in shape and order.

Manual testing:

Make sure nc (netcat) is built for the target platform on the host:
$ m nc

Then the following can be used to issue a request on the platform:
$ echo -n 'getEventTag name=<name> format="<format>"\0EXIT\0' |
> nc -U /dev/socket/logd

Test: gTest logd-unit-test --gtest_filter=getEventTag*
Bug: 31456426
Change-Id: I5dacc5f84a24d52dae09cca5ee1a3a9f9207f06d
/system/core/logd/LogBuffer.cpp
b5b879678522882e6dbb02511379518d2b7b545d 23-Jan-2017 Mark Salyzyn <salyzyn@google.com> logd: multiple identical do not report expired

Report multiple identical chatty messages differently than for
regular expire chatty messages. Multiple identical will
report identical count, while spam filter will report
expire count.

This should reduce the expected flood of people confused
but chatty messages in continuous logcat output.

Test: gTest logd_unit_tests --gtest_filter=logd.multiple*
Change-Id: Iad93d3efc6a3938a4b87ccadddbd86626a015d44
/system/core/logd/LogBuffer.cpp
684bdb576dd43f1c262011e7bc4343a1ae4a32d0 13-Dec-2016 Mark Salyzyn <salyzyn@google.com> logd: LogBufferElementKey use uint32_t for uid

Test: gTest liblog-unit-tests, logd-unit-tests & logcat-unit-test
Change-Id: Icae34b1fa0b3df0a45ad175ec81aaf232f322f38
/system/core/logd/LogBuffer.cpp
1dfb4de43697912b47c01eec8faae76ed34a72c6 17-Dec-2016 Mark Salyzyn <salyzyn@google.com> logd: sum liblog tag messages

As an extension to the duplicate multiple message filtering, special
case liblog tagged event messages to be summed. This solves the
inefficient and confusing duplicate message report from the DOS attack
detection such as:

liblog: 2
liblog: 2
liblog: 2
liblog: 2
liblog: 3

which would result in:

liblog: 2
chatty: ... expire 2 lines
liblog: 2
liblog: 3

And instead sums them and turns them all into:

liblog: 11

liblog messages should never be subject to chatty conversion.

Test: liblog-benchmarks manually check for coalesced liblog messages
and make sure they do not turn into chatty messages.
Instrumented code to capture sum intermediates to be sure.
Bug: 33535908
Change-Id: I3bf03c4bfa36071b578bcd6f62234b409a91184b
/system/core/logd/LogBuffer.cpp
8f83a35511e4b53ac2850e93571d9154af63f7c0 17-Dec-2016 Mark Salyzyn <salyzyn@google.com> logd: correct duplicate message state machine

Inspection turned up that for the case of three identical messages,
the result would be a stutter of the first message only. Added
comments to describe the state machine, incoming variables, outcoming
and false condition outputs, for proper maintenance in the future.

Test: gTest liblog-benchmarks BM_log_maximum* and manually check
for correct midstream chatty messages,
Bug: 33535908
Change-Id: I852260d18a484e6207b80063159f1a74eaa83b55
/system/core/logd/LogBuffer.cpp
a2c022257c5bed56fbc47de25c5d909bbe880f7b 13-Dec-2016 Mark Salyzyn <salyzyn@google.com> logd: record multiple duplicate messages as chatty

If a series of messages arrive from a single source with identical
message content payload, then suppress them and generate a chatty
report. The checking is done on a per log id basis.

This alters the assumption that chatty messages are always at the
oldest entries, they now show up in the middle too. To address this
change in behavior we print the first line, a chatty reference
which internally takes little space, then the last line in the series.

This does not conserve processing time in logd, and certainly has no
impact on the long path of formatting and submitting log messages from
from the source, but it may contribute to memory space and signal to
noise savings under heavy spammy loads.

Test: gTest liblog-unit-tests, logd-unit-tests & logcat-unit-tests
Bug: 33535908
Change-Id: I3160c36d4f4e2f8216f528605a1b3993173f4dec
/system/core/logd/LogBuffer.cpp
60636fa872382a8cde0440b72cdfc9032b5fa7d0 25-Oct-2016 Mark Salyzyn <salyzyn@google.com> logd: getTag() functional for chatty entries

getTag() becomes invalid when entry is dropped because mMsg
disappears to save space; but the per-tag spam filter depends on it
still being valid. Conserve space in LogBufferElement by optimizing
the size of the fields, then add a new mTag field that is set in the
object constructor. Add an isBinary() method.

SideEffects: save 12 bytes/log message overhead on 64-bit.
Test: define DEBUG_CHECK_FOR_STALE_ENTRIES and look for stale entries
Bug: 32247044
Change-Id: Iaa5f416718a92c9e0e6ffd56bd5260d8b908d5c0
/system/core/logd/LogBuffer.cpp
8fcfd85acc26f96dffb987951c33f09416e1ede7 24-Oct-2016 Mark Salyzyn <salyzyn@google.com> logd: address code fragility in last watermarks

Do not make the assumption that if worstPid is set, that the log
buffer id is not LOG_ID_EVENTS or LOG_ID_SECURITY. Add comments
to prevent future over-optimization based on this assumption.

Make sure we reset mLast[id] = begin() when we mark it unset, but
tell optimizer this is an _impossible_ path.

SideEffects: drop two branches in all erase calls, gain an unordered
find() on an empty list for events and security buffers.
Test: gTest logd-unit-tests, liblog-unit-test & logcat-unit-tests
Bug: 32247044
Change-Id: Ic156ca2253c050c28021cedf48bedaf7bd692c09
/system/core/logd/LogBuffer.cpp
fa07f9dc4b4d101a49fba5dbbf35c88cdfec4433 21-Oct-2016 Mark Salyzyn <salyzyn@google.com> logd: mLastWorstPidOFSystem crash

mLastWorstPidOfSystem is filled with iterator references
that are not from AID_SYSTEM to aid the performance. But
we only clear entries from the list during erase if they
are from AID_SYSTEM. Remove the filter check in erase so
the stale references will be removed.

The conditions that caused this failure are difficult to
reproduce and are rare.

Test: gTests logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 32247044
Bug: 31237377
Change-Id: Ie405dd643203b816cac15eef5c97600551cee450
/system/core/logd/LogBuffer.cpp
f10e27379064797acb2659afc45b54eafbfcd019 27-Sep-2016 Mark Salyzyn <salyzyn@google.com> logd: Use private interfaces for buffer size properties

Test: gTest logd-unit-tests, liblog-unit-tests and logcat-unit-tests
Bug: 31750617
Change-Id: I692577cfdf4bf8c93616f32df4b56786918aef1c
/system/core/logd/LogBuffer.cpp
807e40ecc9786755e2f74a7a6a9b20c812588119 22-Sep-2016 Mark Salyzyn <salyzyn@google.com> liblog: logd: Add android_lookupEventTag_len()

Allows us to mitigate the impact of MAP_PRIVATE and copy on write by
calling android_lookupEventTag_len instead of android_lookupEventTag,
and delaying the copy on write impact to the later. We return a
string length in a supplied location along with the string pointer
with android_lookupEventTag_len(const EventTagMap* map, size_t* len,
int tag). The string is not guaranteed to be nul terminated. Since
android_lookupEventTag() called even once can cause the memory
impact, we will mark it as deprecated, but we currently have no
timeframe for removal since this is a very old interface.

Add an API for __android_log_is_loggable_len() that accepts the non
null terminated content and fixup callers that would gain because the
length is known prior to the call either in the compiler or at
runtime. Tackle transition to android_lookupEventTag_len() and
fixup callers.

On any application that performs logging (eg: com.android.phone)

/proc/<pid>/smaps before:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 463 /system/etc/event-log-tags
Size: 20 kB
Rss: 20 kB
Pss: 1 kB
Shared_Clean: 0 kB
Shared_Dirty: 20 kB
Private_Clean: 0 kB
Private_Dirty: 0 kB
Referenced: 0 kB
Anonymous: 20 kB
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me ac

/proc/<pid>/smaps after:

xxxxxxxxxx-xxxxxxxxxx rw-p 00000000 fd:00 1773 /system/etc/event-log-tags
Size: 20 kB
Rss: 20 kB
Pss: 1 kB
Shared_Clean: 20 kB (was 0kB)
Shared_Dirty: 0 kB (was 20kB)
Private_Clean: 0 kB
Private_Dirty: 0 kB
Referenced: 20 kB (was 0kB)
Anonymous: 0 kB (was 20kB)
AnonHugePages: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me ac

Added liblog-unit-tests --gtest_filter=liblog.event_log_tags to
check for Shared_Clean: to not be 0 and Anonymous: to be 0 for
all processes referencing event-log-tags. Which can include multiple
references to /system/etc/event-log-tags and future possible refs to
/data/misc/logd/event-log-tags and /dev/event-log-tags. We want
failure messages to help point to errant code using the deprecated
interface.

This change saves 1/4MB of memory or more on a typical system.

Test: gTest liblog-unit-tests
Bug: 31456426
Change-Id: I9e08e44d9092bd96fe704b5709242e7195281d33
/system/core/logd/LogBuffer.cpp
43a5f31e94513d4412ad1f552fd35d04e480a658 02-Sep-2016 Mark Salyzyn <salyzyn@google.com> logd: clear all from non system user status request

pruneRows not necessarily ULONG_MAX when uid not system source,
allow for speed up for status response if pruneRows exhausted.

Change-Id: I38c76bb20215e3d96513a575e2e3bc85a5e5b41c
/system/core/logd/LogBuffer.cpp
1eefca281ee837d183e49951ae29683d8665129a 01-Sep-2016 Mark Salyzyn <salyzyn@google.com> logd: crash in prune mLastWorstPidOfSystem

mLastWorstPidOfSystem is supposed to be indexed by element->getPid()

Bug: 31237377
Bug: 30797725
Bug: 30688716
Change-Id: I81a55e92f175ded1c571a0aa8836736d86b36b1d
/system/core/logd/LogBuffer.cpp
6a06694a610d103afdf424b0bb69dc8f7f2b8e5a 15-Jul-2016 Mark Salyzyn <salyzyn@google.com> logd: Worst Tag filter enabled for events buffer

- Add drop logistics to TagTable
- replace uid references to a key reference since it
is an UID for most buffers, but a TAG for the
events and security buffer
- template the find worst entry mechanics into LogFindWorst class

Bug: 30118730
Change-Id: Ibea4be2c50d6ff4b39039e371365fed2453f17a2
/system/core/logd/LogBuffer.cpp
0f858179851ae24e1fe27b4eb3968218b5510ca2 15-Jul-2016 Mark Salyzyn <salyzyn@google.com> logd: rename sort() for pids to sortPids()

Bug: 30118730
Change-Id: If992b53b52a7470427fbe82abb93c95c1b2dc57a
/system/core/logd/LogBuffer.cpp
1cc82ce95c6f42c313744553430c7a6eb3edbf45 25-Apr-2016 Chih-Hung Hsieh <chh@google.com> Fix google-explicit-constructor warnings.

Bug: 28341362
Change-Id: I2cf746fd07addc6e6c22e98e2a5bb8a8ce47c885
/system/core/logd/LogBuffer.cpp
8fa8896d2ed97eb274c62f0e386dabf2e2a82a45 26-Jan-2016 Mark Salyzyn <salyzyn@google.com> logd: security buffer only AID_SYSTEM reader

- limit AID_SYSTEM uid or gid to read security buffer messages
- adjust liblog tests to reflect the reality of this adjustment

To fully test all security buffer paths and modes

$ su 0,0,0 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*
$ su 1000,1000,1000 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*
$ su 2000,2000,2000 /data/nativetest/liblog-unit-tests/liblog-unit-tests --gtest_filter=liblog.__security*

ToDo: Integrate the above individually into the gTest Q/A testing

Bug: 26029733
Change-Id: Idcf5492db78fa6934ef6fb43f3ef861052675651
/system/core/logd/LogBuffer.cpp
7fd6c5c6f5f55e680a67cd9ca949f9c85b0ac0d0 20-Jan-2016 Mark Salyzyn <salyzyn@google.com> logd: prune maintain per-id watermark (part deux)

iterator corruption as we allow mLast to slip through the FIFO

Bug: 23685592
Bug: 26646087
Change-Id: Ifcbaecf390ee47b195c3d823d080c66c15db4530
/system/core/logd/LogBuffer.cpp
507eb9fec2b062e02cac0b76e35fb435cc9bf3d7 11-Jan-2016 Mark Salyzyn <salyzyn@google.com> logd: prune maintain per-id watermark

Without this change LogBuffer::prune and LogBuffer::erase
contributes 16.7% and 1.79% respectively. With this change,
they contributes 3.06 and 2.33% respectively. Pruning is
performed roughly 1 in every 255 log entries, a periodic
tamer latency spike.

Bug: 23685592
Change-Id: I6ae1cf9f3559bca4cf448efe8bcb2b96a1914c54
/system/core/logd/LogBuffer.cpp
1a5bac2069c3b8a0f4b5ede91ec4f83be5509827 06-Jan-2016 Mark Salyzyn <salyzyn@google.com> Merge "Revert "logd: liblog: whitelist "snet_event_log"""
0ee8de3c2df48c579a12e60299ff820ebf3db12a 06-Jan-2016 Mark Salyzyn <salyzyn@google.com> Revert "logd: liblog: whitelist "snet_event_log""

Callers will not guarantee that they can or will ratelimit, we need to
retain the ability to blacklist snet_event_log as a result.

This reverts commit 6aa21b225dd1600473388bd640443653d649420a.

Bug: 26178938
Change-Id: Ibf47d2e23a84c56f5f72d02312c698df7ff2b601
/system/core/logd/LogBuffer.cpp
66607ebc0e451d239b7b15a8794cfd7bec992e6c 05-Jan-2016 Mark Salyzyn <salyzyn@google.com> logd: document ro.logd.size

Bad comment advise in LogBuffer.cpp results in partners failing to
considering using ro.logd.size to set the platform buffer size
default.

NB: It is not good practice to increase the log buffer size to deal
with logspam, as increases will result in logd scale issues getting
closer to hitting the background cgroup cpu cap. Once we hit that
cap, logd spirals, pruning old entries slower than the incoming log
entries. logd.writer will take 100% cpu.

Change-Id: If4a7a74f300d078eeaed0ffd3eb3fd77d1f9fe90
/system/core/logd/LogBuffer.cpp
6aa21b225dd1600473388bd640443653d649420a 23-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: liblog: whitelist "snet_event_log"

Dangerous bridge to cross to whitelist, who is special, who is not?
Rationalized as these events are used to catch exploits on platform.
As it stands no one should be allowed to block any messages in the
security context, not even for development purposes.

Bug: 26178938
Change-Id: Ibdc76bc0fe29ba05be168b623af1c9f41d7edbd2
/system/core/logd/LogBuffer.cpp
bec3c3def945576d59d3344c16e149e6d9154e15 28-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: Add worst pid of system filter

- Add a new statistic that reports per pid and log_id for AID_SYSTEM
- Add a new pruning filter ~1000/! boolean
- Use this new statistic to prune on worst pid within AID_SYSTEM

Bug: 26029733
Bug: 21615139
Bug: 22855208
Change-Id: Iab5dd28f807dcf03d276372853883f3b6afa8294
/system/core/logd/LogBuffer.cpp
9c66a58f216e88e46f4ceacbd54599c28a20a729 15-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: Allow flags "eng" and "svelte" in boolean

- enhance property_get_bool, drop property_get_bool_svelte
- enhance base properties with ro and persist variants
- update and fortify README.property
- primarily move auditd and kernel logger into a realm where
they can be controlled by build properties.
- Move logd.klogd to logd.kernel, and add ro.logd.kernel
and persist.logd.kernel.
- Add ro.logd.auditd and persist.logd.auditd.
- Document persist.logd.security
- Document log.tag and persist.logd.tag properties.
- Document ro.logd.size, persist.logd.size and logd.size
properties.

Bug: 26178938
Bug: 26029733
Bug: 17760225
Change-Id: Ibc1a497e45d69db5cf52133937f7ba6fb1d6cd21
/system/core/logd/LogBuffer.cpp
ee3b838e13dc2140ac2051c1012d471effd0fd5f 17-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: statistics per-pid filter

Primarily gives access to the Chattiest TIDs and TAGs
associated with a pid.

Has a secondary effect of allowing us to pull out the
command line, comm and in some cases the associated
PACKAGE for a specific pid while the logs are still
present even if the executable is gone.

Bug: 26029733
Bug: 21615139
Change-Id: I1ea63165a680a9318360579b70b1512078ed5682
/system/core/logd/LogBuffer.cpp
cdda62b2c1178eca8cb9f5d8c775190736a98e3b 14-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: ro.config.low_ram set buffer size to 64K

Bug: 25792367
Change-Id: Icae85a7de70b3a71f89b2bf8c80866649f727177
/system/core/logd/LogBuffer.cpp
86052a5d4f217a73c769c77f7ac0904b65e67942 11-Dec-2015 Mark Salyzyn <salyzyn@google.com> Merge "logd: liblog: logcat: Add LOG_ID_SECURITY"
7b87365ecf8c08307173537645b85708f59aab78 04-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: readlog apps get logger_entry_v4

Adds the uid field to outgoing content for readlog applications.
AID_LOG, AID_ROOT and AID_SYSTEM gain access to the information.

Bug: 25996918
Change-Id: I0254303c19d174cbf5e722c38844be5c54410c85
/system/core/logd/LogBuffer.cpp
083b037c0740ca00f72429e4457bfdd4b4d4dfa7 04-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: Add LOG_ID_SECURITY

- Largish commit, buffer and access controls done together
- Add LOG_ID_SECURITY binary content log
- Add "default" meta buffer
- allow LOG_ID_SECURITY only from AID_SYSTEM and AID_ROOT UID & GID
- Use __android_log_security() to gate logging
- Add __android_log_security_bwrite() native access to security
logging.
- Add liblog.__security_buffer end-to-end gTest

Bug: 26029733
Change-Id: Ibcf5b4660c17c1aa6902c0d93f8ffd29c93d9a93
/system/core/logd/LogBuffer.cpp
b75cce0389748bea111ca62af623645117e12d9d 30-Nov-2015 Mark Salyzyn <salyzyn@google.com> logd: wakeup on wrap or timeout

If a timeout is specified for the reader, then go to sleep
with the socket open. If the start time is about to get
pruned in the specified log buffers, then wakeup and dump
the logs; or wakeup on timeout, whichever comes first.

Bug: 25929746
Change-Id: I7d2421c2c5083b33747b84f74d9a560d3ba645df
/system/core/logd/LogBuffer.cpp
ba7a9a016bf011fdf45b6736d4c6d6795faba9d3 02-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: switch to android_log_clockid() (2)

android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I38dee773bf3844177826b03a26b03215c79a5359
/system/core/logd/LogBuffer.cpp
9e18cdcebd893fbbb2369d893be219a7d832865f 07-Dec-2015 Mark Salyzyn <salyzyn@google.com> Revert "logd: liblog: logcat: switch to android_log_clockid()"

This reverts commit 77b5696b1dea6f7afed89e113e479f4a131c14fc.

Change-Id: I7711bf1a7e3f72ed29a2498d7287b725a0e624bd
/system/core/logd/LogBuffer.cpp
77b5696b1dea6f7afed89e113e479f4a131c14fc 02-Dec-2015 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: switch to android_log_clockid()

android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()

Bug: 23668800
Change-Id: I3c4e3e6b87f6676950797f1f0e203b44c542ed43
/system/core/logd/LogBuffer.cpp
c2e7d4965f86dbe90cece6d25e91d934a698d195 16-Nov-2015 Mark Salyzyn <salyzyn@google.com> Revert "liblog: resolve deadlocks"

This reverts commit 7a2a3071921b11d7e476862e7f9cbe72be43d0f7.

Bug: 25693940
Change-Id: I9a7c926289e972f80c03c92e33535e1dedaa7381
/system/core/logd/LogBuffer.cpp
7a2a3071921b11d7e476862e7f9cbe72be43d0f7 06-Nov-2015 Mark Salyzyn <salyzyn@google.com> liblog: resolve deadlocks

Although ever present, an increased regression introduced with
commit b6bee33182cedea49199eb2252b3f3b442899c6d (liblog: logd:
support logd.timestamp = monotonic).

A signal handler can interrupt in locked context, if log is written
in the signal handler, we are in deadlock. Block signals while we
are locked. Separate out timestamp lock from is loggable lock to
reduce contention situations. Provide a best-guess response if
lock would fail in timestamp path.

Bug: 25563384
Change-Id: I6dccd6b99ebace1c473c03a785a35c63ed5c6a8a
/system/core/logd/LogBuffer.cpp
8897a3fffd28c779dcfd8e5988ae90f5da7b5a88 04-Nov-2015 Mark Salyzyn <salyzyn@google.com> Merge "liblog: logd: support logd.timestamp = monotonic"
50122695d218232d88ffde5c3fc3e93021971080 12-Oct-2015 Mark Salyzyn <salyzyn@google.com> logd: pruning time horizon

Estimate a time horizon of ten fold for worst UID pruning

Bug: 24782000
Change-Id: I7118deb6d42531c68ed2ac2a59c57b0580b942cc
/system/core/logd/LogBuffer.cpp
b6bee33182cedea49199eb2252b3f3b442899c6d 08-Sep-2015 Mark Salyzyn <salyzyn@google.com> liblog: logd: support logd.timestamp = monotonic

if ro.logd.timestamp or persist.logd.timestamp are set to the value
monotonic then liblog writer, liblog printing and logd all switch to
recording/printing monotonic time rather than realtime. If reinit
detects a change for presist.logd.timestamp, correct the older entry
timestamps in place.

ToDo: A corner case condition where new log entries in monotonic time
occur before logd reinit detects persist.logd.timestamp, there
will be a few out-of-order entries, but with accurate
timestamps. This problem does not happen for ro.logd.timestamp
as it is set before logd starts.

NB: This offers a nano second time accuracy on all log entries
that may be more suitable for merging with other system
activities, such as systrace, that also use monotonic time. This
feature is for debugging.

Bug: 23668800
Change-Id: Iee6dab7140061b1a6627254921411f61b01aa5c2
/system/core/logd/LogBuffer.cpp
58b8be8906f903ac3d83c41bcb0fb9c7841945f0 30-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: correct for number of elements in prune

Chatty logs would distort the average log size by elevating the
elements, but not the size. Add statistical collection for the
number of elements that report chatty, and subtract that from
the number of elements to improve the pruning estimate. Pick
minElements as 1% rather than 10% of the total with this more
accurate number of elements, to a minumum of 4.

Bug: 24511000
Change-Id: I3f36558138aa0b2a50e4fac6440c3a8505d95276
/system/core/logd/LogBuffer.cpp
aaad42f47c7363d68ddfb9ef8f1b51972c4d429d 30-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: use coalesce instead of merge (cleanup)

- switch to coalesce instead of merge in naming of functions
and variables. Confusing since we also to merge-sorts and
other activities in the logger.
- define maxPrune rather than using a number in the code path.

Bug: 24511000
/system/core/logd/LogBuffer.cpp
2b25c66070f73413013caa48e1c171cb895869b5 17-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: clearAll by UID speedup

- If doing a clear, skip accounting
- Ensure for busy checking, behind a region lock for instance, only
break out if there was something to do. Basically move the filter
actions first, and defer checking the region lock to the ends of
the loops.

Bug: 23711431
Change-Id: Icc984f406880633516fb17dda84188a30d092e01
/system/core/logd/LogBuffer.cpp
c5dc970edc202f89ecdd0c2fe988c7e2b8408bef 17-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: clear return and deal with busy if readers locked

- Propagate to caller the clearing errors, busy blocked by reader.
- For clear, perform retries within logd with a one second lul each,
telling readers to skip, but on final retry to kill all readers if
problem still persists due to block reader (or high volume logspammer).

Bug: 23711431
Change-Id: Ie4c46bc9480a7f49b96a81fae25a95c603270c33
/system/core/logd/LogBuffer.cpp
5bb2972dce918b60f1ed9ddc6fe0636e97679187 08-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: worst uid record watermark part five

A regression that resulted in increased memory consumption for some
logging patterns because we rarely did merge or leading checks, and
age-out checking. On the last prune cycle, we reset for a full scan.

Add some comments describing the pruning processes.

Bug: 23327476
Bug: 23681639
Bug: 23685592
Change-Id: I22b0f339c9269b006831fda9cefe295a263ebb92
/system/core/logd/LogBuffer.cpp
831aa297307a038705bc771281ffd53266484b4a 04-Sep-2015 Mark Salyzyn <salyzyn@google.com> logd: worst uid record watermark part four

With part deux we caused an apparent regression by not checking for
stale recorded iterators. This checking was on-purpose bypassesed
when leading prune entries were to be deleted without touching the
statistics engine due to an in-place merge.

Part deux had us leaving iterators we were not focussed on untouched
which in turn because they were left behind, had a much higher
likelihood of being deleted without touching the statistics engine.

Perform the check every delete.

Bug: 23789348
Change-Id: Idc6cc23d1f9e3b6cd9a083139a0de59479fbfe08
/system/core/logd/LogBuffer.cpp
ccfe8446a19c1c0c9e55133fde84dedb2b9f5d4f 24-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: worst uid record watermark part three

Regression that cause records to be preserved for more than a day.

Bug: 23681639
Bug: 23685592
Change-Id: I5e4393c8e3ed935790994c77ec51dc6512a6daa6
/system/core/logd/LogBuffer.cpp
49afe0d00fdc163e5b8a1ab2f859c4688613d5b8 24-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: worst uid record watermark part deux

Only record watermark if not known, or represents the worst UID
currently under focus. This has resulted in a halving of the average
prune time in the face of heavy spam because we get less processing
spikes.

Bug: 23327476
Change-Id: I19f297042b9fc2c98d902695c1c36df1bf5cd6f6
/system/core/logd/LogBuffer.cpp
73160acc5cb5236b30327569e6b51dbfe73e4a0f 20-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: switch asprintf to std::string

Bug: 23350706
Change-Id: I715cdd4563a09de3680081947a3439f0cac623be
/system/core/logd/LogBuffer.cpp
c892ea3fa80dfd3d35c5a3b8bfdc73e7b85eaede 20-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: worst uid record watermark

Hold on to last worst uid watermark and bypass a spike to O(n*n*x)
(n=samples, x=number of spammers) wrt chatty trimming.

Bug: 23327476
Change-Id: I9f21ce95e969b67e576417a760f75c4d86acf364
/system/core/logd/LogBuffer.cpp
b39ed0c9925356c74a6347630b04d875288d803b 19-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: prune 10% or 256 entries max

Bug: 22351810
Bug: 23327476
Change-Id: I902ba6b431d8b7cee2d65ee2f76e9f7c4f30b152
/system/core/logd/LogBuffer.cpp
62ab0fd4efeed313adf2fdf84167d754620c0ad1 10-Aug-2015 Mark Salyzyn <salyzyn@google.com> logd: sizes > 1M prune in smaller batches

Switch to 1% batch sizes from 10% when individual buffer size > 1M

Bug: 22351810
Change-Id: Ifee570a54643ceb0ba767e1787e937f70cc90b72
/system/core/logd/LogBuffer.cpp
e59c469fa89d438d2d7150b7d8cd6b401900709b 02-Oct-2014 Mark Salyzyn <salyzyn@google.com> logd: filter on __android_log_is_loggable

- Default level when not specified is ANDROID_LOG_VERBOSE
which is inert.

Bug: 20416721
Bug: 19544788
Bug: 17760225
Change-Id: Icc098e53dc47ceaaeb24ec42eb6f61d6430ec2f6
/system/core/logd/LogBuffer.cpp
047cc0729fd837a03b99db901941c1421ef15f96 04-Jun-2015 Mark Salyzyn <salyzyn@google.com> logd: filters remove leading expire messages and rate

- Cleanup resulting from experience and feedback
- When filtering inside logd, drop any leading expire messages, they
are cluttering up leading edge of tombstones (which filter by pid)
- Increase and introduce EXPIRE_RATELIMIT from 1 to 10 seconds
- Increase EXPIRE_THRESHOLD from 4 to 10 count
- Improve the expire messages from:
logd : uid=1000(system) too chatty comm=com.google.android.phone,
expire 2800 lines
change tag to be more descriptive, and reduce accusatory tone to:
chatty : uid=1000(system) com.google.android.phone expire 2800
lines
- if the UID name forms a prefix for comm name, then drop UID name

Change-Id: Ied7cc04c0ab3ae02167649a0b97378e44ef7b588
/system/core/logd/LogBuffer.cpp
511338dd575572d567c04d69eaea60627b6c3452 19-May-2015 Mark Salyzyn <salyzyn@google.com> logd: switch to unordered_map from BasicHashtable

BasicHashtable is relatively untested, move over to
a C++ template library that has more bake time.

Bug: 20419786
Bug: 21590652
Bug: 20500228
Change-Id: I926aaecdc8345eca75c08fdd561b0473504c5d95
/system/core/logd/LogBuffer.cpp
10a124d342530b4c366f08d3a899474c4e5eb7fc 01-Jun-2015 Mark Salyzyn <salyzyn@google.com> Merge "logd: whitelist should not preserve expire messages"
5921276a16528bf79292e828080bf0ec984cbb23 01-Jun-2015 Mark Salyzyn <salyzyn@google.com> logd: KISS & fix preserve a day

Code in 833a9b1e38ce65f2cdf3ebd095aaa99a92eb9467 was borken,
simpler approach is to simply check last entry (to save a
syscall) minus EXPIRE_HOUR_THRESHOLD. This does make longer logs
less likely to call upon the spam detection than the algorithm
being replaced, but sadly we ended up with a log entry in the
future at the beginning of the logs confounding the previous
algorithm.

Bug: 21555259
Change-Id: I04fad67e95c8496521dbabb73b5f32c19d6a16c2
/system/core/logd/LogBuffer.cpp
5392aac95d279a7ffc91d8fbcd074307186ca36c 22-May-2015 Mark Salyzyn <salyzyn@google.com> logd: deal with sloppy leading expire messages

The odds of chatty content also leading the logs is pretty high eg:

1799 12017 I logd: uid=10007 chatty comm=Binder_B, expire 4 lines
1799 1829 I logd: uid=10007 chatty comm=Binder_2, expire 4 lines
1919 20637 I logd: uid=10007 chatty comm=m.sersistent, expire 1 line
1919 20638 I logd: uid=10007 chatty comm=s.persistent, expire 1 line
1919 2316 I logd: uid=10007 chatty comm=UlrDispatch, expire 4 lines
19379 20634 I logd: uid=10045 chatty, expire 14 lines
19379 19388 I logd: uid=10045 chatty comm=lizerDaemon, expire 4 lines
591 4396 I logd: uid=1000 chatty comm=Thread-220, expire 5 lines
591 1377 I logd: uid=1000 chatty comm=Thread-92, expire 4 lines
1919 2267 I logd: uid=10007 chatty comm=WifiScanner, expire 4 lines
591 4397 I logd: uid=1000 chatty comm=DhcpClient, expire 4 lines
591 4398 I logd: uid=1000 chatty comm=Thread-222, expire 4 lines
226 580 D CommandListener: Setting iface cfg

Change-Id: I5ab24bc7bf5d2690bae7e789831b07f23ff8bcc6
/system/core/logd/LogBuffer.cpp
c5bf3b830472bca677407833018f20b7643953fe 21-May-2015 Mark Salyzyn <salyzyn@google.com> logd: whitelist should not preserve expire messages

Change-Id: I56275c73191b96aa21e7b4049d401e1f44211f9b
/system/core/logd/LogBuffer.cpp
833a9b1e38ce65f2cdf3ebd095aaa99a92eb9467 16-May-2015 Mark Salyzyn <salyzyn@google.com> logd: worst-UID only to preserve a day

Do not invoke worst-UID pruning in the face of other
UIDs logs that are more than a day old, switch to
pruning oldest only.

Change-Id: Icf988b8d5458400a660d0f8e9d2df3f9d9a4c2d9
/system/core/logd/LogBuffer.cpp
7718778793b106498b931dd708a466cf3a6f6a0f 13-May-2015 Mark Salyzyn <salyzyn@google.com> logd: Cleanup

- Android Coding Standard for Constructors
- Side effects NONE

Change-Id: I2cda9dd73f3ac3ab58f394015cb810820093d47b
/system/core/logd/LogBuffer.cpp
21fb7e0b753b2251369bfaa1c6f6a09e58e64437 20-Apr-2015 Mark Salyzyn <salyzyn@google.com> logd: improve details on chatty records

- Report applications UID, TID/PID by name.
- change wording to have an accurate connotation
- drop privilege check since filtered upstream

Bug: 19608965
Bug: 20334069
Bug: 20370119
Change-Id: I2b1c26580b4c2de293874214ff5ae745546f3cca
/system/core/logd/LogBuffer.cpp
35173a9ac5bd1f4702ccfda3df02ec47ecb57949 23-Apr-2015 Mark Salyzyn <salyzyn@google.com> logd: reduce chance of dropped 1 messages

- do not time out at 1 second if drop has count of less than 4

Bug: 20334069
Bug: 20370119
Change-Id: I787cb553dfab5ed71abd6ed72b63de675f834e0c
/system/core/logd/LogBuffer.cpp
653f9581bf32cc2532c2b1d442d7bb2bbf0c173e 23-Apr-2015 Mark Salyzyn <salyzyn@google.com> Merge "logd: per UID less aggressive 12.5% threshold"
e06a6e0f26f51a8f1aab84076d5241ae820069b7 20-Apr-2015 Mark Salyzyn <salyzyn@google.com> logd: ratelimit drop messages to 1/sec

Bug: 20334069
Bug: 20370119
Change-Id: I6f850aec46c4df1c99a5b1f28db75d071e134ad5
/system/core/logd/LogBuffer.cpp
d717d805d4d636a837ccfba87c78b0dc89cb8fd9 21-Apr-2015 Mark Salyzyn <salyzyn@google.com> logd: per UID less aggressive 12.5% threshold

Per-UID quota has a threshold of 12.5% of the total log size.
If less than that space is taken by the UID, then we
will not engage the pruning based on worst UID.

Change-Id: I9f15c9a26938f1115eb75e9c28ddb073e7680e06
/system/core/logd/LogBuffer.cpp
2c9d909a00a6b0dd7f17402f3f0d94d5fd76c8c3 18-Apr-2015 Mark Salyzyn <salyzyn@google.com> logd: better drop message merging

- Former algorithm anlo coalesced adjacent records
- New algorithm maintains a hash list of all drop
records and coalesces them all.

Bug: 20334069
Bug: 20370119
Change-Id: Idc15ce31fc1087c2cfa39da60c62feade8b88761
/system/core/logd/LogBuffer.cpp
202e153f94a0957185ae4b4bed4c5356513e4322 09-Feb-2015 Mark Salyzyn <salyzyn@google.com> logd: propagate ::log status

Add a return value for the ::log() methods, this allows
us to optimize the wakeup for the readers to only occur
when the log message is actually placed.

This is for a future where we may dedupe identical log
messages, filter out log messages, and certainly if we
filter the messages out with an internal logd check of
__android_log_is_loggable().

Change-Id: I763b2a7c29502ab7fa0a5d5022c7b60244fcfde4
/system/core/logd/LogBuffer.cpp
ae769238391f7f9fa5c03a436d5f1fd73130e6bd 18-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: disable worst uid prune for events buffer

There is some usage statistics that would be hurt by pruning by UID,
since _all_ usage statistics come from system_server. In other words
we expect it to be chatty. Until we formulate and evaluate a better
(eg: per-tag?) filtration mechanism, lets hold off pruning by UID.

Bug: 19608965
Change-Id: Iddd45a671e13bdcf3394c20919ad1f2e4ef36616
/system/core/logd/LogBuffer.cpp
ab0dcf682867bd7e1fdebfd8d8f9fafaccfad7f6 16-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: annotate worst-UID pruned entries

- internal dropped entries are associated by prune by worst UID
and are applied by UID and by PID
- track dropped entries by rewriting them in place
- merge similar dropped entries together for same UID(implied),
PID and TID so that blame can more clearly be placed
- allow aging of dropped entries by the general backgound pruning
- report individual dropped entries formatted to reader
- add statistics to track dropped entries by UID, the combination
of statistics and dropped logging can track over-the-top Chattiest
clients.

Bug: 19608965
Change-Id: Ibc68480df0c69c55703270cd70c6b26aea165853
/system/core/logd/LogBuffer.cpp
720f6d1d55d936d98cc9752e96f479e03e6d5009 16-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: Add Pid statistics

- Optional class of statistics for PID
- Enhance pidToName
- Enhanced uidToName
- Enhance pidToUid
- template sort and iteration

Bug: 19608965
Change-Id: I04a1f02e9851b62987f9b176908134e455f22d1d
/system/core/logd/LogBuffer.cpp
97c1c2beee2cbd8c67c1cd507367e5b084d853c8 10-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: optimize statistics

- Go back to basic requirements
- Simplify
- use hash tables to minimize memory impact

Bug: 19608965
Change-Id: If7becb34354d6415e5c387ecea7d4109a15259c8
/system/core/logd/LogBuffer.cpp
f7c0f75275d0fde2d8b7614f1501f0ad0cd3a01c 03-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: replace internal CLOCK_MONOTONIC use with sequence numbers

- switch to simpler and faster internal sequence number, drops
a syscall overhead on 32-bit platforms.
- add ability to break-out of flushTo loop with filter return -1
allowing in reduction in reader overhead.

Change-Id: Ic5cb2b9afa4d9470153971fc9197b07279e2b79d
/system/core/logd/LogBuffer.cpp
11e55cb9c1e5efe553e36f1b5c04ab21883f66e1 11-Mar-2015 Mark Salyzyn <salyzyn@google.com> logd: add reinit command

- respond to SIGHUP
- respond to logd command "reinit"
- respond to logd --reinit
- reopens files on /data, eg: re-read of persistent properties

Bug: 19681572
Change-Id: Iadac58e6653f027cb7355497bd675eef376ce0a8
/system/core/logd/LogBuffer.cpp
4ed16b4381e6723670575ff8da3cfe12fe74998a 03-Mar-2015 Mark Salyzyn <salyzyn@google.com> Revert "logd: Add minimum time bucket statistics"

This forward port reverts
commit e457b74ce6ee6d799812dc2ec5e4b8b18bcd3e91

No longer as necessary once we add
liblog: Instrument logging of logd write drops
Although this provided an indication of how close statistically we
were to overloading logd it is simpler to understand fails thus to
hunt and peck a corrected value for /proc/sys/net/unix/max_dgram_qlen

Change-Id: I2b30e0fc30625a48fd11a12c2d2cc6a41f26226f
/system/core/logd/LogBuffer.cpp
8e8e8db549ffa6e692246abce6f5560c3a1e93c2 15-Jan-2015 Dragoslav Mitrinovic <drago@motorola.com> logd: fix persistent blocking reader performance

logd suffers major performance degradation when persistent (blocking)
client reader connects to it (e.g. logcat). The root cause of the
degradation is that each time when reader is notified of the arrival
of new log entries, the reader commences its search for the new entries
from the beginning of the linked list (oldest entries first).

This commit alters the search to start from the end of the linked list
and work backwards. This dramatically decreases logd CPU consumption
when blocking reader is connected, and increases the maximum logging
throughput (before the logs start getting lost) by a factor ~ 20.

Change-Id: Ib60955ce05544e52a8b24acc3dcf5863e1e39c5c
/system/core/logd/LogBuffer.cpp
da6495d06f1798ea81cebbfbdd44f16135e1a3cd 17-Dec-2014 TraianX Schiau <traianx.schiau@intel.com> logd: Fix pruning

In a scenario in which an on-line (blocking) client is running and
a clean is attempted (logcat -c), the following can be observed:

1) the on-line logger seems to freeze
2) any other clear attempt will have no effect

What is actually happening:

In this case prune function will "instruct" the oldest timeEntry
to skip a huge number (very close to ULONG_MAX) of messages, this
being the cause of 1.

Since the consumer thread will skip all the log entries, mStart
updating will also be skipped. So a new cleaning attempt will have
the same oldest entry, nothing will be done.

Fix description:
a. keep a separated skipAhead count for individual log buffers (log_id_t)
LogTimeEntry::LogTimeEntry
LogTimeEntry::FilterSecondPass
LogTimeEntry::skipAhead
LogTimeEntry::riggerSkip_Locked

b. update LogTimeEntry::mStart even if the current message is skipped
LogTimeEntry::FilterSecondPass

c. while pruning, only take into account the LogTimeEntrys that are monitoring
the log_id in question, and provide a public method of checking this.
LogTimeEntry::isWatching
LogTimeEntry::FilterFirstPass
LogTimeEntry::FilterSecondPass

d. Reset the skip cont befor the client thtread starts to sleep, at this point
we should be up to date.
LogTimeEntry::cleanSkip_Locked
LogTimeEntry::threadStart

Change-Id: I1b369dc5b02476e633e52578266a644e37e188a5
Signed-off-by: TraianX Schiau <traianx.schiau@intel.com>
/system/core/logd/LogBuffer.cpp
eae155e1ce9c496c2af71a5e56cb182484f10531 14-Oct-2014 Mark Salyzyn <salyzyn@google.com> logd: insert order for first entry

Change-Id: I39e8e6d32407a1796a0c3a121f9dc4dc5402c3df
/system/core/logd/LogBuffer.cpp
e72c6e43668c8c6e1af77e2e5038557581cbf148 21-Sep-2014 Mark Salyzyn <salyzyn@google.com> logd: cleanup

- simplify access and control exposure to class list
- indent
- compile warning
- Follow standard naming convention for variables and methods
- merge common fragments
- Side Effects: none

Change-Id: I74796043ac34753c6dd10018719ebc0bcd94e010
/system/core/logd/LogBuffer.cpp
1a240b47903c0dc3d7f23b609b6520f17f11b953 12-Jun-2014 Mark Salyzyn <salyzyn@google.com> logd: Allow apps to clear their UID-specific data

Bug: 13501501
Change-Id: Ia72e25fc19430ce63fb359cd9b3f0523d41f5aa8
/system/core/logd/LogBuffer.cpp
ab4b7308ecd8a425cdeb3e289fcfeda0e08085be 23-May-2014 Mark Salyzyn <salyzyn@google.com> logd: used before set warning

Change-Id: I30c078f8b22ebe4dcb48d57adf88b3e51b4fa202
/system/core/logd/LogBuffer.cpp
57a0af93133ad0d190a79372b702653f96b99fe8 10-May-2014 Mark Salyzyn <salyzyn@google.com> init: logd: Allow Developer settings to adjust logd size

- AID_SYSTEM can set persist.logd.size
- AID_SYSTEM can issue command to /dev/socket/logd to
change the runtime global log sizes.
- Add support for ro.logd.size.* as populated by BoardConfig.mk
- Limit size to maximum ~3% of physical memory.

Bug: 14563261
Bug: 14627052
Change-Id: I606420db2e9d9d032296e71149e4a5b20cbd1137
/system/core/logd/LogBuffer.cpp
671e343c7d9c832eca093325c0b8b934c47a83b4 06-May-2014 Mark Salyzyn <salyzyn@google.com> logd: logcat: Add persist.logd.size group of properties

- logd Add persist.logd.size (global), persist.logd.size.<logid>
- logcat report a more flexible multiplier in -g command.

Bug: 14563261
Bug: 14469172
Change-Id: Ie389caa14ad3ae3d4a3a3cc463425bb9dbc5e483
/system/core/logd/LogBuffer.cpp
c8a576c637ae00577273b778498019dd609fcd15 05-Apr-2014 Mark Salyzyn <salyzyn@google.com> logd: Statistics improvements

- Drop in-place sorting.
- Add fast-track for uid sizes and elements.
- Add sort() for per-uid and per-pid statistics.

Change-Id: Ib8655d4cc0b3bd4e87534522987bcc7fc7a5251a
/system/core/logd/LogBuffer.cpp
99f47a9e7c4374f2bbfc18e4a97aa7848245ea33 07-Apr-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: debuggerd: Add LOG_ID_CRASH

Change-Id: Iea453764a1a4fc1661f461f10c641c30150e4d20
/system/core/logd/LogBuffer.cpp
1c950479393d42d18829d4009dbdb3a7f03acbb7 02-Apr-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: enable prune features for user

- Enable whitelist, blacklist and logsize tuneables for user

Change-Id: Id0c283844c71c5263a8cfbebf2e550f7ac415858
/system/core/logd/LogBuffer.cpp
ca4c63d7994e66b45e9ebeb62e417b7da904b87c 02-Apr-2014 Mark Salyzyn <salyzyn@google.com> logd: build breakage in user

build breakage in branch: git_klp-dev-gpl @ 1101951

Change-Id: I4c9681bf4c97368ec19f5a79fef134aba937f337
/system/core/logd/LogBuffer.cpp
e457b74ce6ee6d799812dc2ec5e4b8b18bcd3e91 20-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: Add minimum time bucket statistics

* Only enabled for dev builds because halves performance.
- Used to establish if /proc/sys/net/unix/max_dgram_qlen
is appropriate for the platform
(see logd/LogStatistics.cpp comments)
- enabled if logd.dgram_qlen.statistics is not zero/empty

Change-Id: Ib8ecfeb75b6f0f954c099a6b1032b8afb5efcbd4
/system/core/logd/LogBuffer.cpp
b992d0d7d34bed62fd16151a68d60d58cc8003ef 21-Mar-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: Thread IDs missing from logcat -v thread

- stuff caller's thread id into the packet.

Bug: 13568206
Change-Id: I02d0cdf9b1d9e839ff8969f591db42dfe6e4cc95
/system/core/logd/LogBuffer.cpp
dfa7a07f5be656cfafdb4e75916bc9dcd9e592e7 11-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: Add LogWhiteBlackList

- liblog android_logger_get_log_size and android_logger_get_readable_size
adjusted to return long instead of int because of -G flag extending range

NB: ifdef'd only for userdebug and eng builds

- liblog Add android_logger_[sg]et_prune_list and android_logger_set_log_size
- logcat Add -P, -p and -G flags
- logd Add LogWhiteBlackList and configurable log size

(cherry picked from commit 18a5432158ad43b8faefe4950b30e760200ce0b4)

Change-Id: I1572338c1b34bd968ad7867857ef708156ec3b6a
/system/core/logd/LogBuffer.cpp
64d6fe936253b336049c285369a56cf139bd002f 07-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: prune by worst offending UID

(cherry picked from commit 3c4919e4748d32d7f3e147ab57f4fafee28c7447)

Change-Id: I39965007569123ff5eebe01b5bfa555bbcb2dfe7
/system/core/logd/LogBuffer.cpp
34facab86b0fe7ec613de92b46b637f864fb0682 06-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: logcat: Add Statistics

- logd add statistical collection and formatting
- liblog add android_logger_get_statistics call
- logcat add -S flag
- logcat add -b all

(cherry picked from commit 51a29c8dc445e4fb89860561933e54a231e6ffb4)

Change-Id: I521753b1969ecd4590c956aeeb1557d101059d67
/system/core/logd/LogBuffer.cpp
7e2f83c0bcc3ad8a2840a48be14d302ed79d671c 05-Mar-2014 Mark Salyzyn <salyzyn@google.com> logd: liblog: 64-bit issues

- structure packing
- move towards log_time from struct timespec
- extend log_time to cover differences between
log_time and struct timespec

Change-Id: I106ed0b609917306d170044054b5b32645f2a295
/system/core/logd/LogBuffer.cpp
c03e72cc1c155ff668df8df1caec363b07347d0d 18-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: Adjust to match defacto coding style

(cherry picked from commit c46f77bd2ad01f3a695416c4cf22d6a9738bb7b8)

Change-Id: I80685cdc7116e10c5a5a77abe856fd96804f9117
/system/core/logd/LogBuffer.cpp
740f9b4f97d6311b29fa885e86413d51d8c92d53 14-Jan-2014 Mark Salyzyn <salyzyn@google.com> logd: prune more aggressively when over the top

(cherry picked from commit 63c15d50615a4c9e9ad25f601ef9dcb1161d8990)

Change-Id: I929dddc7da048c032fb791c7af23f215f8856bf3
/system/core/logd/LogBuffer.cpp
0175b0747a1f55329109e84c9a1322dcb95e2848 26-Feb-2014 Mark Salyzyn <salyzyn@google.com> logd: initial checkin.

* Create a new userspace log daemon for handling logging messages.

Original-Change-Id: I75267df16359684490121e6c31cca48614d79856
Signed-off-by: Nick Kralevich <nnk@google.com>

* Merge conflicts
* rename new syslog daemon to logd to prevent confusion with bionic syslog
* replace racy getGroups call with KISS call to client->getGid()
* Timestamps are filed at logging source
* insert entries into list in timestamp order
* Added LogTimeEntry tail filtration handling
* Added region locking around LogWriter list
* separate threads for each writer
* /dev/socket/logd* permissions

Signed-off-by: Mark Salyzyn <salyzyn@google.com>

(cherry picked from commit 3e76e0a49760c4970b7cda6153e51026af98e4f3)

Author: Nick Kralevich <nnk@google.com>
Change-Id: Ice88b1412d8f9daa7f9119b2b5aaf684a5e28098
/system/core/logd/LogBuffer.cpp