Skip to content

Commit 28695e0

Browse files
author
Dianne Hackborn
committed
More performance work:
- ActivityManager now keeps track of previous app as you move across the home app. - Better debug info about why an activity is being destroyed. - New performance tests. Change-Id: I3a5ae7cb1b9f1624c6792a4f6184353f532b8f3b
1 parent 11b49ba commit 28695e0

File tree

9 files changed

+600
-32
lines changed

9 files changed

+600
-32
lines changed

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static class PendingActivityLaunch {
293293
/**
294294
* Historical data of past broadcasts, for debugging.
295295
*/
296-
static final int MAX_BROADCAST_HISTORY = 100;
296+
static final int MAX_BROADCAST_HISTORY = 25;
297297
final BroadcastRecord[] mBroadcastHistory
298298
= new BroadcastRecord[MAX_BROADCAST_HISTORY];
299299

@@ -13898,7 +13898,7 @@ final void updateOomAdjLocked() {
1389813898
if (curLevel >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE) {
1389913899
// For these apps we will also finish their activities
1390013900
// to help them free memory.
13901-
mMainStack.destroyActivitiesLocked(app, false);
13901+
mMainStack.destroyActivitiesLocked(app, false, "trim");
1390213902
}
1390313903
}
1390413904
app.trimMemoryLevel = curLevel;
@@ -13962,7 +13962,7 @@ final void updateOomAdjLocked() {
1396213962
}
1396313963

1396413964
if (mAlwaysFinishActivities) {
13965-
mMainStack.destroyActivitiesLocked(null, false);
13965+
mMainStack.destroyActivitiesLocked(null, false, "always-finish");
1396613966
}
1396713967
}
1396813968

services/java/com/android/server/am/ActivityStack.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbna
947947
r.state = ActivityState.STOPPED;
948948
if (!r.finishing) {
949949
if (r.configDestroy) {
950-
destroyActivityLocked(r, true, false);
950+
destroyActivityLocked(r, true, false, "stop-config");
951951
resumeTopActivityLocked(null);
952952
}
953953
}
@@ -976,7 +976,7 @@ private final void completePauseLocked() {
976976
// instance right now, we need to first completely stop
977977
// the current instance before starting the new one.
978978
if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev);
979-
destroyActivityLocked(prev, true, false);
979+
destroyActivityLocked(prev, true, false, "pause-config");
980980
} else {
981981
mStoppingActivities.add(prev);
982982
if (mStoppingActivities.size() > 3) {
@@ -1364,7 +1364,8 @@ final boolean resumeTopActivityLocked(ActivityRecord prev) {
13641364
}
13651365
}
13661366

1367-
if (!prev.finishing && prev.app != null && prev.app != next.app) {
1367+
if (!prev.finishing && prev.app != null && prev.app != next.app
1368+
&& prev.app != mService.mHomeProcess) {
13681369
// We are switching to a new activity that is in a different
13691370
// process than the previous one. Note the previous process,
13701371
// so we can try to keep it around.
@@ -3113,7 +3114,7 @@ private final void stopActivityLocked(ActivityRecord r) {
31133114
if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r);
31143115
r.state = ActivityState.STOPPED;
31153116
if (r.configDestroy) {
3116-
destroyActivityLocked(r, true, false);
3117+
destroyActivityLocked(r, true, false, "stop-except");
31173118
}
31183119
}
31193120
}
@@ -3288,7 +3289,7 @@ final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
32883289
for (i=0; i<NF; i++) {
32893290
ActivityRecord r = (ActivityRecord)finishes.get(i);
32903291
synchronized (mService) {
3291-
destroyActivityLocked(r, true, false);
3292+
destroyActivityLocked(r, true, false, "finish-idle");
32923293
}
32933294
}
32943295

@@ -3487,7 +3488,7 @@ private final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,
34873488
|| prevState == ActivityState.INITIALIZING) {
34883489
// If this activity is already stopped, we can just finish
34893490
// it right now.
3490-
return destroyActivityLocked(r, true, true) ? null : r;
3491+
return destroyActivityLocked(r, true, true, "finish-imm") ? null : r;
34913492
} else {
34923493
// Need to go through the full pause cycle to get this
34933494
// activity into the stopped state and then finish it.
@@ -3593,7 +3594,7 @@ final void cleanUpActivityServicesLocked(ActivityRecord r) {
35933594
}
35943595
}
35953596

