There was a bug in SerializedFlushToState::Prune() caused by an access to a SerializedLogEntry raw pointer as a member of a MinHeapElement, which was deleted earlier in the function. Instead of just fixing the order of the access and the deletion, I sought out to remove the raw pointer entirely. In doing so, I noticed that the min heap doesn't provide significant benefit, since we'll only ever have 8 log buffers so scalability is not an issue. Therefore this change removes the min heap entirely and uses the existing log_position_ and logs_needed_from_next_position_ members to keep track of which are the next unread logs. It also adds a smoke test for SerializedFlushToState::Prune() and additional CHECK() statements to help prevent future errors. Bug: 168869299 Test: unit tests Change-Id: Id4d5fdbaff2fe6dc49c38f01e73f900f84d3696b |
||
|---|---|---|
| .. | ||
| doc_images | ||
| fuzz | ||
| .clang-format | ||
| Android.bp | ||
| AndroidTest.xml | ||
| auditctl.cpp | ||
| ChattyLogBuffer.cpp | ||
| ChattyLogBuffer.h | ||
| ChattyLogBufferTest.cpp | ||
| CommandListener.cpp | ||
| CommandListener.h | ||
| CompressionEngine.cpp | ||
| CompressionEngine.h | ||
| event.logtags | ||
| libaudit.cpp | ||
| libaudit.h | ||
| LogAudit.cpp | ||
| LogAudit.h | ||
| LogBuffer.h | ||
| LogBufferElement.cpp | ||
| LogBufferElement.h | ||
| LogBufferTest.cpp | ||
| LogBufferTest.h | ||
| logd.rc | ||
| logd_test.cpp | ||
| LogKlog.cpp | ||
| LogKlog.h | ||
| LogListener.cpp | ||
| LogListener.h | ||
| LogPermissions.cpp | ||
| LogPermissions.h | ||
| LogReader.cpp | ||
| LogReader.h | ||
| LogReaderList.cpp | ||
| LogReaderList.h | ||
| LogReaderThread.cpp | ||
| LogReaderThread.h | ||
| LogSize.cpp | ||
| LogSize.h | ||
| LogStatistics.cpp | ||
| LogStatistics.h | ||
| logtagd.rc | ||
| LogTags.cpp | ||
| LogTags.h | ||
| LogUtils.h | ||
| LogWriter.h | ||
| main.cpp | ||
| OWNERS | ||
| PruneList.cpp | ||
| PruneList.h | ||
| README.auditd | ||
| README.compression.md | ||
| README.property | ||
| README.replay.md | ||
| RecordedLogMessage.h | ||
| RecordingLogBuffer.cpp | ||
| RecordingLogBuffer.h | ||
| ReplayMessages.cpp | ||
| rwlock.h | ||
| SerializedData.h | ||
| SerializedFlushToState.cpp | ||
| SerializedFlushToState.h | ||
| SerializedFlushToStateTest.cpp | ||
| SerializedLogBuffer.cpp | ||
| SerializedLogBuffer.h | ||
| SerializedLogChunk.cpp | ||
| SerializedLogChunk.h | ||
| SerializedLogChunkTest.cpp | ||
| SerializedLogEntry.h | ||
| SimpleLogBuffer.cpp | ||
| SimpleLogBuffer.h | ||
logd can record and replay log messages for offline analysis.
Recording Messages
logd has a RecordingLogBuffer buffer that records messages to /data/misc/logd/recorded-messages.
It stores messages in memory until that file is accessible, in order to capture all messages since
the beginning of boot. It is only meant for logging developers to use and must be manually enabled
in by adding RecordingLogBuffer.cpp to Android.bp and setting
log_buffer = new SimpleLogBuffer(&reader_list, &log_tags, &log_statistics); in main.cpp.
Recording messages may delay the Log() function from completing and it is highly recommended to make
the logd socket in liblog blocking, by removing SOCK_NONBLOCK from the socket() call in
liblog/logd_writer.cpp.
Replaying Messages
Recorded messages can be replayed offline with the replay_messages tool. It runs on host and
device and supports the following options:
interesting- this prints 'interesting' statistics for each of the log buffer types (simple, chatty, serialized). The statistics are:- Log Entry Count
- Size (the uncompressed size of the log messages in bytes)
- Overhead (the total cost of the log messages in memory in bytes)
- Range (the range of time that the logs cover in seconds)
memory_usage BUFFER_TYPE- this prints the memory usage (sum of private dirty pages of thereplay_messagesprocess). Note that the input file is mmap()'ed as RO/Shared so it does not appear in these dirty pages, and a baseline is taken before allocating the log buffers, so only their contributions are measured. The tool outputs the memory usage every 100,000 messages.latency BUFFER_TYPE- this prints statistics of the latency of the Log() function for the given buffer type. It specifically prints the 1st, 2nd, and 3rd quartiles; the 95th, 99th, and 99.99th percentiles; and the maximum latency.print_logs BUFFER_TYPE [buffers] [print_point]- this prints the logs as processed by the given buffer_type from the buffers specified bybuffersstarting after the number of logs specified byprint_pointhave been logged. This acts as if a user calledlogcatimmediately after the specified logs have been logged, which is particularly useful since it will show the chatty pruning messages at that point. It additionally prints the statistics fromlogcat -Safter the logs.buffersis a comma separated list of the numeric buffer id values from<android/log.h>. For example,0,1,3represents the main, radio, and system buffers. It can can also beall.print_pointis an positive integer. If it is unspecified, logs are printed after the entire input file is consumed.nothing BUFFER_TYPE- this does nothing other than read the input file and call Log() for the given buffer type. This is used for profiling CPU usage of strictly the log buffer.