diff options
author | Jens Ole Lauridsen <jlauridsen@google.com> | 2022-01-26 15:26:01 -0800 |
---|---|---|
committer | Jens Ole Lauridsen <jlauridsen@google.com> | 2022-01-27 22:16:44 +0000 |
commit | 568c8e7208f0fcb58195d8a5bfa233eb5cb0ba0f (patch) | |
tree | 7f4b7cc58e91c1c7b8c07f2f7cc4d2dd8c895c7e /layout-inspector/src | |
parent | 91bfd62ef03fa6d29216a7140537eaee79157887 (diff) | |
download | idea-568c8e7208f0fcb58195d8a5bfa233eb5cb0ba0f.tar.gz |
Add recompositions in the properties panel
Also: add a column in the component tree for skips
Bug: 172894679
Test: Added unit tests
Change-Id: Ia2b84895cb78aaf99cb04acc8cc2a86393214f51
Diffstat (limited to 'layout-inspector/src')
9 files changed, 50 insertions, 11 deletions
diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/model/ComposeViewNode.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/model/ComposeViewNode.kt index 394716fd9cd..41743505ed7 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/model/ComposeViewNode.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/model/ComposeViewNode.kt @@ -67,6 +67,7 @@ class ComposeViewNode( textValue: String, layoutFlags: Int, var recomposeCount: Int, + var recomposeSkips: Int, var composeFilename: String, var composePackageHash: Int, var composeOffset: Int, @@ -90,6 +91,11 @@ class ComposeViewNode( override fun isSingleCall(treeSettings: TreeSettings): Boolean = treeSettings.composeAsCallstack && readAccess { (parent as? ComposeViewNode)?.children?.size == 1 && children.size == 1 } + fun resetRecomposeCounts() { + recomposeCount = 0 + recomposeSkips = 0 + } + @Suppress("NOTHING_TO_INLINE") inline fun Int.hasFlag(flag: Int) = flag and this == flag } diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/model/InspectorModel.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/model/InspectorModel.kt index 3373aa4957a..2aedfc52101 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/model/InspectorModel.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/model/InspectorModel.kt @@ -177,6 +177,10 @@ class InspectorModel(val project: Project) : ViewNodeAndResourceLookup { selectionListeners.forEach { it(old, new, origin) } } + fun updatePropertiesPanel() { + setSelection(selection, SelectionOrigin.INTERNAL) + } + fun updateConnection(client: InspectorClient) { connectionListeners.forEach { it(client) } } @@ -332,6 +336,7 @@ class InspectorModel(val project: Project) : ViewNodeAndResourceLookup { oldNode.composeLineNumber = newNode.composeLineNumber oldNode.composeFlags = newNode.composeFlags oldNode.recomposeCount = newNode.recomposeCount + oldNode.recomposeSkips = newNode.recomposeSkips } oldNode.children.clear() diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ComposeViewNodeCreator.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ComposeViewNodeCreator.kt index e5c6be814f4..5090fb265c2 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ComposeViewNodeCreator.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ComposeViewNodeCreator.kt @@ -101,6 +101,7 @@ class ComposeViewNodeCreator(response: GetComposablesResponse) { "", 0, recomposeCount, + recomposeSkips, stringTable[filename], packageHash, offset, diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ParameterItem.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ParameterItem.kt index d57a9076dea..9e10a1b28c3 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ParameterItem.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/pipeline/appinspection/compose/ParameterItem.kt @@ -36,6 +36,7 @@ fun parameterNamespaceOf(section: PropertySection) = when (section) { PropertySection.MERGED -> "merged" PropertySection.UNMERGED -> "unmerged" PropertySection.DIMENSION -> "internal" + PropertySection.RECOMPOSITIONS -> "internal" else -> "" } diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/InspectorPropertiesView.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/InspectorPropertiesView.kt index b88d85ccf7d..04253580cee 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/InspectorPropertiesView.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/InspectorPropertiesView.kt @@ -76,5 +76,12 @@ class InspectorPropertiesView(model: InspectorPropertiesModel) : PropertiesView< model, enumSupportProvider, controlTypeProvider, searchable = true)) tab.builders.add(InspectorTableBuilder("Declared Semantics", { it.section == PropertySection.UNMERGED }, model, enumSupportProvider, controlTypeProvider, searchable = true)) + tab.builders.add(InspectorTableBuilder("Recomposition", { it.section == PropertySection.RECOMPOSITIONS && showRecompositions(model) }, + model, enumSupportProvider, controlTypeProvider, searchable = true)) + } + + // When TreeSettings.showRecompositions is off, we will want to hide the Recomposition section: + private fun showRecompositions(model: InspectorPropertiesModel): Boolean { + return model.layoutInspector?.treeSettings?.showRecompositions ?: false } } diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertiesProvider.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertiesProvider.kt index 5358e327382..78eae1996b7 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertiesProvider.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertiesProvider.kt @@ -19,8 +19,10 @@ import com.android.SdkConstants.ATTR_HEIGHT import com.android.SdkConstants.ATTR_ID import com.android.SdkConstants.ATTR_NAME import com.android.SdkConstants.ATTR_WIDTH +import com.android.tools.idea.layoutinspector.model.ComposeViewNode import com.android.tools.idea.layoutinspector.model.ViewNode import com.android.tools.idea.layoutinspector.properties.PropertySection.DIMENSION +import com.android.tools.idea.layoutinspector.properties.PropertySection.RECOMPOSITIONS import com.android.tools.idea.layoutinspector.properties.PropertySection.VIEW import com.android.tools.property.panel.api.PropertiesTable import com.google.common.util.concurrent.Futures @@ -75,6 +77,17 @@ fun addInternalProperties( add(table, ATTR_WIDTH, Type.DIMENSION, view.width.toString(), DIMENSION, view.drawId, lookup) add(table, ATTR_HEIGHT, Type.DIMENSION, view.height.toString(), DIMENSION, view.drawId, lookup) attrId?.let { add(table, ATTR_ID, Type.STRING, it, VIEW, view.drawId, lookup) } + + (view as? ComposeViewNode)?.addComposeProperties(table, lookup) +} + +private fun ComposeViewNode.addComposeProperties(table: PropertiesTable<InspectorPropertyItem>, lookup: ViewNodeAndResourceLookup) { + if (recomposeCount > 0 || recomposeSkips > 0) { + // Do not show the "Recomposition" section in the properties panel for nodes without any counts. + // This includes inlined composables for which we are unable to get recomposition counts for. + add(table, "count", Type.INT32, recomposeCount.toString(), RECOMPOSITIONS, drawId, lookup) + add(table, "skips", Type.INT32, recomposeSkips.toString(), RECOMPOSITIONS, drawId, lookup) + } } private fun add(table: PropertiesTable<InspectorPropertyItem>, name: String, type: Type, value: String?, section: PropertySection, id: Long, diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertySection.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertySection.kt index 49165eb533d..83bf506e27e 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertySection.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/properties/PropertySection.kt @@ -19,12 +19,13 @@ package com.android.tools.idea.layoutinspector.properties * The attributes are grouped in sections in the properties panel. */ enum class PropertySection { - DEFAULT, // Use this value if an item is not in any of the groups mentioned below - DECLARED, // This attribute was specified by the user in a layout file in the application - LAYOUT, // This attribute is a layout attribute i.e. defined by the parent view - DIMENSION, // This attribute is intended for the Dimension section only - VIEW, // This attribute is intended for the SelectedView section only - PARAMETERS, // This attribute is a parameter of a composable - MERGED, // This attribute is a merged semantic attribute of a composable - UNMERGED, // This attribute is an unmerged semantic attribute from a semantic modifier of a composable + DEFAULT, // Use this value if an item is not in any of the groups mentioned below + DECLARED, // This attribute was specified by the user in a layout file in the application + LAYOUT, // This attribute is a layout attribute i.e. defined by the parent view + DIMENSION, // This attribute is intended for the Dimension section only + VIEW, // This attribute is intended for the SelectedView section only + PARAMETERS, // This attribute is a parameter of a composable + MERGED, // This attribute is a merged semantic attribute of a composable + UNMERGED, // This attribute is an unmerged semantic attribute from a semantic modifier of a composable + RECOMPOSITIONS, // This attribute holds recomposition and skip counts } diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt index 23284abe916..8178ab1c6c8 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/LayoutInspectorTreePanel.kt @@ -103,7 +103,8 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou .withToggleClickCount(3) .withContextMenu(::showPopup) .withoutTreeSearch() - .withColumn(createIntColumnInfo<TreeViewNode>("RecompositionCounts", { (it.view as? ComposeViewNode)?.recomposeCount })) + .withColumn(createIntColumnInfo<TreeViewNode>("Counts", { (it.view as? ComposeViewNode)?.recomposeCount })) + .withColumn(createIntColumnInfo<TreeViewNode>("Skips", { (it.view as? ComposeViewNode)?.recomposeSkips })) .withInvokeLaterOption { ApplicationManager.getApplication().invokeLater(it) } .withHorizontalScrollBar() .withComponentName("inspectorComponentTree") @@ -173,8 +174,10 @@ class LayoutInspectorTreePanel(parentDisposable: Disposable) : ToolContent<Layou GotoDeclarationAction.findNavigatable(model)?.navigate(true) } - fun showRecompositionColumn(show: Boolean) = + fun showRecompositionColumn(show: Boolean) { setColumnVisibility(1, show) + setColumnVisibility(2, show) + } // TODO: There probably can only be 1 layout inspector per project. Do we need to handle changes? override fun setToolContext(toolContext: LayoutInspector?) { diff --git a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt index b1a871e5a58..12765105c65 100644 --- a/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt +++ b/layout-inspector/src/com/android/tools/idea/layoutinspector/tree/TreeSettingsActions.kt @@ -137,7 +137,9 @@ object RecompositionCounts : ToggleAction("Show Recomposition Counts", null, nul inspector.treeSettings.showRecompositions = state client.updateRecompositionCountSettings() event.treePanel()?.showRecompositionColumn(state) - inspector.layoutInspectorModel.updateAll { (it as? ComposeViewNode)?.recomposeCount = 0 } + val model = inspector.layoutInspectorModel + model.updateAll { node -> (node as? ComposeViewNode)?.resetRecomposeCounts() } + model.updatePropertiesPanel() } override fun update(event: AnActionEvent) { |