task-123: 性能基准堆采样前先 GC,消除全量套件下残留垃圾导致的 1GB 边界 flaky
This commit is contained in:
+6
-1
@@ -237,9 +237,14 @@ public class SimilarAsinPerfFixture {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 采样当前堆已用字节峰值;MXBean 不可用时返回 -1,与 "> 0" 类断言不冲突(GC 场景始终可用)。 */
|
/**
|
||||||
|
* 采样当前堆已用字节峰值;MXBean 不可用时返回 -1,与 "> 0" 类断言不冲突(GC 场景始终可用)。
|
||||||
|
* 采样前先触发一次 GC:全量套件运行时前序测试的残留垃圾会让"已用堆"短暂虚高,
|
||||||
|
* 使 1GB 峰值边界断言在全量回归下随机失败;GC 后采样反映本夹具自身的存活集。
|
||||||
|
*/
|
||||||
private static long sampledPeakHeapBytes() {
|
private static long sampledPeakHeapBytes() {
|
||||||
try {
|
try {
|
||||||
|
System.gc();
|
||||||
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user