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