From b436ce9cea86f8e4c0e2ad034ce9f4ef46d31cf8 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 19 Mar 2018 16:51:48 +0000 Subject: [PATCH] Close file descriptors of ProfilerInfo When using "am start --start-profiler" command, am doesn't close instances of related ParcelFileDescriptor of the profiler file path, but relies on garbage collection, so at the system level the file kept open for longer than it is needed. In a result, some processes that monitors the file close event using unix inotify_add_watch method would wait 20~30 Seconds. This change closes file descriptors after passing it to ActivityThread process, which is similar to what "am profile start" does. Bug: b/73891014 Test: tested manually by flashing into Pixel XL device. Merged-In: I5b63b96335fdaf86f0cd0caec2c53c32c0e41d72 Change-Id: I5b63b96335fdaf86f0cd0caec2c53c32c0e41d72 --- .../com/android/server/am/ActivityManagerService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 4d839d20c49ac..8731cdad69c58 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -7145,6 +7145,9 @@ public class ActivityManagerService extends IActivityManager.Stub if (profilerInfo != null && profilerInfo.profileFd != null) { profilerInfo.profileFd = profilerInfo.profileFd.dup(); + if (TextUtils.equals(mProfileApp, processName) && mProfilerInfo != null) { + clearProfilerLocked(); + } } // We deprecated Build.SERIAL and it is not accessible to @@ -7211,7 +7214,10 @@ public class ActivityManagerService extends IActivityManager.Stub mCoreSettingsObserver.getCoreSettingsLocked(), buildSerial); } - + if (profilerInfo != null) { + profilerInfo.closeFd(); + profilerInfo = null; + } checkTime(startTime, "attachApplicationLocked: immediately after bindApplication"); updateLruProcessLocked(app, false, null); checkTime(startTime, "attachApplicationLocked: after updateLruProcessLocked");