Merge "Add recent disk write speed metrics to Disk Stats"

This commit is contained in:
TreeHugger Robot
2018-01-18 02:50:48 +00:00
committed by Android (Google) Code Review
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());
}
}
}