• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

修订版254b0d5a7f8474a95281151a668a5486101b9bb5 (tree)
时间2019-12-18 23:39:16
作者Gavin Corkery <gavincorkery@goog...>
CommiterGavin Corkery

Log Message

Log watchdog-initiated rollback reason

To help with monitoring Mainline releases, log the reason
for a watchdog-initiated rollback. This may be due to
native crashes, app crashes, ANRs or explicit health check
failures.

Add a mapping from PackageWatchdog failure reason to the
new metrics.

Bug: 146415463
Test: atest PackageWatchdogTest
Test: atest StatsdHostTestCases
Change-Id: Ia3e73d955508297004591eac762555665c557b8a
Merged-In: Ia3e73d955508297004591eac762555665c557b8a
(cherry picked from commit dd1dabaef7dfae54b20f225ee407f182e86411ac)

更改概述

差异

--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -1385,7 +1385,10 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra
13851385
13861386 Status StatsService::sendWatchdogRollbackOccurredAtom(const int32_t rollbackTypeIn,
13871387 const android::String16& packageNameIn,
1388- const int64_t packageVersionCodeIn) {
1388+ const int64_t packageVersionCodeIn,
1389+ const int32_t rollbackReasonIn,
1390+ const android::String16&
1391+ failingPackageNameIn) {
13891392 // Note: We skip the usage stats op check here since we do not have a package name.
13901393 // This is ok since we are overloading the usage_stats permission.
13911394 // This method only sends data, it does not receive it.
@@ -1407,7 +1410,8 @@ Status StatsService::sendWatchdogRollbackOccurredAtom(const int32_t rollbackType
14071410 }
14081411
14091412 android::util::stats_write(android::util::WATCHDOG_ROLLBACK_OCCURRED,
1410- rollbackTypeIn, String8(packageNameIn).string(), packageVersionCodeIn);
1413+ rollbackTypeIn, String8(packageNameIn).string(), packageVersionCodeIn,
1414+ rollbackReasonIn, String8(failingPackageNameIn).string());
14111415
14121416 // Fast return to save disk read.
14131417 if (rollbackTypeIn != android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS
--- a/cmds/statsd/src/StatsService.h
+++ b/cmds/statsd/src/StatsService.h
@@ -200,7 +200,9 @@ public:
200200 virtual Status sendWatchdogRollbackOccurredAtom(
201201 const int32_t rollbackTypeIn,
202202 const android::String16& packageNameIn,
203- const int64_t packageVersionCodeIn) override;
203+ const int64_t packageVersionCodeIn,
204+ const int32_t rollbackReasonIn,
205+ const android::String16& failingPackageNameIn) override;
204206
205207 /**
206208 * Binder call to get registered experiment IDs.
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -1687,6 +1687,19 @@ message WatchdogRollbackOccurred {
16871687 optional string package_name = 2;
16881688
16891689 optional int32 package_version_code = 3;
1690+
1691+ enum RollbackReasonType {
1692+ REASON_UNKNOWN = 0;
1693+ REASON_NATIVE_CRASH = 1;
1694+ REASON_EXPLICIT_HEALTH_CHECK = 2;
1695+ REASON_APP_CRASH = 3;
1696+ REASON_APP_NOT_RESPONDING = 4;
1697+ }
1698+ optional RollbackReasonType rollback_reason = 4;
1699+
1700+ // Set by RollbackPackageHealthObserver to be the package that is failing when a rollback
1701+ // is initiated. Empty if the package is unknown.
1702+ optional string failing_package_name = 5;
16901703 }
16911704
16921705 /**
--- a/core/java/android/os/IStatsManager.aidl
+++ b/core/java/android/os/IStatsManager.aidl
@@ -224,7 +224,7 @@ interface IStatsManager {
224224 * Logs an event for watchdog rollbacks.
225225 */
226226 oneway void sendWatchdogRollbackOccurredAtom(in int rollbackType, in String packageName,
227- in long packageVersionCode);
227+ in long packageVersionCode, in int rollbackReason, in String failingPackageName);
228228
229229 /**
230230 * Returns the most recently registered experiment IDs.
--- a/core/java/android/util/StatsLog.java
+++ b/core/java/android/util/StatsLog.java
@@ -179,6 +179,8 @@ public final class StatsLog extends StatsLogInternal {
179179 * @param rollbackType state of the rollback.
180180 * @param packageName package name being rolled back.
181181 * @param packageVersionCode version of the package being rolled back.
182+ * @param rollbackReason reason the package is being rolled back.
183+ * @param failingPackageName the package name causing the failure.
182184 *
183185 * @return True if the log request was sent to statsd.
184186 *
@@ -186,7 +188,7 @@ public final class StatsLog extends StatsLogInternal {
186188 */
187189 @RequiresPermission(allOf = {DUMP, PACKAGE_USAGE_STATS})
188190 public static boolean logWatchdogRollbackOccurred(int rollbackType, String packageName,
189- long packageVersionCode) {
191+ long packageVersionCode, int rollbackReason, String failingPackageName) {
190192 synchronized (sLogLock) {
191193 try {
192194 IStatsManager service = getIStatsManagerLocked();
@@ -198,7 +200,7 @@ public final class StatsLog extends StatsLogInternal {
198200 }
199201
200202 service.sendWatchdogRollbackOccurredAtom(rollbackType, packageName,
201- packageVersionCode);
203+ packageVersionCode, rollbackReason, failingPackageName);
202204 return true;
203205 } catch (RemoteException e) {
204206 sService = null;
--- a/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java
+++ b/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java
@@ -16,6 +16,13 @@
1616
1717 package com.android.server.rollback;
1818
19+import static android.util.StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_APP_CRASH;
20+import static android.util.StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_APP_NOT_RESPONDING;
21+import static android.util.StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_EXPLICIT_HEALTH_CHECK;
22+import static android.util.StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_NATIVE_CRASH;
23+import static android.util.StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN;
24+
25+import android.annotation.NonNull;
1926 import android.annotation.Nullable;
2027 import android.content.BroadcastReceiver;
2128 import android.content.Context;
@@ -111,6 +118,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
111118 RollbackManager rollbackManager = mContext.getSystemService(RollbackManager.class);
112119 VersionedPackage moduleMetadataPackage = getModuleMetadataPackage();
113120 RollbackInfo rollback = getAvailableRollback(rollbackManager, failedPackage);
121+ int reasonToLog = mapFailureReasonToMetric(rollbackReason);
114122
115123 if (rollback == null) {
116124 Slog.w(TAG, "Expected rollback but no valid rollback found for package: [ "
@@ -120,7 +128,8 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
120128 }
121129
122130 logEvent(moduleMetadataPackage,
123- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE);
131+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE,
132+ reasonToLog, failedPackage.getPackageName());
124133 LocalIntentReceiver rollbackReceiver = new LocalIntentReceiver((Intent result) -> {
125134 int status = result.getIntExtra(RollbackManager.EXTRA_STATUS,
126135 RollbackManager.STATUS_FAILURE);
@@ -137,11 +146,13 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
137146 moduleMetadataPackage);
138147 } else {
139148 logEvent(moduleMetadataPackage,
140- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS);
149+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS,
150+ reasonToLog, failedPackage.getPackageName());
141151 }
142152 } else {
143153 logEvent(moduleMetadataPackage,
144- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE);
154+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE,
155+ reasonToLog, failedPackage.getPackageName());
145156 }
146157 });
147158
@@ -220,12 +231,14 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
220231 }
221232 if (sessionInfo.isStagedSessionApplied()) {
222233 logEvent(oldModuleMetadataPackage,
223- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS);
234+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS,
235+ WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN, "");
224236 } else if (sessionInfo.isStagedSessionReady()) {
225237 // TODO: What do for staged session ready but not applied
226238 } else {
227239 logEvent(oldModuleMetadataPackage,
228- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE);
240+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE,
241+ WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN, "");
229242 }
230243 }
231244
@@ -304,12 +317,16 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
304317 saveLastStagedRollbackId(rollbackId);
305318 logEvent(moduleMetadataPackage,
306319 StatsLog
307- .WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_BOOT_TRIGGERED);
320+ .WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_BOOT_TRIGGERED,
321+ WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN,
322+ "");
308323 mContext.getSystemService(PowerManager.class).reboot("Rollback staged install");
309324 } else if (sessionInfo.isStagedSessionFailed()
310325 && markStagedSessionHandled(rollbackId)) {
311326 logEvent(moduleMetadataPackage,
312- StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE);
327+ StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE,
328+ WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN,
329+ "");
313330 mContext.unregisterReceiver(listener);
314331 }
315332 }
@@ -356,11 +373,12 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
356373 return rollbackId;
357374 }
358375
359- private static void logEvent(@Nullable VersionedPackage moduleMetadataPackage, int type) {
376+ private static void logEvent(@Nullable VersionedPackage moduleMetadataPackage, int type,
377+ int rollbackReason, @NonNull String failingPackageName) {
360378 Slog.i(TAG, "Watchdog event occurred of type: " + type);
361379 if (moduleMetadataPackage != null) {
362380 StatsLog.logWatchdogRollbackOccurred(type, moduleMetadataPackage.getPackageName(),
363- moduleMetadataPackage.getVersionCode());
381+ moduleMetadataPackage.getVersionCode(), rollbackReason, failingPackageName);
364382 }
365383 }
366384
@@ -393,4 +411,20 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve
393411 + "and mitigate native crashes");
394412 mHandler.post(()->checkAndMitigateNativeCrashes());
395413 }
414+
415+ private int mapFailureReasonToMetric(@FailureReasons int failureReason) {
416+ switch (failureReason) {
417+ case PackageWatchdog.FAILURE_REASON_NATIVE_CRASH:
418+ return WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_NATIVE_CRASH;
419+ case PackageWatchdog.FAILURE_REASON_EXPLICIT_HEALTH_CHECK:
420+ return WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_EXPLICIT_HEALTH_CHECK;
421+ case PackageWatchdog.FAILURE_REASON_APP_CRASH:
422+ return WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_APP_CRASH;
423+ case PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING:
424+ return WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_APP_NOT_RESPONDING;
425+ default:
426+ return WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_REASON__REASON_UNKNOWN;
427+ }
428+ }
429+
396430 }