You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
AdLike2048/assets/script/game/MemoryDiag.ts

61 lines
2.3 KiB

import { assetManager } from 'cc';
import { DEV } from 'cc/env';
import { ResourcesManager } from '../../mx/module/res/ResourcesManager';
import { ResourcePhase, getResourcePhase } from '../../mx/module/res/ResourcePhase';
import { UIID } from './ConfigRes';
/** 线上内存/资源快照采集(供 PerfReport 使用,不走运营 inLevel) */
export class MemoryDiag {
static getStats(): { bundleCount: number; pkgCount: number; assetCount: number; preloadedCount: number } {
const resStats = ResourcesManager.getInstance().getMemoryDiagStats();
let bundleCount = 0;
assetManager.bundles.forEach(() => bundleCount++);
return {
bundleCount,
pkgCount: resStats.pkgCount,
assetCount: resStats.assetCount,
preloadedCount: resStats.preloadedCount,
};
}
/**
* DEV:打印资源引用快照,辅助 decRef 审计(M7)。
* 在 Tab 切换 / 进退战斗前后各打一次,对比 pkgCount、assetCount、bundleCount。
*/
static logRefSnapshot(tag: string): void {
if (!DEV) return;
const stats = this.getStats();
const bundles: string[] = [];
assetManager.bundles.forEach((_b, name) => bundles.push(name));
bundles.sort();
console.log(
`[MemoryDiag] ${tag} pkg=${stats.pkgCount} asset=${stats.assetCount} bundle=${stats.bundleCount} preloaded=${stats.preloadedCount} bundles=${bundles.join(',')}`,
);
}
/** 战斗 / 大厅 / 其它(加载过渡等) */
static getPhase(): string {
const phase = getResourcePhase();
switch (phase) {
case ResourcePhase.Battle:
return '战斗';
case ResourcePhase.HallPreload:
return '大厅预载';
case ResourcePhase.Hall:
return '大厅';
case ResourcePhase.BattleExit:
return '战斗退出';
case ResourcePhase.Boot:
return '启动';
default:
break;
}
if (gg.ui?.hasPanel?.(UIID.BattleGame)) {
return '战斗';
}
if (gg.ui?.hasPanel?.(UIID.Home)) {
return gg.game?.preLoadChapterRes ? '大厅预载' : '大厅';
}
return '其它';
}
}