Add recent disk write speed metrics to Disk Stats

Report disk write speed via dumpsys diskstats. Write speed provided by
storaged, which benchmarks current write speed every hour.

Fixes: 62393328
Test: manual (After at least an hour of use:
              adb shell dumpsys diskstats --proto > temp.pb
              printproto --proto2 --raw_protocol_buffer \
	      --message=android.service.diskstats.DiskStatsServiceDumpProto \
	      --multiline \
	      --proto=frameworks/base/core/proto/android/service/diskstats.proto \
	      ./temp.pb | grep benchmarked_write_speed_kbps)
Change-Id: Ic86406d6ce43d3962719af10f45288130c13b1a2
This commit is contained in:
Michael Wachenschwanz
2017-12-14 18:32:14 -08:00
parent a629e4c393
commit 3e20a105b2
2 changed files with 49 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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;
@@ -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,
@@ -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());
}
}
}