aboutsummaryrefslogtreecommitdiff
path: root/car-lib/src/android/car/storagemonitoring
diff options
context:
space:
mode:
authorEnrico Granata <egranata@google.com>2017-10-27 14:57:34 -0700
committerEnrico Granata <egranata@google.com>2017-11-01 11:29:06 -0700
commita97fce2a0759cfb9fc2e7d88fd9c28c9ea50e42a (patch)
tree39f454cc9561ffdaeb723de9fcdb2d1e9ed5be52 /car-lib/src/android/car/storagemonitoring
parentae6b1b90044b58c2243445143e7778702f470055 (diff)
downloadCar-a97fce2a0759cfb9fc2e7d88fd9c28c9ea50e42a.tar.gz
Implement CarStorageMonitoringManager.getBootIoStats()
This API returns information about I/O activity that the system performed from kernel initalization until the BOOT_COMPLETE notification was broadcast. Bug: 65846699 Bug: 32512551 Test: runtest -x p/s/C/tests/carservice[_unit]_test/src/com/android/car/CarStorageMonitoringTest.java Change-Id: I2eaed1491dc6a5dda8e34edd41047c64dcc2f537
Diffstat (limited to 'car-lib/src/android/car/storagemonitoring')
-rw-r--r--car-lib/src/android/car/storagemonitoring/CarStorageMonitoringManager.java22
-rw-r--r--car-lib/src/android/car/storagemonitoring/ICarStorageMonitoring.aidl6
-rw-r--r--car-lib/src/android/car/storagemonitoring/UidIoStats.aidl (renamed from car-lib/src/android/car/storagemonitoring/UidIoStatEntry.aidl)2
-rw-r--r--car-lib/src/android/car/storagemonitoring/UidIoStats.java (renamed from car-lib/src/android/car/storagemonitoring/UidIoStatEntry.java)85
-rw-r--r--car-lib/src/android/car/storagemonitoring/UidIoStatsRecord.java67
5 files changed, 164 insertions, 18 deletions
diff --git a/car-lib/src/android/car/storagemonitoring/CarStorageMonitoringManager.java b/car-lib/src/android/car/storagemonitoring/CarStorageMonitoringManager.java
index 7192158a85..d61f71c98e 100644
--- a/car-lib/src/android/car/storagemonitoring/CarStorageMonitoringManager.java
+++ b/car-lib/src/android/car/storagemonitoring/CarStorageMonitoringManager.java
@@ -119,4 +119,26 @@ public final class CarStorageMonitoringManager implements CarManagerBase {
}
return Collections.emptyList();
}
+
+ /**
+ * This method returns a list of per user-id I/O activity metrics as collected at the end of
+ * system boot.
+ *
+ * The BOOT_COMPLETE broadcast is used as the trigger to collect this data. The implementation
+ * may impose an additional, and even variable across boot cycles, delay between the sending
+ * of the broadcast and the collection of the data.
+ *
+ * If the information is not available, an empty list will be returned.
+ */
+ @RequiresPermission(value=Car.PERMISSION_STORAGE_MONITORING)
+ public List<UidIoStats> getBootIoStats() throws CarNotConnectedException {
+ try {
+ return mService.getBootIoStats();
+ } catch (IllegalStateException e) {
+ checkCarNotConnectedExceptionFromCarService(e);
+ } catch (RemoteException e) {
+ throw new CarNotConnectedException();
+ }
+ return Collections.emptyList();
+ }
}
diff --git a/car-lib/src/android/car/storagemonitoring/ICarStorageMonitoring.aidl b/car-lib/src/android/car/storagemonitoring/ICarStorageMonitoring.aidl
index b22e96b7a5..19e65e304c 100644
--- a/car-lib/src/android/car/storagemonitoring/ICarStorageMonitoring.aidl
+++ b/car-lib/src/android/car/storagemonitoring/ICarStorageMonitoring.aidl
@@ -16,6 +16,7 @@
package android.car.storagemonitoring;
+import android.car.storagemonitoring.UidIoStats;
import android.car.storagemonitoring.WearEstimate;
import android.car.storagemonitoring.WearEstimateChange;
@@ -35,4 +36,9 @@ interface ICarStorageMonitoring {
* Returns the list of all observed wear estimate changes.
*/
List<WearEstimateChange> getWearEstimateHistory() = 3;
+
+ /**
+ * Returns I/O stats as collected at service boot time.
+ */
+ List<UidIoStats> getBootIoStats() = 4;
}
diff --git a/car-lib/src/android/car/storagemonitoring/UidIoStatEntry.aidl b/car-lib/src/android/car/storagemonitoring/UidIoStats.aidl
index a70630f225..2a9aee1dc2 100644
--- a/car-lib/src/android/car/storagemonitoring/UidIoStatEntry.aidl
+++ b/car-lib/src/android/car/storagemonitoring/UidIoStats.aidl
@@ -16,4 +16,4 @@
package android.car.storagemonitoring;
-parcelable UidIoStatEntry;
+parcelable UidIoStats;
diff --git a/car-lib/src/android/car/storagemonitoring/UidIoStatEntry.java b/car-lib/src/android/car/storagemonitoring/UidIoStats.java
index 1d1edc64af..3b8ae93379 100644
--- a/car-lib/src/android/car/storagemonitoring/UidIoStatEntry.java
+++ b/car-lib/src/android/car/storagemonitoring/UidIoStats.java
@@ -33,16 +33,16 @@ import org.json.JSONObject;
* @hide
*/
@SystemApi
-public final class UidIoStatEntry implements Parcelable {
+public final class UidIoStats implements Parcelable {
- public static final Parcelable.Creator<UidIoStatEntry> CREATOR =
- new Parcelable.Creator<UidIoStatEntry>() {
- public UidIoStatEntry createFromParcel(Parcel in) {
- return new UidIoStatEntry(in);
+ public static final Parcelable.Creator<UidIoStats> CREATOR =
+ new Parcelable.Creator<UidIoStats>() {
+ public UidIoStats createFromParcel(Parcel in) {
+ return new UidIoStats(in);
}
- public UidIoStatEntry[] newArray(int size) {
- return new UidIoStatEntry[size];
+ public UidIoStats[] newArray(int size) {
+ return new UidIoStats[size];
}
};
@@ -56,6 +56,14 @@ public final class UidIoStatEntry implements Parcelable {
public final int uid;
/**
+ * How long any process running on behalf of this user id running for, in milliseconds.
+ *
+ * This field is allowed to be an approximation and it does not provide any way to
+ * relate uptime to specific processes.
+ */
+ public final long runtimeMillis;
+
+ /**
* Statistics for apps running in foreground.
*/
public final PerStateMetrics foreground;
@@ -65,18 +73,36 @@ public final class UidIoStatEntry implements Parcelable {
*/
public final PerStateMetrics background;
- public UidIoStatEntry(int uid, PerStateMetrics foreground, PerStateMetrics background) {
+ public UidIoStats(int uid,
+ long runtimeMillis, PerStateMetrics foreground, PerStateMetrics background) {
this.uid = uid;
+ this.runtimeMillis = runtimeMillis;
this.foreground = Objects.requireNonNull(foreground);
this.background = Objects.requireNonNull(background);
}
- public UidIoStatEntry(Parcel in) {
+ public UidIoStats(Parcel in) {
uid = in.readInt();
+ runtimeMillis = in.readLong();
foreground = in.readParcelable(PerStateMetrics.class.getClassLoader());
background = in.readParcelable(PerStateMetrics.class.getClassLoader());
}
+ public UidIoStats(UidIoStatsRecord record, long runtimeMillis) {
+ uid = record.uid;
+ this.runtimeMillis = runtimeMillis;
+ foreground = new PerStateMetrics(record.foreground_rchar,
+ record.foreground_wchar,
+ record.foreground_read_bytes,
+ record.foreground_write_bytes,
+ record.foreground_fsync);
+ background = new PerStateMetrics(record.background_rchar,
+ record.background_wchar,
+ record.background_read_bytes,
+ record.background_write_bytes,
+ record.background_fsync);
+ }
+
@Override
public int describeContents() {
return 0;
@@ -85,6 +111,7 @@ public final class UidIoStatEntry implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(uid);
+ dest.writeLong(runtimeMillis);
dest.writeParcelable(foreground, flags);
dest.writeParcelable(background, flags);
}
@@ -92,13 +119,15 @@ public final class UidIoStatEntry implements Parcelable {
public void writeToJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.beginObject();
jsonWriter.name("uid").value(uid);
+ jsonWriter.name("runtimeMillis").value(runtimeMillis);
jsonWriter.name("foreground"); foreground.writeToJson(jsonWriter);
jsonWriter.name("background"); background.writeToJson(jsonWriter);
jsonWriter.endObject();
}
- public UidIoStatEntry(JSONObject in) throws JSONException {
+ public UidIoStats(JSONObject in) throws JSONException {
uid = in.getInt("uid");
+ runtimeMillis = in.getLong("runtimeMillis");
foreground = new PerStateMetrics(in.getJSONObject("foreground"));
background = new PerStateMetrics(in.getJSONObject("background"));
}
@@ -112,20 +141,22 @@ public final class UidIoStatEntry implements Parcelable {
*
* @hide
*/
- public UidIoStatEntry delta(UidIoStatEntry other) {
+ public UidIoStats delta(UidIoStats other) {
if (uid != other.uid) {
throw new IllegalArgumentException("cannot calculate delta between different user IDs");
}
- return new UidIoStatEntry(uid,
+ return new UidIoStats(uid,
+ runtimeMillis - other.runtimeMillis,
foreground.delta(other.foreground), background.delta(other.background));
}
@Override
public boolean equals(Object other) {
- if (other instanceof UidIoStatEntry) {
- UidIoStatEntry uidIoStatEntry = (UidIoStatEntry)other;
+ if (other instanceof UidIoStats) {
+ UidIoStats uidIoStatEntry = (UidIoStats)other;
return uid == uidIoStatEntry.uid &&
+ runtimeMillis == uidIoStatEntry.runtimeMillis &&
foreground.equals(uidIoStatEntry.foreground) &&
background.equals(uidIoStatEntry.background);
}
@@ -135,13 +166,33 @@ public final class UidIoStatEntry implements Parcelable {
@Override
public int hashCode() {
- return Objects.hash(uid, foreground, background);
+ return Objects.hash(uid, runtimeMillis, foreground, background);
}
@Override
public String toString() {
- return String.format("uid = %d, foreground = %s, background = %s",
- uid, foreground, background);
+ return String.format("uid = %d, runtime = %d, foreground = %s, background = %s",
+ uid, runtimeMillis, foreground, background);
+ }
+
+ /**
+ * Validates that this object contains the same I/O metrics as a UidIoStatsRecord.
+ *
+ * It matches UID, and I/O activity values, but ignores runtime.
+ * @hide
+ */
+ public boolean representsSameMetrics(UidIoStatsRecord record) {
+ return record.uid == uid &&
+ record.foreground_rchar == foreground.bytesRead &&
+ record.foreground_wchar == foreground.bytesWritten &&
+ record.foreground_read_bytes == foreground.bytesReadFromStorage &&
+ record.foreground_write_bytes == foreground.bytesWrittenToStorage &&
+ record.foreground_fsync == foreground.fsyncCalls &&
+ record.background_rchar == background.bytesRead &&
+ record.background_wchar == background.bytesWritten &&
+ record.background_read_bytes == background.bytesReadFromStorage &&
+ record.background_write_bytes == background.bytesWrittenToStorage &&
+ record.background_fsync == background.fsyncCalls;
}
/**
diff --git a/car-lib/src/android/car/storagemonitoring/UidIoStatsRecord.java b/car-lib/src/android/car/storagemonitoring/UidIoStatsRecord.java
new file mode 100644
index 0000000000..6eb1f417e5
--- /dev/null
+++ b/car-lib/src/android/car/storagemonitoring/UidIoStatsRecord.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.car.storagemonitoring;
+
+import android.annotation.SystemApi;
+
+/**
+ * Record of data as extracted from /proc/uid_io/stats
+ *
+ * @hide
+ */
+@SystemApi
+public final class UidIoStatsRecord {
+
+ public final int uid;
+
+ public final long foreground_rchar;
+ public final long foreground_wchar;
+ public final long foreground_read_bytes;
+ public final long foreground_write_bytes;
+ public final long foreground_fsync;
+
+ public final long background_rchar;
+ public final long background_wchar;
+ public final long background_read_bytes;
+ public final long background_write_bytes;
+ public final long background_fsync;
+
+ public UidIoStatsRecord(int uid,
+ long foreground_rchar,
+ long foreground_wchar,
+ long foreground_read_bytes,
+ long foreground_write_bytes,
+ long foreground_fsync,
+ long background_rchar,
+ long background_wchar,
+ long background_read_bytes,
+ long background_write_bytes,
+ long background_fsync) {
+ this.uid = uid;
+
+ this.foreground_rchar = foreground_rchar;
+ this.foreground_wchar = foreground_wchar;
+ this.foreground_read_bytes = foreground_read_bytes;
+ this.foreground_write_bytes = foreground_write_bytes;
+ this.foreground_fsync = foreground_fsync;
+
+ this.background_rchar = background_rchar;
+ this.background_wchar = background_wchar;
+ this.background_read_bytes = background_read_bytes;
+ this.background_write_bytes = background_write_bytes;
+ this.background_fsync = background_fsync;
+ }
+}