diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index afcd51572d517..8dd0f428648e0 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -704,7 +704,7 @@ public final class ActivityThread extends ClientTransactionHandler { streamingOutput); profiling = true; } catch (RuntimeException e) { - Slog.w(TAG, "Profiling failed on path " + profileFile); + Slog.w(TAG, "Profiling failed on path " + profileFile, e); try { profileFd.close(); profileFd = null; diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 96633da165089..0d74df4a7931a 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -25378,6 +25378,14 @@ public class ActivityManagerService extends IActivityManager.Stub } catch (IOException e) { } mProfilerInfo.profileFd = null; + + if (proc.pid == MY_PID) { + // When profiling the system server itself, avoid closing the file + // descriptor, as profilerControl will not create a copy. + // Note: it is also not correct to just set profileFd to null, as the + // whole ProfilerInfo instance is passed down! + profilerInfo = null; + } } else { stopProfilerLocked(proc, profileType); if (profilerInfo != null && profilerInfo.profileFd != null) {