New Pipeline: Add Trace calls to measure performance.
Fixes: 204695099 Test: generate a perfetto trace Change-Id: Ia534fd07a8702e4d3a5606a0a470f72c46e5b90f
This commit is contained in:
@@ -48,6 +48,7 @@ import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.Notification;
|
||||
import android.os.RemoteException;
|
||||
import android.os.Trace;
|
||||
import android.os.UserHandle;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.NotificationListenerService.Ranking;
|
||||
@@ -512,6 +513,7 @@ public class NotifCollection implements Dumpable {
|
||||
}
|
||||
|
||||
private void dispatchEventsAndRebuildList() {
|
||||
Trace.beginSection("NotifCollection.dispatchEventsAndRebuildList");
|
||||
mAmDispatchingToOtherCode = true;
|
||||
while (!mEventQueue.isEmpty()) {
|
||||
mEventQueue.remove().dispatchTo(mNotifCollectionListeners);
|
||||
@@ -521,6 +523,7 @@ public class NotifCollection implements Dumpable {
|
||||
if (mBuildListener != null) {
|
||||
mBuildListener.onBuildList(mReadOnlyNotificationSet);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void onEndLifetimeExtension(
|
||||
|
||||
@@ -30,6 +30,7 @@ import static com.android.systemui.statusbar.notification.collection.listbuilder
|
||||
|
||||
import android.annotation.MainThread;
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Trace;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -316,6 +317,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
* if we detect that behavior, we should crash instantly.
|
||||
*/
|
||||
private void buildList() {
|
||||
Trace.beginSection("ShadeListBuilder.buildList");
|
||||
mPipelineState.requireIsBefore(STATE_BUILD_STARTED);
|
||||
mPipelineState.setState(STATE_BUILD_STARTED);
|
||||
|
||||
@@ -369,9 +371,11 @@ public class ShadeListBuilder implements Dumpable {
|
||||
|
||||
// Step 8: Dispatch the new list, first to any listeners and then to the view layer
|
||||
dispatchOnBeforeRenderList(mReadOnlyNotifList);
|
||||
Trace.beginSection("ShadeListBuilder.onRenderList");
|
||||
if (mOnRenderListListener != null) {
|
||||
mOnRenderListListener.onRenderList(mReadOnlyNotifList);
|
||||
}
|
||||
Trace.endSection();
|
||||
|
||||
// Step 9: We're done!
|
||||
mLogger.logEndBuildList(
|
||||
@@ -383,9 +387,11 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
mPipelineState.setState(STATE_IDLE);
|
||||
mIterationCount++;
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void notifySectionEntriesUpdated() {
|
||||
Trace.beginSection("ShadeListBuilder.notifySectionEntriesUpdated");
|
||||
NotifSection currentSection = null;
|
||||
mTempSectionMembers.clear();
|
||||
for (int i = 0; i < mNotifList.size(); i++) {
|
||||
@@ -399,6 +405,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
mTempSectionMembers.add(currentEntry);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,6 +447,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
Collection<? extends ListEntry> entries,
|
||||
List<ListEntry> out,
|
||||
List<NotifFilter> filters) {
|
||||
Trace.beginSection("ShadeListBuilder.filterNotifs");
|
||||
final long now = mSystemClock.uptimeMillis();
|
||||
for (ListEntry entry : entries) {
|
||||
if (entry instanceof GroupEntry) {
|
||||
@@ -471,9 +479,11 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void groupNotifs(List<ListEntry> entries, List<ListEntry> out) {
|
||||
Trace.beginSection("ShadeListBuilder.groupNotifs");
|
||||
for (ListEntry listEntry : entries) {
|
||||
// since grouping hasn't happened yet, all notifs are NotificationEntries
|
||||
NotificationEntry entry = (NotificationEntry) listEntry;
|
||||
@@ -529,12 +539,14 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void stabilizeGroupingNotifs(List<ListEntry> topLevelList) {
|
||||
if (mNotifStabilityManager == null) {
|
||||
return;
|
||||
}
|
||||
Trace.beginSection("ShadeListBuilder.stabilizeGroupingNotifs");
|
||||
|
||||
for (int i = 0; i < topLevelList.size(); i++) {
|
||||
final ListEntry tle = topLevelList.get(i);
|
||||
@@ -560,6 +572,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -592,6 +605,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
|
||||
private void promoteNotifs(List<ListEntry> list) {
|
||||
Trace.beginSection("ShadeListBuilder.promoteNotifs");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
final ListEntry tle = list.get(i);
|
||||
|
||||
@@ -610,9 +624,11 @@ public class ShadeListBuilder implements Dumpable {
|
||||
});
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void pruneIncompleteGroups(List<ListEntry> shadeList) {
|
||||
Trace.beginSection("ShadeListBuilder.pruneIncompleteGroups");
|
||||
for (int i = 0; i < shadeList.size(); i++) {
|
||||
final ListEntry tle = shadeList.get(i);
|
||||
|
||||
@@ -667,6 +683,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -733,6 +750,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
|
||||
private void sortListAndNotifySections() {
|
||||
Trace.beginSection("ShadeListBuilder.sortListAndNotifySections");
|
||||
// Assign sections to top-level elements and sort their children
|
||||
for (ListEntry entry : mNotifList) {
|
||||
NotifSection section = applySections(entry);
|
||||
@@ -750,6 +768,7 @@ public class ShadeListBuilder implements Dumpable {
|
||||
|
||||
// notify sections since the list is sorted now
|
||||
notifySectionEntriesUpdated();
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void freeEmptyGroups() {
|
||||
@@ -1000,27 +1019,35 @@ public class ShadeListBuilder implements Dumpable {
|
||||
}
|
||||
|
||||
private void dispatchOnBeforeTransformGroups(List<ListEntry> entries) {
|
||||
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeTransformGroups");
|
||||
for (int i = 0; i < mOnBeforeTransformGroupsListeners.size(); i++) {
|
||||
mOnBeforeTransformGroupsListeners.get(i).onBeforeTransformGroups(entries);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void dispatchOnBeforeSort(List<ListEntry> entries) {
|
||||
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeSort");
|
||||
for (int i = 0; i < mOnBeforeSortListeners.size(); i++) {
|
||||
mOnBeforeSortListeners.get(i).onBeforeSort(entries);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void dispatchOnBeforeFinalizeFilter(List<ListEntry> entries) {
|
||||
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeFinalizeFilter");
|
||||
for (int i = 0; i < mOnBeforeFinalizeFilterListeners.size(); i++) {
|
||||
mOnBeforeFinalizeFilterListeners.get(i).onBeforeFinalizeFilter(entries);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void dispatchOnBeforeRenderList(List<ListEntry> entries) {
|
||||
Trace.beginSection("ShadeListBuilder.dispatchOnBeforeRenderList");
|
||||
for (int i = 0; i < mOnBeforeRenderListListeners.size(); i++) {
|
||||
mOnBeforeRenderListListeners.get(i).onBeforeRenderList(entries);
|
||||
}
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.statusbar.notification.collection.listbuilder.pluggable;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Trace;
|
||||
|
||||
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
|
||||
|
||||
@@ -50,7 +51,9 @@ public abstract class Pluggable<This> {
|
||||
*/
|
||||
public final void invalidateList() {
|
||||
if (mListener != null) {
|
||||
Trace.beginSection("Pluggable<" + mName + ">.invalidateList");
|
||||
mListener.onPluggableInvalidated((This) this);
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.NotificationEntry
|
||||
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
|
||||
@@ -36,7 +37,7 @@ class NodeSpecBuilder(
|
||||
fun buildNodeSpec(
|
||||
rootController: NodeController,
|
||||
notifList: List<ListEntry>
|
||||
): NodeSpec {
|
||||
): NodeSpec = traceSection("NodeSpecBuilder.buildNodeSpec") {
|
||||
val root = NodeSpecImpl(null, rootController)
|
||||
var currentSection: NotifSection? = null
|
||||
val prevSections = mutableSetOf<NotifSection?>()
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.collection.render
|
||||
import android.annotation.MainThread
|
||||
import android.view.View
|
||||
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
|
||||
@@ -47,7 +48,7 @@ class ShadeViewDiffer(
|
||||
* provided [spec]. The root node of the spec must match the root controller passed to the
|
||||
* differ's constructor.
|
||||
*/
|
||||
fun applySpec(spec: NodeSpec) {
|
||||
fun applySpec(spec: NodeSpec) = traceSection("ShadeViewDiffer.applySpec") {
|
||||
val specMap = treeToMap(spec)
|
||||
|
||||
if (spec.controller != rootNode.controller) {
|
||||
|
||||
@@ -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.stack.NotificationListContainer
|
||||
import com.android.systemui.statusbar.phone.NotificationIconAreaController
|
||||
import com.android.systemui.util.traceSection
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -47,16 +48,20 @@ class ShadeViewManager constructor(
|
||||
listBuilder.setOnRenderListListener(::onNewNotifTree)
|
||||
|
||||
private fun onNewNotifTree(notifList: List<ListEntry>) {
|
||||
viewDiffer.applySpec(specBuilder.buildNodeSpec(rootController, notifList))
|
||||
updateGroupCounts(notifList)
|
||||
notificationIconAreaController.updateNotificationIcons(notifList)
|
||||
traceSection("ShadeViewManager.onNewNotifTree") {
|
||||
viewDiffer.applySpec(specBuilder.buildNodeSpec(rootController, notifList))
|
||||
updateGroupCounts(notifList)
|
||||
notificationIconAreaController.updateNotificationIcons(notifList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGroupCounts(notifList: List<ListEntry>) {
|
||||
notifList.asSequence().filterIsInstance<GroupEntry>().forEach { groupEntry ->
|
||||
val controller = viewBarn.requireView(checkNotNull(groupEntry.summary))
|
||||
val row = controller.view as ExpandableNotificationRow
|
||||
row.setUntruncatedChildCount(groupEntry.untruncatedChildCount)
|
||||
traceSection("ShadeViewManager.updateGroupCounts") {
|
||||
notifList.asSequence().filterIsInstance<GroupEntry>().forEach { groupEntry ->
|
||||
val controller = viewBarn.requireView(checkNotNull(groupEntry.summary))
|
||||
val row = controller.view as ExpandableNotificationRow
|
||||
row.setUntruncatedChildCount(groupEntry.untruncatedChildCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Trace;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -336,12 +337,14 @@ public class NotificationIconAreaController implements
|
||||
}
|
||||
|
||||
private void updateNotificationIcons() {
|
||||
Trace.beginSection("NotificationIconAreaController.updateNotificationIcons");
|
||||
updateStatusBarIcons();
|
||||
updateShelfIcons();
|
||||
updateCenterIcon();
|
||||
updateAodNotificationIcons();
|
||||
|
||||
applyNotificationIconsTint();
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
private void updateShelfIcons() {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user