frameworks/base
Révision | 254b0d5a7f8474a95281151a668a5486101b9bb5 (tree) |
---|---|
l'heure | 2019-12-18 23:39:16 |
Auteur | Gavin Corkery <gavincorkery@goog...> |
Commiter | Gavin Corkery |
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)
@@ -1385,7 +1385,10 @@ Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& tra | ||
1385 | 1385 | |
1386 | 1386 | Status StatsService::sendWatchdogRollbackOccurredAtom(const int32_t rollbackTypeIn, |
1387 | 1387 | 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) { | |
1389 | 1392 | // Note: We skip the usage stats op check here since we do not have a package name. |
1390 | 1393 | // This is ok since we are overloading the usage_stats permission. |
1391 | 1394 | // This method only sends data, it does not receive it. |
@@ -1407,7 +1410,8 @@ Status StatsService::sendWatchdogRollbackOccurredAtom(const int32_t rollbackType | ||
1407 | 1410 | } |
1408 | 1411 | |
1409 | 1412 | 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()); | |
1411 | 1415 | |
1412 | 1416 | // Fast return to save disk read. |
1413 | 1417 | if (rollbackTypeIn != android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS |
@@ -200,7 +200,9 @@ public: | ||
200 | 200 | virtual Status sendWatchdogRollbackOccurredAtom( |
201 | 201 | const int32_t rollbackTypeIn, |
202 | 202 | 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; | |
204 | 206 | |
205 | 207 | /** |
206 | 208 | * Binder call to get registered experiment IDs. |
@@ -1687,6 +1687,19 @@ message WatchdogRollbackOccurred { | ||
1687 | 1687 | optional string package_name = 2; |
1688 | 1688 | |
1689 | 1689 | 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; | |
1690 | 1703 | } |
1691 | 1704 | |
1692 | 1705 | /** |
@@ -224,7 +224,7 @@ interface IStatsManager { | ||
224 | 224 | * Logs an event for watchdog rollbacks. |
225 | 225 | */ |
226 | 226 | oneway void sendWatchdogRollbackOccurredAtom(in int rollbackType, in String packageName, |
227 | - in long packageVersionCode); | |
227 | + in long packageVersionCode, in int rollbackReason, in String failingPackageName); | |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * Returns the most recently registered experiment IDs. |
@@ -179,6 +179,8 @@ public final class StatsLog extends StatsLogInternal { | ||
179 | 179 | * @param rollbackType state of the rollback. |
180 | 180 | * @param packageName package name being rolled back. |
181 | 181 | * @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. | |
182 | 184 | * |
183 | 185 | * @return True if the log request was sent to statsd. |
184 | 186 | * |
@@ -186,7 +188,7 @@ public final class StatsLog extends StatsLogInternal { | ||
186 | 188 | */ |
187 | 189 | @RequiresPermission(allOf = {DUMP, PACKAGE_USAGE_STATS}) |
188 | 190 | public static boolean logWatchdogRollbackOccurred(int rollbackType, String packageName, |
189 | - long packageVersionCode) { | |
191 | + long packageVersionCode, int rollbackReason, String failingPackageName) { | |
190 | 192 | synchronized (sLogLock) { |
191 | 193 | try { |
192 | 194 | IStatsManager service = getIStatsManagerLocked(); |
@@ -198,7 +200,7 @@ public final class StatsLog extends StatsLogInternal { | ||
198 | 200 | } |
199 | 201 | |
200 | 202 | service.sendWatchdogRollbackOccurredAtom(rollbackType, packageName, |
201 | - packageVersionCode); | |
203 | + packageVersionCode, rollbackReason, failingPackageName); | |
202 | 204 | return true; |
203 | 205 | } catch (RemoteException e) { |
204 | 206 | sService = null; |
@@ -16,6 +16,13 @@ | ||
16 | 16 | |
17 | 17 | package com.android.server.rollback; |
18 | 18 | |
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; | |
19 | 26 | import android.annotation.Nullable; |
20 | 27 | import android.content.BroadcastReceiver; |
21 | 28 | import android.content.Context; |
@@ -111,6 +118,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
111 | 118 | RollbackManager rollbackManager = mContext.getSystemService(RollbackManager.class); |
112 | 119 | VersionedPackage moduleMetadataPackage = getModuleMetadataPackage(); |
113 | 120 | RollbackInfo rollback = getAvailableRollback(rollbackManager, failedPackage); |
121 | + int reasonToLog = mapFailureReasonToMetric(rollbackReason); | |
114 | 122 | |
115 | 123 | if (rollback == null) { |
116 | 124 | Slog.w(TAG, "Expected rollback but no valid rollback found for package: [ " |
@@ -120,7 +128,8 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
120 | 128 | } |
121 | 129 | |
122 | 130 | logEvent(moduleMetadataPackage, |
123 | - StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE); | |
131 | + StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE, | |
132 | + reasonToLog, failedPackage.getPackageName()); | |
124 | 133 | LocalIntentReceiver rollbackReceiver = new LocalIntentReceiver((Intent result) -> { |
125 | 134 | int status = result.getIntExtra(RollbackManager.EXTRA_STATUS, |
126 | 135 | RollbackManager.STATUS_FAILURE); |
@@ -137,11 +146,13 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
137 | 146 | moduleMetadataPackage); |
138 | 147 | } else { |
139 | 148 | logEvent(moduleMetadataPackage, |
140 | - StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS); | |
149 | + StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS, | |
150 | + reasonToLog, failedPackage.getPackageName()); | |
141 | 151 | } |
142 | 152 | } else { |
143 | 153 | logEvent(moduleMetadataPackage, |
144 | - StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE); | |
154 | + StatsLog.WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_FAILURE, | |
155 | + reasonToLog, failedPackage.getPackageName()); | |
145 | 156 | } |
146 | 157 | }); |
147 | 158 |
@@ -220,12 +231,14 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
220 | 231 | } |
221 | 232 | if (sessionInfo.isStagedSessionApplied()) { |
222 | 233 | 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, ""); | |
224 | 236 | } else if (sessionInfo.isStagedSessionReady()) { |
225 | 237 | // TODO: What do for staged session ready but not applied |
226 | 238 | } else { |
227 | 239 | 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, ""); | |
229 | 242 | } |
230 | 243 | } |
231 | 244 |
@@ -304,12 +317,16 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
304 | 317 | saveLastStagedRollbackId(rollbackId); |
305 | 318 | logEvent(moduleMetadataPackage, |
306 | 319 | 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 | + ""); | |
308 | 323 | mContext.getSystemService(PowerManager.class).reboot("Rollback staged install"); |
309 | 324 | } else if (sessionInfo.isStagedSessionFailed() |
310 | 325 | && markStagedSessionHandled(rollbackId)) { |
311 | 326 | 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 | + ""); | |
313 | 330 | mContext.unregisterReceiver(listener); |
314 | 331 | } |
315 | 332 | } |
@@ -356,11 +373,12 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
356 | 373 | return rollbackId; |
357 | 374 | } |
358 | 375 | |
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) { | |
360 | 378 | Slog.i(TAG, "Watchdog event occurred of type: " + type); |
361 | 379 | if (moduleMetadataPackage != null) { |
362 | 380 | StatsLog.logWatchdogRollbackOccurred(type, moduleMetadataPackage.getPackageName(), |
363 | - moduleMetadataPackage.getVersionCode()); | |
381 | + moduleMetadataPackage.getVersionCode(), rollbackReason, failingPackageName); | |
364 | 382 | } |
365 | 383 | } |
366 | 384 |
@@ -393,4 +411,20 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve | ||
393 | 411 | + "and mitigate native crashes"); |
394 | 412 | mHandler.post(()->checkAndMitigateNativeCrashes()); |
395 | 413 | } |
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 | + | |
396 | 430 | } |