1logd can record and replay log messages for offline analysis. 2 3Recording Messages 4------------------ 5 6logd has a `RecordingLogBuffer` buffer that records messages to /data/misc/logd/recorded-messages. 7It stores messages in memory until that file is accessible, in order to capture all messages since 8the beginning of boot. It is only meant for logging developers to use and must be manually enabled 9in by adding `RecordingLogBuffer.cpp` to `Android.bp` and setting 10`log_buffer = new SimpleLogBuffer(&reader_list, &log_tags, &log_statistics);` in `main.cpp`. 11 12Recording messages may delay the Log() function from completing and it is highly recommended to make 13the logd socket in `liblog` blocking, by removing `SOCK_NONBLOCK` from the `socket()` call in 14`liblog/logd_writer.cpp`. 15 16Replaying Messages 17------------------ 18 19Recorded messages can be replayed offline with the `replay_messages` tool. It runs on host and 20device and supports the following options: 21 221. `interesting` - this prints 'interesting' statistics for each of the log buffer types (simple, 23 chatty, serialized). The statistics are: 24 1. Log Entry Count 25 2. Size (the uncompressed size of the log messages in bytes) 26 3. Overhead (the total cost of the log messages in memory in bytes) 27 4. Range (the range of time that the logs cover in seconds) 282. `memory_usage BUFFER_TYPE` - this prints the memory usage (sum of private dirty pages of the 29 `replay_messages` process). Note that the input file is mmap()'ed as RO/Shared so it does not 30 appear in these dirty pages, and a baseline is taken before allocating the log buffers, so only 31 their contributions are measured. The tool outputs the memory usage every 100,000 messages. 323. `latency BUFFER_TYPE` - this prints statistics of the latency of the Log() function for the given 33 buffer type. It specifically prints the 1st, 2nd, and 3rd quartiles; the 95th, 99th, and 99.99th 34 percentiles; and the maximum latency. 354. `print_logs BUFFER_TYPE [buffers] [print_point]` - this prints the logs as processed by the given 36 buffer_type from the buffers specified by `buffers` starting after the number of logs specified by 37 `print_point` have been logged. This acts as if a user called `logcat` immediately after the 38 specified logs have been logged, which is particularly useful since it will show the chatty 39 pruning messages at that point. It additionally prints the statistics from `logcat -S` after the 40 logs. 41 `buffers` is a comma separated list of the numeric buffer id values from `<android/log.h>`. For 42 example, `0,1,3` represents the main, radio, and system buffers. It can can also be `all`. 43 `print_point` is an positive integer. If it is unspecified, logs are printed after the entire 44 input file is consumed. 455. `nothing BUFFER_TYPE` - this does nothing other than read the input file and call Log() for the 46 given buffer type. This is used for profiling CPU usage of strictly the log buffer. 47