DevEco Studio集成的DevEco Profiler性能调优工具(以下简称为Profiler),提供Time、Allocation、Snapshot、CPU等场景化分析任务类型。开发者可使用Profiler的Allocation内存分析器,在应用或服务运行时实时显示内存使用情况,识别可能会导致应用卡顿、内存泄漏、内存抖动的问题,或找到导致内存瓶颈的问题。
使用约束
已通过USB连接设备并在设备上打开需要调试的设备。
仅在应用为debug编译模式时使用
仅支持OpenHarmony API 9及以上版本的Stage工程
场景示例
本示例设置两个页面,通过内存分析器来分析页面跳转场景下是否存在内存分配不合理的问题。
主页面代码如下:
import router from '@ohos.router'
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Button("点击跳转").onClick(() => {
onJumpClick();
})
}
.width('100%')
}
.height('100%')
}
}
// 跳转下个页面
function onJumpClick(): void {
router.pushUrl({
url: 'pages/second' // 目标url
}, router.RouterMode.Standard, (err) => {
if (err) {
console.error(`Invoke pushUrl failed, code is ${
err.code}, message is ${
err.message}`);
return;
}
console.info('Invoke pushUrl succeeded.');
});
}
跳转后页面代码如下:
@Component
struct SwiperChild {
@State arr: number[] = [];
aboutToAppear(): void {
for (let i = 1; i <= 10; i++) {
this.data.push(i);
}
}
build() {
Column() {
List({
space: 20 }) {
ForEach(this.arr, (index: number) => {
ListItem() {
Text(index.