Loading core/proto/android/service/diskstats.proto +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ message DiskStatsServiceDumpProto { optional EncryptionType encryption = 5; // Cached values of folder sizes, etc. optional DiskStatsCachedValuesProto cached_folder_sizes = 6; // Average write speed of storaged benchmark for last 24 hours optional int32 benchmarked_write_speed_kbps = 7; } message DiskStatsCachedValuesProto { Loading services/core/java/com/android/server/DiskStatsService.java +47 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ package com.android.server; import android.content.Context; import android.os.Binder; import android.os.Environment; import android.os.IBinder; import android.os.IStoraged; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StatFs; import android.os.SystemClock; import android.os.storage.StorageManager; Loading Loading @@ -109,6 +113,12 @@ public class DiskStatsService extends Binder { } } if (protoFormat) { reportDiskWriteSpeedProto(proto); } else { reportDiskWriteSpeed(pw); } reportFreeSpace(Environment.getDataDirectory(), "Data", pw, proto, DiskStatsFreeSpaceProto.FOLDER_DATA); reportFreeSpace(Environment.getDownloadCacheDirectory(), "Cache", pw, proto, Loading Loading @@ -285,4 +295,41 @@ public class DiskStatsService extends Binder { Log.w(TAG, "exception reading diskstats cache file", e); } } private int getRecentPerf() throws RemoteException, IllegalStateException { IBinder binder = ServiceManager.getService("storaged"); if (binder == null) throw new IllegalStateException("storaged not found"); IStoraged storaged = IStoraged.Stub.asInterface(binder); return storaged.getRecentPerf(); } // Keep reportDiskWriteSpeed and reportDiskWriteSpeedProto in sync private void reportDiskWriteSpeed(PrintWriter pw) { try { long perf = getRecentPerf(); if (perf != 0) { pw.print("Recent Disk Write Speed (kB/s) = "); pw.println(perf); } else { pw.println("Recent Disk Write Speed data unavailable"); Log.w(TAG, "Recent Disk Write Speed data unavailable!"); } } catch (RemoteException | IllegalStateException e) { pw.println(e.toString()); Log.e(TAG, e.toString()); } } private void reportDiskWriteSpeedProto(ProtoOutputStream proto) { try { long perf = getRecentPerf(); if (perf != 0) { proto.write(DiskStatsServiceDumpProto.BENCHMARKED_WRITE_SPEED_KBPS, perf); } else { Log.w(TAG, "Recent Disk Write Speed data unavailable!"); } } catch (RemoteException | IllegalStateException e) { Log.e(TAG, e.toString()); } } } Loading
core/proto/android/service/diskstats.proto +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ message DiskStatsServiceDumpProto { optional EncryptionType encryption = 5; // Cached values of folder sizes, etc. optional DiskStatsCachedValuesProto cached_folder_sizes = 6; // Average write speed of storaged benchmark for last 24 hours optional int32 benchmarked_write_speed_kbps = 7; } message DiskStatsCachedValuesProto { Loading
services/core/java/com/android/server/DiskStatsService.java +47 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ package com.android.server; import android.content.Context; import android.os.Binder; import android.os.Environment; import android.os.IBinder; import android.os.IStoraged; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StatFs; import android.os.SystemClock; import android.os.storage.StorageManager; Loading Loading @@ -109,6 +113,12 @@ public class DiskStatsService extends Binder { } } if (protoFormat) { reportDiskWriteSpeedProto(proto); } else { reportDiskWriteSpeed(pw); } reportFreeSpace(Environment.getDataDirectory(), "Data", pw, proto, DiskStatsFreeSpaceProto.FOLDER_DATA); reportFreeSpace(Environment.getDownloadCacheDirectory(), "Cache", pw, proto, Loading Loading @@ -285,4 +295,41 @@ public class DiskStatsService extends Binder { Log.w(TAG, "exception reading diskstats cache file", e); } } private int getRecentPerf() throws RemoteException, IllegalStateException { IBinder binder = ServiceManager.getService("storaged"); if (binder == null) throw new IllegalStateException("storaged not found"); IStoraged storaged = IStoraged.Stub.asInterface(binder); return storaged.getRecentPerf(); } // Keep reportDiskWriteSpeed and reportDiskWriteSpeedProto in sync private void reportDiskWriteSpeed(PrintWriter pw) { try { long perf = getRecentPerf(); if (perf != 0) { pw.print("Recent Disk Write Speed (kB/s) = "); pw.println(perf); } else { pw.println("Recent Disk Write Speed data unavailable"); Log.w(TAG, "Recent Disk Write Speed data unavailable!"); } } catch (RemoteException | IllegalStateException e) { pw.println(e.toString()); Log.e(TAG, e.toString()); } } private void reportDiskWriteSpeedProto(ProtoOutputStream proto) { try { long perf = getRecentPerf(); if (perf != 0) { proto.write(DiskStatsServiceDumpProto.BENCHMARKED_WRITE_SPEED_KBPS, perf); } else { Log.w(TAG, "Recent Disk Write Speed data unavailable!"); } } catch (RemoteException | IllegalStateException e) { Log.e(TAG, e.toString()); } } }