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

Parsing and applying proguard mapping during heap analysis #1542

Merged
merged 8 commits into from Aug 30, 2019

Conversation

mzgreen
Copy link
Contributor

@mzgreen mzgreen commented Aug 22, 2019

I created a proguard mapping parser and hooked it into the heap analysis process.
Please review it and I'm happy to fix any issues you find.

Note that this is not ready to merge yet - I need to figure out the best way to expose an API for providing proguard mapping files.

Resolves #1499

@CLAassistant
Copy link

CLAassistant commented Aug 22, 2019

CLA assistant check
All committers have signed the CLA.

@mzgreen mzgreen changed the title #1499 Parsing and applying proguard mapping during heap analysis Parsing and applying proguard mapping during heap analysis Aug 22, 2019
Copy link
Member

@pyricau pyricau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Would you mind adding one test to LeakTraceRendererTest (and use obfuscated names like "a.b.c" for the obfuscated names ? These are more end to end and would show how the final rendering looks readable despite obfuscated classes.

shark-graph/src/main/java/shark/ProguardMapping.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/ProguardMapping.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/ProguardMapping.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/ProguardMapping.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/HprofHeapGraph.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/HprofHeapGraph.kt Outdated Show resolved Hide resolved
Michal Zielinski and others added 5 commits August 26, 2019 11:31
…mapping

# Conflicts:
#	shark-graph/src/main/java/shark/HeapObject.kt
#	shark-graph/src/main/java/shark/HprofHeapGraph.kt
#	shark-graph/src/main/java/shark/ProguardMapping.kt
#	shark-graph/src/main/java/shark/internal/HprofInMemoryIndex.kt
#	shark-graph/src/test/java/shark/ProguardMappingTest.kt
Copy link
Member

@pyricau pyricau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I left a few notes, there seem to be formatting issues. Other than that, the main thing is that I think the heap analyzer should get the mapping rather than the reader itself. That way we can have the mapping from somewhere else.

@@ -44,12 +71,14 @@ fun printHelp() {

analyze-process: Dumps the heap for the provided process name, pulls the hprof file and analyzes it.
USAGE: analyze-process PROCESS_PACKAGE_NAME
(optional) -proguard_mapping PROGUARD_MAPPING_FILE_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about the distinct casing (dash for "analyze-process" vs underscore for "proguard_mapping"), is there a standard practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't know, I just wanted it to look different than the "main options" because it's more like adding an additional parameter. But I started reading and it seems that it's pretty interesting topic!
This is an awesome response with links to good resources: https://softwareengineering.stackexchange.com/questions/307467/what-are-good-habits-for-designing-command-line-arguments

Maybe we should use something like: http://commons.apache.org/proper/commons-cli/ or http://jcommander.org/?

I think it should be done as a separate change, and for this one I'll change the name to match the dash convention you started. Will that be ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of checking out Clikt: #1467

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that seems cool too and it's in Kotlin :)

shark-cli/src/main/java/shark/Main.kt Outdated Show resolved Hide resolved
shark-cli/src/main/java/shark/Main.kt Show resolved Hide resolved
shark-graph/src/main/java/shark/HprofHeapGraph.kt Outdated Show resolved Hide resolved
shark-graph/src/main/java/shark/HprofHeapGraph.kt Outdated Show resolved Hide resolved
shark/src/test/java/shark/LeakTraceRendererTest.kt Outdated Show resolved Hide resolved
val listener = OnAnalysisProgressListener { step ->
SharkLog.d { step.name }
}

val proguardMappingReader = proguardMappingFile?.let { ProguardMappingReader(it.inputStream()) }
Copy link
Member

@pyricau pyricau Aug 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I should have been more clear: I think we should push ProguardMappingReader to the outmost layer. I can't think of a good reason for HeapAnalyzer to know about where the mapping comes from. The general idea is to enable doing this even when we don't have a file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for misunderstanding, I moved the reader our of the analyzer :)

@@ -25,7 +52,7 @@ fun printHelp() {

// ASCII art is a remix of a shark from -David "TAZ" Baltazar- and chick from jgs.
SharkLog.d {
"""
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more spacing issues :)

@@ -96,7 +125,7 @@ private fun dumpHeap(packageName: String): File {
val heapDumpDevicePath = "/data/local/tmp/$heapDumpFileName"

SharkLog.d {
"Dumping heap for process \"$processName\" with pid $processId to $heapDumpDevicePath"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

@@ -81,7 +110,7 @@ private fun dumpHeap(packageName: String): File {
matchingExactly
} else {
SharkLog.d {
"More than one process matches \"$packageName\" but none matches exactly: ${matchingProcesses.map { it.first }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

@pyricau pyricau merged commit 66182a5 into square:master Aug 30, 2019
@pyricau pyricau added this to the 2.0 Next Release milestone Aug 30, 2019
@mzgreen mzgreen deleted the proguard_mapping branch September 2, 2019 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Proguard mapping files
3 participants