3596-
final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj) {
3597+
final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
35973598
for (int i=mHistory.size()-1; i>=0; i--) {
35983599
ActivityRecord r = mHistory.get(i);
35993600
if (owner != null && r.app != owner) {
@@ -3604,7 +3605,7 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj) {
36043605
if (r.app != null && r.haveState && !r.visible && r.stopped && !r.finishing
36053606
&& r.state != ActivityState.DESTROYING
36063607
&& r.state != ActivityState.DESTROYED) {
3607-
destroyActivityLocked(r, true, oomAdj);
3608+
destroyActivityLocked(r, true, oomAdj, "trim");
36083609
}
36093610
}
36103611
}
@@ -3616,13 +3617,13 @@ final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj) {
36163617
* but then create a new client-side object for this same HistoryRecord.
36173618
*/
36183619
final boolean destroyActivityLocked(ActivityRecord r,
3619-
boolean removeFromApp, boolean oomAdj) {
3620+
boolean removeFromApp, boolean oomAdj, String reason) {
36203621
if (DEBUG_SWITCH) Slog.v(
36213622
TAG, "Removing activity: token=" + r
36223623
+ ", app=" + (r.app != null ? r.app.processName : "(null)"));
36233624
EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY,
36243625
System.identityHashCode(r),
3625-
r.task.taskId, r.shortComponentName);
3626+
r.task.taskId, r.shortComponentName, reason);
36263627

36273628
boolean removedFromHistory = false;
36283629

@@ -4109,7 +4110,7 @@ final boolean ensureActivityConfigurationLocked(ActivityRecord r,
41094110
if (r.app == null || r.app.thread == null) {
41104111
if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
41114112
"Switch is destroying non-running " + r);
4112-
destroyActivityLocked(r, true, false);
4113+
destroyActivityLocked(r, true, false, "config");
41134114
} else if (r.state == ActivityState.PAUSING) {
41144115
// A little annoying: we are waiting for this activity to
41154116
// finish pausing. Let's not do anything now, but just

services/java/com/android/server/am/EventLogTags.logtags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ option java_package com.android.server.am
4848
# Reporting to applications that memory is low
4949
30017 am_low_memory (Num Processes|1|1)
5050
# An activity is being destroyed:
51-
30018 am_destroy_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
51+
30018 am_destroy_activity (Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)
5252
# An activity has been relaunched, resumed, and is now in the foreground:
5353
30019 am_relaunch_resume_activity (Token|1|5),(Task ID|1|5),(Component Name|3)
5454
# An activity has been relaunched:
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2011 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:layout_width="match_parent"
18+
android:layout_height="match_parent" >
19+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
20+
android:text="FooBarYou" />
21+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
22+
android:text="FooBarYou" />
23+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
24+
android:text="FooBarYou" />
25+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
26+
android:text="FooBarYou" />
27+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
28+
android:text="FooBarYou" />
29+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
30+
android:text="FooBarYou" />
31+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
32+
android:text="FooBarYou" />
33+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
34+
android:text="FooBarYou" />
35+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
36+
android:text="FooBarYou" />
37+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
38+
android:text="FooBarYou" />
39+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
40+
android:text="FooBarYou" />
41+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
42+
android:text="FooBarYou" />
43+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
44+
android:text="FooBarYou" />
45+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
46+
android:text="FooBarYou" />
47+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
48+
android:text="FooBarYou" />
49+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
50+
android:text="FooBarYou" />
51+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
52+
android:text="FooBarYou" />
53+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
54+
android:text="FooBarYou" />
55+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
56+
android:text="FooBarYou" />
57+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
58+
android:text="FooBarYou" />
59+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
60+
android:text="FooBarYou" />
61+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
62+
android:text="FooBarYou" />
63+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
64+
android:text="FooBarYou" />
65+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
66+
android:text="FooBarYou" />
67+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
68+
android:text="FooBarYou" />
69+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
70+
android:text="FooBarYou" />
71+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
72+
android:text="FooBarYou" />
73+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
74+
android:text="FooBarYou" />
75+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
76+
android:text="FooBarYou" />
77+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
78+
android:text="FooBarYou" />
79+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
80+
android:text="FooBarYou" />
81+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
82+
android:text="FooBarYou" />
83+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
84+
android:text="FooBarYou" />
85+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
86+
android:text="FooBarYou" />
87+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
88+
android:text="FooBarYou" />
89+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
90+
android:text="FooBarYou" />
91+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
92+
android:text="FooBarYou" />
93+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
94+
android:text="FooBarYou" />
95+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
96+
android:text="FooBarYou" />
97+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
98+
android:text="FooBarYou" />
99+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
100+
android:text="FooBarYou" />
101+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
102+
android:text="FooBarYou" />
103+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
104+
android:text="FooBarYou" />
105+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
106+
android:text="FooBarYou" />
107+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
108+
android:text="FooBarYou" />
109+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
110+
android:text="FooBarYou" />
111+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
112+
android:text="FooBarYou" />
113+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
114+
android:text="FooBarYou" />
115+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
116+
android:text="FooBarYou" />
117+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
118+
android:text="FooBarYou" />
119+
</LinearLayout>

0 commit comments

Comments
 (0)