Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to me.saket.bytesize #2711

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ androidX-test-uiautomator = { module = "androidx.test.uiautomator:uiautomator",
androidX-work-runtime = { module = "androidx.work:work-runtime", version.ref = "workManager" }
androidX-work-multiprocess = { module = "androidx.work:work-multiprocess", version.ref = "workManager" }
androidX-collections = { module = "androidx.collection:collection-ktx", version = "1.4.0" }
bytesize = { module = "me.saket.bytesize:bytesize", version = "2.0.0-beta04" }

androidSupport = { module = "com.android.support:support-v4", version = "28.0.0" }
assertjCore = { module = "org.assertj:assertj-core", version = "3.9.1" }
Expand Down
1 change: 1 addition & 0 deletions shark/shark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ java {

dependencies {
api(projects.shark.sharkGraph)
api(libs.bytesize)

implementation(libs.coroutines.core)
implementation(libs.kotlin.stdlib)
Expand Down
60 changes: 0 additions & 60 deletions shark/shark/src/main/java/shark/ByteSize.kt

This file was deleted.

9 changes: 5 additions & 4 deletions shark/shark/src/main/java/shark/ObjectGrowthDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.collection.MutableLongSet
import androidx.collection.mutableLongListOf
import java.util.ArrayDeque
import java.util.Deque
import me.saket.bytesize.decimalBytes
import shark.HeapObject.HeapClass
import shark.HeapObject.HeapInstance
import shark.HeapObject.HeapObjectArray
Expand Down Expand Up @@ -231,7 +232,7 @@ class ObjectGrowthDetector(
// A map that stores two ints, size and count, in a single long value with bit packing.
val retainedSizeAndCountMap = MutableLongLongMap(dequeuedNodes.size)
for (node in dequeuedNodes.asReversed()) {
var nodeRetainedSize = ZERO_BYTES
var nodeRetainedSize = 0.decimalBytes
var nodeRetainedCount = 0

for (objectId in node.objectIds) {
Expand All @@ -248,7 +249,7 @@ class ObjectGrowthDetector(
if (dominatorObjectId != ValueHolder.NULL_REFERENCE) {
retainedSizeAndCountMap.increase(dominatorObjectId, retainedSize, retainedCount)
}
nodeRetainedSize += retainedSize.bytes
nodeRetainedSize += retainedSize.decimalBytes
nodeRetainedCount += retainedCount
}

Expand Down Expand Up @@ -353,13 +354,13 @@ class ObjectGrowthDetector(
return@reportedGrowingNodeRetainedSize
}

var heapSize = ZERO_BYTES
var heapSize = 0.decimalBytes
var objectCount = 0
for (objectId in node.objectIds) {
val packed = retainedMap[objectId]
val additionalByteSize = packed.unpackAsFirstInt
val additionalObjectCount = packed.unpackAsSecondInt
heapSize += additionalByteSize.bytes
heapSize += additionalByteSize.decimalBytes
objectCount += additionalObjectCount
}
shortestPathNode.retained = Retained(
Expand Down
8 changes: 5 additions & 3 deletions shark/shark/src/main/java/shark/Retained.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package shark

import me.saket.bytesize.ByteSize
import me.saket.bytesize.decimalBytes
import shark.internal.packedWith
import shark.internal.unpackAsFirstInt
import shark.internal.unpackAsSecondInt
Expand Down Expand Up @@ -29,7 +31,7 @@ value class Retained @PublishedApi internal constructor(
internal val packedValue: Long
) {
inline val heapSize: ByteSize
get() = packedValue.unpackAsFirstInt.bytes
get() = packedValue.unpackAsFirstInt.decimalBytes

inline val objectCount: Int
get() = packedValue.unpackAsSecondInt
Expand All @@ -41,5 +43,5 @@ value class Retained @PublishedApi internal constructor(
get() = this == ZERO_RETAINED
}

val ZERO_RETAINED = Retained(ZERO_BYTES, 0)
val UNKNOWN_RETAINED = Retained((-1).bytes, -1)
val ZERO_RETAINED = Retained(0.decimalBytes, 0)
val UNKNOWN_RETAINED = Retained((-1).decimalBytes, -1)
5 changes: 3 additions & 2 deletions shark/shark/src/test/java/shark/ObjectGrowthDetectorTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package shark

import me.saket.bytesize.decimalBytes
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import shark.HprofHeapGraph.Companion.openHeapGraph
Expand Down Expand Up @@ -103,7 +104,7 @@ class ObjectGrowthDetectorTest {

val growingObject = heapTraversal.growingObjects.single()
assertThat(growingObject.retainedIncrease.objectCount).isEqualTo(1)
val expectedRetainedSizeIncrease = (12 + "World!".length * 2).bytes
val expectedRetainedSizeIncrease = (12 + "World!".length * 2).decimalBytes
assertThat(growingObject.retainedIncrease.heapSize).isEqualTo(expectedRetainedSizeIncrease)
}

Expand All @@ -126,7 +127,7 @@ class ObjectGrowthDetectorTest {

val growingObject = heapTraversal.growingObjects.single()
assertThat(growingObject.retainedIncrease.objectCount).isEqualTo(1)
val expectedRetainedSizeIncrease = (12 + "Turtles".length * 2).bytes
val expectedRetainedSizeIncrease = (12 + "Turtles".length * 2).decimalBytes
assertThat(growingObject.retainedIncrease.heapSize).isEqualTo(expectedRetainedSizeIncrease)
}

Expand Down
Loading