Skip to content

Commit

Permalink
chore: print mems data.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Sep 25, 2023
1 parent d952fe9 commit 18c94b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions integration_tests/lib/memory_leak.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,18 @@ class HomePageElement extends StatelessElement {
current = codes[currentIndex + 1];
currentIndex = currentIndex + 1;
}
}, codes.length);

await sleep(Duration(seconds: 1));
bool isLeaked = isMemLeaks(mems);
await sleep(Duration(seconds: 1));
bool isLeaked = isMemLeaks(mems);

print('memory leaks: ${isMemLeaks(mems)} $mems');
if (isLeaked) {
exit(1);
}

mems.clear();
}, codes.length);

print('memory leaks: ${isMemLeaks(mems)}');
if (isLeaked) {
exit(1);
}
exit(0);
}
}
Expand Down Expand Up @@ -254,7 +257,9 @@ class MemoryLeakNavigatorObserver extends NavigatorObserver {
@override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
super.didPush(route, previousRoute);
mems.add(ProcessInfo.currentRss / 1024);
Timer(Duration(milliseconds: 500), () {
mems.add(ProcessInfo.currentRss / 1024);
});
}

@override
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/lib/utils/mem_leak_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool memoryIncreaseRatio(List<double> memoryUsage) {
bool detectMemoryLeakBasedOnRegression(List<double> memoryUsage) {
List<double> timePoints = List.generate(memoryUsage.length, (index) => index.toDouble()); // [0.0, 1.0, 2.0, ...]
double slope = linearRegressionSlope(timePoints, memoryUsage);
return slope > 5; // 如果斜率大于0,则判断为可能存在内存泄漏
return slope > 10;
}

bool isMemLeaks(List<double> mems) {
Expand Down

0 comments on commit 18c94b7

Please sign in to comment.