@@ -12,15 +12,13 @@ import androidx.compose.material.MaterialTheme
12
12
import androidx.compose.material.Text
13
13
import androidx.compose.runtime.Composable
14
14
import androidx.compose.runtime.getValue
15
- import androidx.compose.runtime.key
16
15
import androidx.compose.runtime.mutableStateOf
17
16
import androidx.compose.runtime.remember
18
17
import androidx.compose.runtime.setValue
19
18
import androidx.compose.ui.Alignment
20
19
import androidx.compose.ui.Modifier
21
20
import androidx.compose.ui.graphics.Color
22
21
import androidx.compose.ui.unit.dp
23
- import shark.HeapObject.HeapClass
24
22
import shark.Showing.ShowTree
25
23
import shark.Showing.Start
26
24
@@ -40,17 +38,10 @@ sealed class Showing {
40
38
@Composable
41
39
fun HeapGraphWindow (loadingState : HeapDumpLoadingState , pressedKeys : PressedKeys ) {
42
40
MaterialTheme {
43
- val graph = loadingState.loadedGraph.value
44
- if (graph == null ) {
41
+ val loadedGraph = loadingState.loadedGraph.value
42
+ if (loadedGraph == null ) {
45
43
LoadingScreen (loadingState.file.name)
46
44
} else {
47
- // TODO move
48
- val classesWithInstanceCounts = mutableMapOf<Long , Int >()
49
- classesWithInstanceCounts.putAll(graph.classes.map { it.objectId to 0 })
50
- graph.instances.forEach { instance ->
51
- classesWithInstanceCounts[instance.instanceClassId] =
52
- classesWithInstanceCounts[instance.instanceClassId]!! + 1
53
- }
54
45
55
46
// TODO Backstack doesn't want to have duplicate entries (ie that are equal) but recents
56
47
// allow that to happen. Need to see what's what.
@@ -60,8 +51,7 @@ fun HeapGraphWindow(loadingState: HeapDumpLoadingState, pressedKeys: PressedKeys
60
51
61
52
Backstack (backstack) { screen ->
62
53
HeapGraphScreen (
63
- graph,
64
- classesWithInstanceCounts,
54
+ loadedGraph,
65
55
pressedKeys,
66
56
screen,
67
57
canGoBack = backstack.size > 1 ,
@@ -83,8 +73,7 @@ fun HeapGraphWindow(loadingState: HeapDumpLoadingState, pressedKeys: PressedKeys
83
73
84
74
@Composable
85
75
fun HeapGraphScreen (
86
- graph : HeapGraph ,
87
- classesWithInstanceCounts : Map <Long , Int >,
76
+ graph : LoadedGraph ,
88
77
pressedKeys : PressedKeys ,
89
78
showing : Showing ,
90
79
canGoBack : Boolean ,
@@ -101,19 +90,35 @@ fun HeapGraphScreen(
101
90
}
102
91
}
103
92
Text (text = " Home" )
104
- // TODO Don't use trailing lambda syntax
105
93
WrapTextBox (" Tree" , onClick = {
106
94
val showTree =
107
95
ShowTree (
108
96
" List of classes" ,
109
97
graph.classes.map {
110
- val instanceCount = classesWithInstanceCounts[it.objectId]!!
111
- it.toTreeItem(instanceCount)
98
+ it.toTreeItem(graph.instanceCount(it))
112
99
}
113
100
.toList()
114
101
)
115
102
goTo(showTree)
116
103
})
104
+ WrapTextBox (" Leaks" , onClick = {
105
+ goTo(ShowTree (
106
+ " Leaking objects" ,
107
+ graph.leakingObjectIds.map { graph.findObjectById(it).toTreeItem(graph) }.toList()
108
+ ))
109
+ })
110
+ WrapTextBox (" All objects" , onClick = {
111
+ goTo(ShowTree (
112
+ " All objects" ,
113
+ graph.objects.map { it.toTreeItem(graph) }.toList()
114
+ ))
115
+ })
116
+ WrapTextBox (" Dominators" , onClick = {
117
+ goTo(ShowTree (
118
+ " Dominators" ,
119
+ graph.dominatorsSortedRetained().filter { it != 0L }.map { graph.findObjectById(it).toTreeItem(graph) }
120
+ ))
121
+ })
117
122
Text (text = " Recents" )
118
123
for (item in recents.drop(1 )) {
119
124
TextBox (" $item " , onClick = {
@@ -140,7 +145,7 @@ fun HeapGraphScreen(
140
145
pressedKeys = pressedKeys,
141
146
rootItems = showing.initialItems,
142
147
expandItem = { heapItem ->
143
- heapItem.expand(graph, classesWithInstanceCounts )
148
+ heapItem.expand(graph)
144
149
},
145
150
onDoubleClick = { selectedItems ->
146
151
val showTree = ShowTree (
0 commit comments