Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
shark-android/src/main/java/shark/AndroidMetadataExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package shark | ||
|
||
object AndroidMetadataExtractor : MetadataExtractor { | ||
override fun extractMetadata(graph: HeapGraph): Map<String, String> { | ||
val build = AndroidBuildMirror.fromHeapGraph(graph) | ||
|
||
val buildConfigClass = graph.findClassByName("com.squareup.leakcanary.core.BuildConfig") | ||
val leakCanaryVersion = | ||
buildConfigClass?.get("LIBRARY_VERSION")?.value?.readAsJavaString() ?: "Unknown" | ||
|
||
val loadedApk = graph.findClassByName("android.app.LoadedApk") | ||
?.instances?.firstOrNull() | ||
|
||
val appPackageName = | ||
loadedApk?.get("android.app.LoadedApk", "mPackageName")?.value?.readAsJavaString() | ||
?: "Unknown" | ||
return mapOf( | ||
"Build.VERSION.SDK_INT" to build.sdkInt.toString(), | ||
"Build.MANUFACTURER" to build.manufacturer, | ||
"LeakCanary version" to leakCanaryVersion, | ||
"App package name" to appPackageName | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package shark | ||
|
||
import shark.MetadataExtractor.Companion.invoke | ||
import shark.ObjectInspector.Companion.invoke | ||
|
||
/** | ||
* Extracts metadata from a hprof to be reported in [HeapAnalysisSuccess.metadata]. | ||
* | ||
* You can create a [MetadataExtractor] from a lambda by calling [invoke]. | ||
*/ | ||
interface MetadataExtractor { | ||
fun extractMetadata(graph: HeapGraph): Map<String, String> | ||
|
||
companion object { | ||
|
||
/** | ||
* A no-op [MetadataExtractor] | ||
*/ | ||
val NO_OP = MetadataExtractor { emptyMap() } | ||
|
||
/** | ||
* Utility function to create a [MetadataExtractor] from the passed in [block] lambda instead of | ||
* using the anonymous `object : MetadataExtractor` syntax. | ||
* | ||
* Usage: | ||
* | ||
* ```kotlin | ||
* val inspector = MetadataExtractor { graph -> | ||
* | ||
* } | ||
* ``` | ||
*/ | ||
inline operator fun invoke(crossinline block: (HeapGraph) -> Map<String, String>): MetadataExtractor = | ||
object : MetadataExtractor { | ||
override fun extractMetadata(graph: HeapGraph): Map<String, String> = block(graph) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters