Skip to content
Commit 5371273f authored by Mike Ma's avatar Mike Ma
Browse files

More robust read mechanism in KernelCpuProcReader

KernelCpuProcReader used FileChannel to dump bytes into a large enough
ByteBuffer. However, FileChannel#read stops as soon as there is nothing
left to read. Since the kernel may not deliver all parts of a proc file
simultaneously, previous read mechanism would possibly read only a
portion of the proc file. The impact is that KernelUidCpuFreqTimeReader
gets an incomplete UID list.
New mechanism uses a loop to turn non-blocking FileChannel#read into a
blocking operation. It does not return until hitting EOF. The reason
not to use Files#readAllBytes is that we want to reuse the byte[].

Bug: 111805985
Test: atest KernelCpuProcReaderTest
Test: compared KernelCpuProcReader#readBytes against Files#readAllBytes
      locally
Change-Id: If0d2b6742489632e22c8fec34c627851cda875f2
parent 82b41342
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment