Skip to content

Commit

Permalink
#Deprecated#
Browse files Browse the repository at this point in the history
Changed <leakCanary debug="true" /> to <leakCanary /> and LeakConfig.debug is deprecated
  • Loading branch information
hui.zhao authored and hui.zhao committed Mar 25, 2020
1 parent e9ad0d9 commit b00eaeb
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<cpu intervalMillis="2000" />
<battery />
<fps intervalMillis="2000" />
<leakCanary debug="true" />
<leakCanary />
<heap intervalMillis="2000" />
<pss intervalMillis="2000" />
<ram intervalMillis="2000" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void run() {
LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(false);
LeakCanary.setConfig(new LeakCanary.Config().newBuilder()
.requestWriteExternalStoragePermission(false)
.dumpHeap(leakModule.config().debug())
.dumpHeap(true)
.onHeapAnalyzedListener(new OnHeapAnalyzedListener() {
@Override
public void onHeapAnalyzed(@NotNull HeapAnalysis heapAnalysis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,7 @@ public static GodEyeConfig fromInputStream(InputStream is) {
// leak
element = getFirstElementByTagInRoot(root, "leakCanary");
if (element != null) {
final String debug = element.getAttribute("debug");
LeakConfig leakConfig = new LeakConfig();
if (!TextUtils.isEmpty(debug)) {
leakConfig.debug = Boolean.parseBoolean(debug);
} else {
leakConfig.debug = true;
}
builder.withLeakConfig(leakConfig);
builder.withLeakConfig(new LeakConfig());
}
// heap
element = getFirstElementByTagInRoot(root, "heap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
@Keep
public class LeakConfig implements Serializable {
// if you want leak module work in production,set debug false
/**
* @deprecated
*/
@Deprecated
public boolean debug;
/**
* @deprecated
Expand All @@ -31,13 +35,20 @@ public LeakConfig(boolean debug, boolean debugNotification, String leakRefInfoPr
}

public LeakConfig() {
this.debug = true;
}

/**
* @deprecated
*/
@Deprecated
public LeakConfig(boolean debug) {
this.debug = debug;
}

/**
* @deprecated
*/
@Deprecated
public boolean debug() {
return debug;
}
Expand All @@ -63,8 +74,6 @@ public String leakRefInfoProvider() {

@Override
public String toString() {
return "LeakConfig{" +
"debug=" + debug +
'}';
return "LeakConfig{}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public static HeapInfo getAppHeapInfo() {
return heapInfo;
}

/**
* get native heap
*
* @return
*/
public static NativeHeapInfo getAppNativeHeap() {
NativeHeapInfo nativeHeapInfo = new NativeHeapInfo();

nativeHeapInfo.heapSizeKb = Debug.getNativeHeapSize() / 1024;
nativeHeapInfo.heapAllocatedKb = Debug.getNativeHeapAllocatedSize() / 1024;
nativeHeapInfo.heapFreeSizeKb = Debug.getNativeHeapFreeSize() / 1024;
return nativeHeapInfo;
}
// /**
// * get native heap
// *
// * @return
// */
// public static NativeHeapInfo getAppNativeHeap() {
// NativeHeapInfo nativeHeapInfo = new NativeHeapInfo();
//
// nativeHeapInfo.heapSizeKb = Debug.getNativeHeapSize() / 1024;
// nativeHeapInfo.heapAllocatedKb = Debug.getNativeHeapAllocatedSize() / 1024;
// nativeHeapInfo.heapFreeSizeKb = Debug.getNativeHeapFreeSize() / 1024;
// return nativeHeapInfo;
// }

/**
* 获取应用实际占用RAM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ private void assertConfig(GodEyeConfig config) {
assertEquals(2000, config.getFpsConfig().intervalMillis());
assertEquals(2000, config.getHeapConfig().intervalMillis());
assertEquals("cn.hikyson.godeye.core.internal.modules.imagecanary.DefaultImageCanaryConfigProvider", config.getImageCanaryConfig().getImageCanaryConfigProvider());
assertEquals(true, config.getLeakConfig().debug());
assertEquals(10, config.getMethodCanaryConfig().lowCostMethodThresholdMillis());
assertEquals(300, config.getMethodCanaryConfig().maxMethodCountSingleThreadByCost());
assertEquals(JsonUtil.toJson(new NetworkConfig()), JsonUtil.toJson(config.getNetworkConfig()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cn.hikyson.godeye.core.internal.modules.memory;

import android.os.Build;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import cn.hikyson.godeye.core.GodEye;
import cn.hikyson.godeye.core.helper.RoboTestApplication;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, application = RoboTestApplication.class)
public class MemoryUtilTest {

@Test
public void getAppHeapInfo() {
HeapInfo heapInfo = MemoryUtil.getAppHeapInfo();
Assert.assertTrue(heapInfo.allocatedKb > 0);
Assert.assertTrue(heapInfo.freeMemKb > 0);
Assert.assertTrue(heapInfo.maxMemKb > 0);
}

@Test
public void getAppPssInfo() {
try {
PssInfo pssInfo = MemoryUtil.getAppPssInfo(GodEye.instance().getApplication());
} catch (NullPointerException ignore) {
} catch (Throwable e) {
Assert.fail();
}
}

@Test
public void getRamInfo() {
RamInfo ramInfo = MemoryUtil.getRamInfo(GodEye.instance().getApplication());
Assert.assertNotNull(ramInfo);
}
}
2 changes: 1 addition & 1 deletion android-godeye/src/test/resources/install.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<cpu intervalMillis="2000" />
<battery />
<fps intervalMillis="2000" />
<leakCanary debug="true" />
<leakCanary />
<heap intervalMillis="2000" />
<pss intervalMillis="2000" />
<ram intervalMillis="2000" />
Expand Down
2 changes: 1 addition & 1 deletion android-godeye/src/test/resources/install2.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<cpu intervalMillis="4000" />
<battery />
<fps intervalMillis="4000" />
<leakCanary debug="true" />
<leakCanary />
<heap intervalMillis="4000" />
<pss intervalMillis="4000" />
<ram intervalMillis="4000" />
Expand Down

0 comments on commit b00eaeb

Please sign in to comment.