An efficient proc file reader
A less resource hogging reader for reading proc files in string format. It is singleton and thread-safe, so all downstream clients share the same instance to avoid duplicate allocation. It reads the entire proc file all at once (to mimimize the impact to the kernel) into a reusable char[] buffer (to prevent frequent GC). A read lock is automatically held for the client when a valid file iterator is returned. Client MUST call close() to unlock it or take advantage of try-with-resources. The reader keeps an error counter. It rejects further requests if it has accumulated 5 errors, to prevent log spam. The reader also has a 500ms cache, which can be bypassed with a parameter. Bug: 111216804 Test: atest FrameworksCoreTests:com.android.internal.os.KernelCpuProcStringReaderTest Change-Id: Ifa5213a5c7baf95d62f74486815030d9aa54ca28
Loading
Please register or sign in to comment