-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: hprof parser * fix: fix build: * fix: fix build break * feat: check dumpheap return value * feat: check only if app is debuggable * fix: fix merge issues * feat: only dump hprof with debugable build * fix: fix build * feat: shorten hprof file name * feat: remove appid in file name * feat: add final * feat: remove unused code
- Loading branch information
Showing
17 changed files
with
867 additions
and
4 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
19 changes: 19 additions & 0 deletions
19
common/src/main/java/com/microsoft/hydralab/performance/entity/AndroidHprofMemoryInfo.java
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,19 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.hydralab.performance.entity; | ||
|
||
import com.microsoft.hydralab.performance.hprof.ObjectInfo; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
@Data | ||
public class AndroidHprofMemoryInfo implements Serializable { | ||
private List<ObjectInfo> bitmapInfoList; | ||
private List<ObjectInfo> topObjectList; | ||
private String appPackageName; | ||
private long timeStamp; | ||
private String description; | ||
} |
2 changes: 2 additions & 0 deletions
2
common/src/main/java/com/microsoft/hydralab/performance/entity/AndroidMemoryInfo.java
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
27 changes: 27 additions & 0 deletions
27
common/src/main/java/com/microsoft/hydralab/performance/hprof/BitmapInfo.java
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,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.hydralab.performance.hprof; | ||
|
||
import java.io.Serializable; | ||
|
||
public class BitmapInfo extends ObjectInfo implements Serializable { | ||
|
||
public int width; | ||
public int height; | ||
public int density; | ||
public boolean recycled; | ||
public int pixelsCount; | ||
public long nativePtr; | ||
public float perPixelSize; | ||
|
||
|
||
public void computePerPixelSize() { | ||
perPixelSize = nativeSize * 1f / height / width; | ||
} | ||
|
||
@Override | ||
public String getSizeInfo() { | ||
return super.getSizeInfo() + ", BitmapSize: " + width + " × " + height; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
common/src/main/java/com/microsoft/hydralab/performance/hprof/BitmapInfoExtractor.java
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,19 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.hydralab.performance.hprof; | ||
|
||
import com.squareup.haha.perflib.Instance; | ||
|
||
public class BitmapInfoExtractor extends Extractor { | ||
|
||
@Override | ||
public ObjectInfo extractInstanceInfo(int retainedSizeRanking, Instance instance) { | ||
return extractBitmapInfo(retainedSizeRanking, instance); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "bitmap"; | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
common/src/main/java/com/microsoft/hydralab/performance/hprof/Extractor.java
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,176 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.hydralab.performance.hprof; | ||
|
||
import com.squareup.haha.perflib.ClassInstance; | ||
import com.squareup.haha.perflib.ClassObj; | ||
import com.squareup.haha.perflib.Field; | ||
import com.squareup.haha.perflib.Instance; | ||
import com.squareup.haha.perflib.Type; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public abstract class Extractor { | ||
/** | ||
* min size in byte | ||
*/ | ||
private int minNativeSize = 1000; | ||
|
||
protected List<ObjectInfo> resultList = new ArrayList<>(); | ||
|
||
public void setMinNativeSize(int minNativeSize) { | ||
this.minNativeSize = minNativeSize; | ||
} | ||
|
||
public String getName() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
void onExtractInfo(int retainedSizeRanking, Instance instance) { | ||
ObjectInfo objectInfo = extractInstanceInfo(retainedSizeRanking, instance); | ||
if (objectInfo == null) { | ||
return; | ||
} | ||
resultList.add(objectInfo); | ||
} | ||
|
||
abstract ObjectInfo extractInstanceInfo(int retainedSizeRanking, Instance instance); | ||
|
||
public List<ObjectInfo> getResultList() { | ||
return resultList; | ||
} | ||
|
||
protected void mapSetBaseAttr(Instance instance, ObjectInfo bitmapInfo) { | ||
List<Instance> founds = new ArrayList<>(); | ||
ClassObj classObj = instance.getClassObj(); | ||
String className = classObj.getClassName(); | ||
String[] names = new String[1]; | ||
findRelatedInstances(instance, null, founds, names); | ||
bitmapInfo.instance = instance; | ||
bitmapInfo.firstLevelLauncherRef = founds.size() > 0 ? founds.get(0) : null; | ||
bitmapInfo.className = className; | ||
if (bitmapInfo.firstLevelLauncherRef instanceof ClassObj) { | ||
bitmapInfo.isStaticMember = true; | ||
} | ||
bitmapInfo.fieldName = names[0]; | ||
bitmapInfo.nativeSize = instance.getNativeSize(); | ||
bitmapInfo.distanceToRoot = instance.getDistanceToGcRoot(); | ||
bitmapInfo.retainedSize = instance.getTotalRetainedSize(); | ||
bitmapInfo.size = instance.getSize(); | ||
bitmapInfo.id = instance.getId(); | ||
bitmapInfo.uniqueId = instance.getUniqueId(); | ||
} | ||
|
||
protected void findRelatedInstances(Instance instance, Instance visited, List<Instance> founds, String[] names) { | ||
if (instance == null) { | ||
return; | ||
} | ||
ClassObj classObj = instance.getClassObj(); | ||
if (classObj == null) { | ||
if (!(instance instanceof ClassObj)) { | ||
return; | ||
} | ||
classObj = (ClassObj) instance; | ||
} | ||
String className = classObj.getClassName(); | ||
if (className.contains(".launcher")) { | ||
founds.add(instance); | ||
if (instance instanceof ClassInstance) { | ||
ClassInstance classInstance = (ClassInstance) instance; | ||
List<ClassInstance.FieldValue> values = classInstance.getValues(); | ||
for (ClassInstance.FieldValue value : values) { | ||
if (Objects.equals(value.getField().getType(), Type.OBJECT)) { | ||
if (Objects.equals(value.getValue(), visited)) { | ||
if (visited != null) { | ||
founds.add(visited); | ||
names[0] = value.getField().getName(); | ||
} | ||
} | ||
} | ||
} | ||
// static case | ||
} else if (instance instanceof ClassObj) { | ||
if (instance.getNextInstanceToGcRoot() == null) { | ||
founds.add(instance); | ||
Map<Field, Object> staticFieldValues = ((ClassObj) instance).getStaticFieldValues(); | ||
for (Map.Entry<Field, Object> fieldObjectEntry : staticFieldValues.entrySet()) { | ||
Field key = fieldObjectEntry.getKey(); | ||
if (Objects.equals(key.getType(), Type.OBJECT)) { | ||
if (Objects.equals(staticFieldValues.get(key), visited)) { | ||
if (visited != null) { | ||
founds.add(visited); | ||
names[0] = key.getName(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
findRelatedInstances(instance.getNextInstanceToGcRoot(), instance, founds, names); | ||
} | ||
|
||
public ObjectInfo extractBitmapInfo(int retainedSizeRanking, Instance instance) { | ||
ClassObj classObj = instance.getClassObj(); | ||
String className = classObj.getClassName(); | ||
if (className.equals("android.graphics.Bitmap")) { | ||
if (instance instanceof ClassInstance) { | ||
ClassInstance classInstance = (ClassInstance) instance; | ||
List<ClassInstance.FieldValue> values = classInstance.getValues(); | ||
BitmapInfo bitmapInfo = new BitmapInfo(); | ||
if (instance.getNativeSize() < minNativeSize) { | ||
return null; | ||
} | ||
mapSetBaseAttr(instance, bitmapInfo); | ||
for (ClassInstance.FieldValue value : values) { | ||
Field field = value.getField(); | ||
String name = field.getName(); | ||
switch (name) { | ||
case "mWidth": | ||
bitmapInfo.width = (int) value.getValue(); | ||
break; | ||
case "mHeight": | ||
bitmapInfo.height = (int) value.getValue(); | ||
break; | ||
case "mDensity": | ||
bitmapInfo.density = (int) value.getValue(); | ||
break; | ||
case "mNativePtr": | ||
bitmapInfo.nativePtr = (long) value.getValue(); | ||
break; | ||
case "mRecycled": | ||
bitmapInfo.recycled = (boolean) value.getValue(); | ||
break; | ||
} | ||
} | ||
bitmapInfo.computePerPixelSize(); | ||
return bitmapInfo; | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
public abstract String getType(); | ||
|
||
public void onExtractComplete() { | ||
resultList.sort((o1, o2) -> Long.compare(o2.retainedSize, o1.retainedSize)); | ||
Iterator<ObjectInfo> iterator = resultList.iterator(); | ||
int i = 0; | ||
while (iterator.hasNext()) { | ||
ObjectInfo next = iterator.next(); | ||
if (next.distanceToRoot == 0 || next.getFieldChainString() == null) { | ||
iterator.remove(); | ||
continue; | ||
} | ||
next.index = i + 1; | ||
i++; | ||
} | ||
} | ||
} |
Oops, something went wrong.