Open mlopatkin opened 2 years ago
It looks like the kernel
logs are still problematic in this regard. I haven't checked the implementation but I can imagine these logs being copied into the logger daemon's storage by some worker with the actual timestamp. This timestamp would be out of order with the other logs:
--------- switch to kernel
2022-01-09 17:27:01.658 I/logd ( 0): logdr: UID=2000 GID=2000 PID=3496 b tail=0 logMask=99 pid=0 start=0ns deadline=0ns
--------- switch to main
2022-01-09 17:27:01.637 W/dmesg ( 3499): type=1400 audit(0.0:14): avc: denied { syslog_read } for scontext=u:r:shell:s0 tcontext=u:r:kernel:s0 tclass=system permissive=0
--------- switch to kernel
2022-01-09 17:27:07.455 W/healthd ( 0): battery l=100 v=5000 t=25.0 h=2 st=4 c=900000 fc=300000 cc=10 chg=
2022-01-09 17:27:10.981 I/logd ( 0): logdr: UID=2000 GID=2000 PID=3500 n tail=0 logMask=99 pid=0 start=0ns deadline=0ns
--------- switch to main
2022-01-09 17:27:10.953 W/dmesg ( 3503): type=1400 audit(0.0:15): avc: denied { syslog_read } for scontext=u:r:shell:s0 tcontext=u:r:kernel:s0 tclass=system permissive=0
2022-01-09 17:27:12.782 E/android.hardware.power.stats@1.0-service-mock( 393): Failed to getEnergyData
Looks like time adjustments are more common than I thought. As expected, the heuristic added in #283 doesn't work well if not all buffers observe the time travel. Maybe we could do a better job by actually looking at timestamps and finding out affected timespans.
There are multiple reasons for the logs to appear "out-of-order":
The logcat itself before 5.0 was prone to printing log entries out of order, because there were separate log sources for each buffer, and logcat was doing timestamp comparison to determine which one to output first. It was solved for the logcat with the migration to a new "syslog" subsystem that stores log entries sequentially.
Andlogview has to collect logs separately in several concurrent logcat invocations, to properly assign buffer names to log entries (system, main, radio, etc). Moreover, ancient Android versions (Cupcake 1.5, Donut 1.6, and maybe Eclair) cannot print more than one buffer at a time anyway, so it is the only available approach there. This requires the tool to solve the issue similar to the logcat's one described above - combine multiple log streams based on the timestamps.
Our current approach is purely timestamp-based and doesn't take time travels into account at all, so the new log entries may be appended to the very beginning of the log. Even the ordering within a single buffer is not respected when merging. This is problematic.
This issue proposes several improvements:
NB: #215 tracks switching to use logcat dividers (
-D
), that allow to retrieve all log buffers in a single command with proper ordering coming from the system'slogd
. However, the switch is only available since 6.0 (Marshmallow).This is a more elaborate version of #105 which was closed as non-actionable.