summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorSongchun Fan <schfan@google.com>2021-03-03 21:01:37 +0000
committerSongchun Fan <schfan@google.com>2021-03-10 23:20:35 +0000
commitb54bb636745a6cced54c98faf41cceb858a15076 (patch)
tree4e63b3025a492427a44b804e2c932fbae2378518 /core/java/android
parent167dea12182d2d0f8ea5022e171df3df4f0ee3ea (diff)
[incremental] expose duration metrics to activity manager
Change existing metrics proto to include: 1) whether the crashed/ANR'd app is incremental 2) the loading progress of the crashed/ANR'd app 3) the duration in milliseconds since the oldest pending read Example logcat: 03-08 11:21:31.405 1668 5779 E ActivityManager: App crashed on incremental package mytown.police which is 81% loaded. Example crash metrics: metric_id: 1111 event_metrics { data { elapsed_timestamp_nanos: 1141413709431 atom { app_crash_occurred { uid: 10348 event_type: "crash" process_name: "mytown.police" pid: 21236 package_name: "mytown.police" is_instant_app: FALSE foreground_state: FOREGROUND error_source: DATA_APP >>> is_incremental: true >>> loading_progress: 0.81358474 >>> millis_since_oldest_pending_read: 20092 } } } } BUG: 180951530 Test: atest CtsStatsdAtomHostTestCases:android.cts.statsdatom.statsd.UidAtomTests#testANROccurred Test: manual with disabled rest streaming Change-Id: I931acfed37304fa35f756286b424512490b0e312
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/incremental/IncrementalManager.java12
-rw-r--r--core/java/android/os/incremental/IncrementalMetrics.java39
-rw-r--r--core/java/android/os/incremental/IncrementalStorage.java14
3 files changed, 65 insertions, 0 deletions
diff --git a/core/java/android/os/incremental/IncrementalManager.java b/core/java/android/os/incremental/IncrementalManager.java
index dc6f63a94685..ccb4a615f44a 100644
--- a/core/java/android/os/incremental/IncrementalManager.java
+++ b/core/java/android/os/incremental/IncrementalManager.java
@@ -421,6 +421,18 @@ public final class IncrementalManager {
storage.unregisterStorageHealthListener();
}
+ /**
+ * Returns the metrics of an Incremental Storage.
+ */
+ public IncrementalMetrics getMetrics(@NonNull String codePath) {
+ final IncrementalStorage storage = openStorage(codePath);
+ if (storage == null) {
+ // storage does not exist, package not installed
+ return null;
+ }
+ return new IncrementalMetrics(storage.getMetrics());
+ }
+
/* Native methods */
private static native boolean nativeIsEnabled();
private static native boolean nativeIsV2Available();
diff --git a/core/java/android/os/incremental/IncrementalMetrics.java b/core/java/android/os/incremental/IncrementalMetrics.java
new file mode 100644
index 000000000000..44dea1be50f0
--- /dev/null
+++ b/core/java/android/os/incremental/IncrementalMetrics.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2021 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.os.incremental;
+
+import android.annotation.NonNull;
+import android.os.PersistableBundle;
+
+/**
+ * Provides methods to access metrics about an app installed via Incremental
+ * @hide
+ */
+public class IncrementalMetrics {
+ @NonNull private final PersistableBundle mData;
+
+ public IncrementalMetrics(@NonNull PersistableBundle data) {
+ mData = data;
+ }
+
+ /**
+ * @return Milliseconds between now and when the oldest pending read happened
+ */
+ public long getMillisSinceOldestPendingRead() {
+ return mData.getLong(IIncrementalService.METRICS_MILLIS_SINCE_OLDEST_PENDING_READ, -1);
+ }
+}
diff --git a/core/java/android/os/incremental/IncrementalStorage.java b/core/java/android/os/incremental/IncrementalStorage.java
index e6ce8cd56d28..7cf0144d71f7 100644
--- a/core/java/android/os/incremental/IncrementalStorage.java
+++ b/core/java/android/os/incremental/IncrementalStorage.java
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.DataLoaderParams;
import android.content.pm.IDataLoaderStatusListener;
+import android.os.PersistableBundle;
import android.os.RemoteException;
import java.io.File;
@@ -601,4 +602,17 @@ public final class IncrementalStorage {
return;
}
}
+
+ /**
+ * Returns the metrics of the current storage.
+ * {@see IIncrementalService} for metrics keys.
+ */
+ public PersistableBundle getMetrics() {
+ try {
+ return mService.getMetrics(mId);
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ return null;
+ }
+ }
}