Merge "New Pipeline: Add Trace calls to measure performance." into sc-v2-dev am: 8201c87afc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16162917

Change-Id: I7ffb273467b9033b37cf2f7db95cd87fabc882f5
This commit is contained in:
Jeff DeCew
2021-11-01 20:06:33 +00:00
committed by Automerger Merge Worker
8 changed files with 84 additions and 9 deletions

View File

@@ -48,6 +48,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt; import android.annotation.UserIdInt;
import android.app.Notification; import android.app.Notification;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationListenerService.Ranking;
@@ -512,6 +513,7 @@ public class NotifCollection implements Dumpable {
} }
private void dispatchEventsAndRebuildList() { private void dispatchEventsAndRebuildList() {
Trace.beginSection("NotifCollection.dispatchEventsAndRebuildList");
mAmDispatchingToOtherCode = true; mAmDispatchingToOtherCode = true;
while (!mEventQueue.isEmpty()) { while (!mEventQueue.isEmpty()) {
mEventQueue.remove().dispatchTo(mNotifCollectionListeners); mEventQueue.remove().dispatchTo(mNotifCollectionListeners);
@@ -521,6 +523,7 @@ public class NotifCollection implements Dumpable {
if (mBuildListener != null) { if (mBuildListener != null) {
mBuildListener.onBuildList(mReadOnlyNotificationSet); mBuildListener.onBuildList(mReadOnlyNotificationSet);
} }
Trace.endSection();
} }
private void onEndLifetimeExtension( private void onEndLifetimeExtension(

View File

@@ -30,6 +30,7 @@ import static com.android.systemui.statusbar.notification.collection.listbuilder
import android.annotation.MainThread; import android.annotation.MainThread;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.os.Trace;
import android.util.ArrayMap; import android.util.ArrayMap;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -332,6 +333,7 @@ public class ShadeListBuilder implements Dumpable {
* if we detect that behavior, we should crash instantly. * if we detect that behavior, we should crash instantly.
*/ */
private void buildList() { private void buildList() {
Trace.beginSection("ShadeListBuilder.buildList");
mPipelineState.requireIsBefore(STATE_BUILD_STARTED); mPipelineState.requireIsBefore(STATE_BUILD_STARTED);
mPipelineState.setState(STATE_BUILD_STARTED); mPipelineState.setState(STATE_BUILD_STARTED);
@@ -385,9 +387,11 @@ public class ShadeListBuilder implements Dumpable {
// Step 8: Dispatch the new list, first to any listeners and then to the view layer // Step 8: Dispatch the new list, first to any listeners and then to the view layer
dispatchOnBeforeRenderList(mReadOnlyNotifList); dispatchOnBeforeRenderList(mReadOnlyNotifList);
Trace.beginSection("ShadeListBuilder.onRenderList");
if (mOnRenderListListener != null) { if (mOnRenderListListener != null) {
mOnRenderListListener.onRenderList(mReadOnlyNotifList); mOnRenderListListener.onRenderList(mReadOnlyNotifList);
} }
Trace.endSection();
// Step 9: We're done! // Step 9: We're done!
mLogger.logEndBuildList( mLogger.logEndBuildList(
@@ -399,9 +403,11 @@ public class ShadeListBuilder implements Dumpable {
} }
mPipelineState.setState(STATE_IDLE); mPipelineState.setState(STATE_IDLE);
mIterationCount++; mIterationCount++;
Trace.endSection();
} }
private void notifySectionEntriesUpdated() { private void notifySectionEntriesUpdated() {
Trace.beginSection("ShadeListBuilder.notifySectionEntriesUpdated");
NotifSection currentSection = null; NotifSection currentSection = null;
mTempSectionMembers.clear(); mTempSectionMembers.clear();
for (int i = 0; i < mNotifList.size(); i++) { for (int i = 0; i < mNotifList.size(); i++) {
@@ -415,6 +421,7 @@ public class ShadeListBuilder implements Dumpable {
} }
mTempSectionMembers.add(currentEntry); mTempSectionMembers.add(currentEntry);
} }
Trace.endSection();
} }
/** /**
@@ -456,6 +463,7 @@ public class ShadeListBuilder implements Dumpable {
Collection<? extends ListEntry> entries, Collection<? extends ListEntry> entries,
List<ListEntry> out, List<ListEntry> out,
List<NotifFilter> filters) { List<NotifFilter> filters) {
Trace.beginSection("ShadeListBuilder.filterNotifs");
final long now = mSystemClock.uptimeMillis(); final long now = mSystemClock.uptimeMillis();
for (ListEntry entry : entries) { for (ListEntry entry : entries) {
if (entry instanceof GroupEntry) { if (entry instanceof GroupEntry) {
@@ -487,9 +495,11 @@ public class ShadeListBuilder implements Dumpable {
} }
} }
} }
Trace.endSection();
} }
private void groupNotifs(List<ListEntry> entries, List<ListEntry> out) { private void groupNotifs(List<ListEntry> entries, List<ListEntry> out) {
Trace.beginSection("ShadeListBuilder.groupNotifs");
for (ListEntry listEntry : entries) { for (ListEntry listEntry : entries) {
// since grouping hasn't happened yet, all notifs are NotificationEntries // since grouping hasn't happened yet, all notifs are NotificationEntries
NotificationEntry entry = (NotificationEntry) listEntry; NotificationEntry entry = (NotificationEntry) listEntry;
@@ -545,12 +555,14 @@ public class ShadeListBuilder implements Dumpable {
} }
} }
} }
Trace.endSection();
} }
private void stabilizeGroupingNotifs(List<ListEntry> topLevelList) { private void stabilizeGroupingNotifs(List<ListEntry> topLevelList) {
if (mNotifStabilityManager == null) { if (mNotifStabilityManager == null) {
return; return;
} }
Trace.beginSection("ShadeListBuilder.stabilizeGroupingNotifs");
for (int i = 0; i < topLevelList.size(); i++) { for (int i = 0; i < topLevelList.size(); i++) {
final ListEntry tle = topLevelList.get(i); final ListEntry tle = topLevelList.get(i);
@@ -576,6 +588,7 @@ public class ShadeListBuilder implements Dumpable {
} }
} }
} }
Trace.endSection();
} }
/** /**
@@ -608,6 +621,7 @@ public class ShadeListBuilder implements Dumpable {
} }
private void promoteNotifs(List<ListEntry> list) { private void promoteNotifs(List<ListEntry> list) {
Trace.beginSection("ShadeListBuilder.promoteNotifs");
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
final ListEntry tle = list.get(i); final ListEntry tle = list.get(i);
@@ -626,9 +640,11 @@ public class ShadeListBuilder implements Dumpable {
}); });
} }
} }
Trace.endSection();
} }
private void pruneIncompleteGroups(List<ListEntry> shadeList) { private void pruneIncompleteGroups(List<ListEntry> shadeList) {
Trace.beginSection("ShadeListBuilder.pruneIncompleteGroups");
for (int i = 0; i < shadeList.size(); i++) { for (int i = 0; i < shadeList.size(); i++) {
final ListEntry tle = shadeList.get(i); final ListEntry tle = shadeList.get(i);
@@ -683,6 +699,7 @@ public class ShadeListBuilder implements Dumpable {
} }
} }
} }
Trace.endSection();
} }
/** /**
@@ -749,6 +766,7 @@ public class ShadeListBuilder implements Dumpable {
} }
private void sortListAndNotifySections() { private void sortListAndNotifySections() {
Trace.beginSection("ShadeListBuilder.sortListAndNotifySections");
// Assign sections to top-level elements and sort their children // Assign sections to top-level elements and sort their children
for (ListEntry entry : mNotifList) { for (ListEntry entry : mNotifList) {
NotifSection section = applySections(entry); NotifSection section = applySections(entry);
@@ -766,6 +784,7 @@ public class ShadeListBuilder implements Dumpable {
// notify sections since the list is sorted now // notify sections since the list is sorted now
notifySectionEntriesUpdated(); notifySectionEntriesUpdated();
Trace.endSection();
} }
private void freeEmptyGroups() { private void freeEmptyGroups() {
@@ -1016,27 +1035,35 @@ public class ShadeListBuilder implements Dumpable {
} }
private void dispatchOnBeforeTransformGroups(List<ListEntry> entries) { private void dispatchOnBeforeTransformGroups(List<ListEntry> entries) {
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeTransformGroups");
for (int i = 0; i < mOnBeforeTransformGroupsListeners.size(); i++) { for (int i = 0; i < mOnBeforeTransformGroupsListeners.size(); i++) {
mOnBeforeTransformGroupsListeners.get(i).onBeforeTransformGroups(entries); mOnBeforeTransformGroupsListeners.get(i).onBeforeTransformGroups(entries);
} }
Trace.endSection();
} }
private void dispatchOnBeforeSort(List<ListEntry> entries) { private void dispatchOnBeforeSort(List<ListEntry> entries) {
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeSort");
for (int i = 0; i < mOnBeforeSortListeners.size(); i++) { for (int i = 0; i < mOnBeforeSortListeners.size(); i++) {
mOnBeforeSortListeners.get(i).onBeforeSort(entries); mOnBeforeSortListeners.get(i).onBeforeSort(entries);
} }
Trace.endSection();
} }
private void dispatchOnBeforeFinalizeFilter(List<ListEntry> entries) { private void dispatchOnBeforeFinalizeFilter(List<ListEntry> entries) {
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeFinalizeFilter");
for (int i = 0; i < mOnBeforeFinalizeFilterListeners.size(); i++) { for (int i = 0; i < mOnBeforeFinalizeFilterListeners.size(); i++) {
mOnBeforeFinalizeFilterListeners.get(i).onBeforeFinalizeFilter(entries); mOnBeforeFinalizeFilterListeners.get(i).onBeforeFinalizeFilter(entries);
} }
Trace.endSection();
} }
private void dispatchOnBeforeRenderList(List<ListEntry> entries) { private void dispatchOnBeforeRenderList(List<ListEntry> entries) {
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeRenderList");
for (int i = 0; i < mOnBeforeRenderListListeners.size(); i++) { for (int i = 0; i < mOnBeforeRenderListListeners.size(); i++) {
mOnBeforeRenderListListeners.get(i).onBeforeRenderList(entries); mOnBeforeRenderListListeners.get(i).onBeforeRenderList(entries);
} }
Trace.endSection();
} }
@Override @Override

View File

@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.collection.listbuilder.pluggable; package com.android.systemui.statusbar.notification.collection.listbuilder.pluggable;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.os.Trace;
import com.android.systemui.statusbar.notification.collection.NotifPipeline; import com.android.systemui.statusbar.notification.collection.NotifPipeline;
@@ -50,7 +51,9 @@ public abstract class Pluggable<This> {
*/ */
public final void invalidateList() { public final void invalidateList() {
if (mListener != null) { if (mListener != null) {
Trace.beginSection("Pluggable<" + mName + ">.invalidateList");
mListener.onPluggableInvalidated((This) this); mListener.onPluggableInvalidated((This) this);
Trace.endSection();
} }
} }

View File

@@ -20,6 +20,7 @@ import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.ListEntry import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection
import com.android.systemui.util.traceSection
/** /**
* Converts a notif list (the output of the ShadeListBuilder) into a NodeSpec, an abstract * Converts a notif list (the output of the ShadeListBuilder) into a NodeSpec, an abstract
@@ -36,7 +37,7 @@ class NodeSpecBuilder(
fun buildNodeSpec( fun buildNodeSpec(
rootController: NodeController, rootController: NodeController,
notifList: List<ListEntry> notifList: List<ListEntry>
): NodeSpec { ): NodeSpec = traceSection("NodeSpecBuilder.buildNodeSpec") {
val root = NodeSpecImpl(null, rootController) val root = NodeSpecImpl(null, rootController)
var currentSection: NotifSection? = null var currentSection: NotifSection? = null
val prevSections = mutableSetOf<NotifSection?>() val prevSections = mutableSetOf<NotifSection?>()

View File

@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.collection.render
import android.annotation.MainThread import android.annotation.MainThread
import android.view.View import android.view.View
import com.android.systemui.util.kotlin.transform import com.android.systemui.util.kotlin.transform
import com.android.systemui.util.traceSection
/** /**
* Given a "spec" that describes a "tree" of views, adds and removes views from the * Given a "spec" that describes a "tree" of views, adds and removes views from the
@@ -47,7 +48,7 @@ class ShadeViewDiffer(
* provided [spec]. The root node of the spec must match the root controller passed to the * provided [spec]. The root node of the spec must match the root controller passed to the
* differ's constructor. * differ's constructor.
*/ */
fun applySpec(spec: NodeSpec) { fun applySpec(spec: NodeSpec) = traceSection("ShadeViewDiffer.applySpec") {
val specMap = treeToMap(spec) val specMap = treeToMap(spec)
if (spec.controller != rootNode.controller) { if (spec.controller != rootNode.controller) {

View File

@@ -24,6 +24,7 @@ import com.android.systemui.statusbar.notification.collection.ShadeListBuilder
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.stack.NotificationListContainer import com.android.systemui.statusbar.notification.stack.NotificationListContainer
import com.android.systemui.statusbar.phone.NotificationIconAreaController import com.android.systemui.statusbar.phone.NotificationIconAreaController
import com.android.systemui.util.traceSection
import javax.inject.Inject import javax.inject.Inject
/** /**
@@ -47,18 +48,22 @@ class ShadeViewManager constructor(
listBuilder.setOnRenderListListener(::onNewNotifTree) listBuilder.setOnRenderListListener(::onNewNotifTree)
private fun onNewNotifTree(notifList: List<ListEntry>) { private fun onNewNotifTree(notifList: List<ListEntry>) {
traceSection("ShadeViewManager.onNewNotifTree") {
viewDiffer.applySpec(specBuilder.buildNodeSpec(rootController, notifList)) viewDiffer.applySpec(specBuilder.buildNodeSpec(rootController, notifList))
updateGroupCounts(notifList) updateGroupCounts(notifList)
notificationIconAreaController.updateNotificationIcons(notifList) notificationIconAreaController.updateNotificationIcons(notifList)
} }
}
private fun updateGroupCounts(notifList: List<ListEntry>) { private fun updateGroupCounts(notifList: List<ListEntry>) {
traceSection("ShadeViewManager.updateGroupCounts") {
notifList.asSequence().filterIsInstance<GroupEntry>().forEach { groupEntry -> notifList.asSequence().filterIsInstance<GroupEntry>().forEach { groupEntry ->
val controller = viewBarn.requireView(checkNotNull(groupEntry.summary)) val controller = viewBarn.requireView(checkNotNull(groupEntry.summary))
val row = controller.view as ExpandableNotificationRow val row = controller.view as ExpandableNotificationRow
row.setUntruncatedChildCount(groupEntry.untruncatedChildCount) row.setUntruncatedChildCount(groupEntry.untruncatedChildCount)
} }
} }
}
} }
class ShadeViewManagerFactory @Inject constructor( class ShadeViewManagerFactory @Inject constructor(

View File

@@ -6,6 +6,7 @@ import android.content.res.Resources;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.os.Trace;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@@ -336,12 +337,14 @@ public class NotificationIconAreaController implements
} }
private void updateNotificationIcons() { private void updateNotificationIcons() {
Trace.beginSection("NotificationIconAreaController.updateNotificationIcons");
updateStatusBarIcons(); updateStatusBarIcons();
updateShelfIcons(); updateShelfIcons();
updateCenterIcon(); updateCenterIcon();
updateAodNotificationIcons(); updateAodNotificationIcons();
applyNotificationIconsTint(); applyNotificationIconsTint();
Trace.endSection();
} }
private void updateShelfIcons() { private void updateShelfIcons() {

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.util
import android.os.Trace
/**
* Run a block within a [Trace] section.
* Calls [Trace.beginSection] before and [Trace.endSection] after the passed block.
*/
inline fun <T> traceSection(tag: String, block: () -> T): T {
Trace.beginSection(tag)
try {
return block()
} finally {
Trace.endSection()
}
}