@kkarum/framework 2.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Framework.ts +337 -0
- package/Framework.ts.meta +10 -0
- package/FrameworkBase.ts +207 -0
- package/FrameworkBase.ts.meta +10 -0
- package/FrameworkInitialize.ts +79 -0
- package/FrameworkInitialize.ts.meta +10 -0
- package/README.md +93 -0
- package/README.md.meta +6 -0
- package/animation/FWAnimation.ts +13 -0
- package/animation/FWAnimation.ts.meta +10 -0
- package/animation/FWSkeleton.ts +174 -0
- package/animation/FWSkeleton.ts.meta +10 -0
- package/animation/FWTween.ts +60 -0
- package/animation/FWTween.ts.meta +10 -0
- package/animation.meta +13 -0
- package/component/FWVirtuaScrollViewComponent.ts +56 -0
- package/component/FWVirtuaScrollViewComponent.ts.meta +10 -0
- package/component/FWVirtualViewComponent.ts +2212 -0
- package/component/FWVirtualViewComponent.ts.meta +10 -0
- package/component.meta +13 -0
- package/config/FWAssetConfig.ts +7 -0
- package/config/FWAssetConfig.ts.meta +10 -0
- package/config/FWSystemConfig.ts +29 -0
- package/config/FWSystemConfig.ts.meta +10 -0
- package/config.meta +13 -0
- package/controller/FWLayerController.ts +178 -0
- package/controller/FWLayerController.ts.meta +10 -0
- package/controller.meta +13 -0
- package/data/FWData.ts +6 -0
- package/data/FWData.ts.meta +10 -0
- package/data.meta +13 -0
- package/define/FWEventDefine.ts +28 -0
- package/define/FWEventDefine.ts.meta +10 -0
- package/define/FWSystemDefine.ts +154 -0
- package/define/FWSystemDefine.ts.meta +10 -0
- package/define.meta +13 -0
- package/entry/FWEntry.ts +219 -0
- package/entry/FWEntry.ts.meta +10 -0
- package/entry.meta +13 -0
- package/expand/FWCocosExpand.ts +73 -0
- package/expand/FWCocosExpand.ts.meta +10 -0
- package/expand/FWDecorator.ts +366 -0
- package/expand/FWDecorator.ts.meta +10 -0
- package/expand/FWNodeExpand.ts +147 -0
- package/expand/FWNodeExpand.ts.meta +10 -0
- package/expand/FWRollingViewNesting.ts +195 -0
- package/expand/FWRollingViewNesting.ts.meta +10 -0
- package/expand/FWTweenExpand.ts +44 -0
- package/expand/FWTweenExpand.ts.meta +10 -0
- package/expand.meta +13 -0
- package/item/FWVirtualListItem.ts +141 -0
- package/item/FWVirtualListItem.ts.meta +10 -0
- package/item.meta +13 -0
- package/language/FWLanguage.ts +71 -0
- package/language/FWLanguage.ts.meta +10 -0
- package/language/FWLanguageLabelLocalize.ts +144 -0
- package/language/FWLanguageLabelLocalize.ts.meta +10 -0
- package/language/FWLanguageSkeletonLocalize.ts +106 -0
- package/language/FWLanguageSkeletonLocalize.ts.meta +10 -0
- package/language/FWLanguageSpriteLocalize.ts +81 -0
- package/language/FWLanguageSpriteLocalize.ts.meta +10 -0
- package/language.meta +13 -0
- package/layer/FWLayer.ts +14 -0
- package/layer/FWLayer.ts.meta +10 -0
- package/layer.meta +13 -0
- package/log/FWLog.ts +135 -0
- package/log/FWLog.ts.meta +10 -0
- package/log.meta +13 -0
- package/logic/FWLogic.ts +6 -0
- package/logic/FWLogic.ts.meta +10 -0
- package/logic.meta +13 -0
- package/machine/FWAnimationMachine.ts +28 -0
- package/machine/FWAnimationMachine.ts.meta +10 -0
- package/machine/FWStateMachine.ts +74 -0
- package/machine/FWStateMachine.ts.meta +10 -0
- package/machine.meta +13 -0
- package/manager/FWAnimationManager.ts +89 -0
- package/manager/FWAnimationManager.ts.meta +10 -0
- package/manager/FWAssetManager.ts +451 -0
- package/manager/FWAssetManager.ts.meta +10 -0
- package/manager/FWAudioManager.ts +339 -0
- package/manager/FWAudioManager.ts.meta +10 -0
- package/manager/FWBundleManager.ts +97 -0
- package/manager/FWBundleManager.ts.meta +10 -0
- package/manager/FWComponentManager.ts +24 -0
- package/manager/FWComponentManager.ts.meta +10 -0
- package/manager/FWEngineManager.ts +74 -0
- package/manager/FWEngineManager.ts.meta +10 -0
- package/manager/FWEventManager.ts +361 -0
- package/manager/FWEventManager.ts.meta +10 -0
- package/manager/FWHotUpdateManager.ts +344 -0
- package/manager/FWHotUpdateManager.ts.meta +10 -0
- package/manager/FWLanguageManager.ts +114 -0
- package/manager/FWLanguageManager.ts.meta +10 -0
- package/manager/FWLayerManager.ts +862 -0
- package/manager/FWLayerManager.ts.meta +10 -0
- package/manager/FWManager.ts +9 -0
- package/manager/FWManager.ts.meta +10 -0
- package/manager/FWObjectManager.ts +161 -0
- package/manager/FWObjectManager.ts.meta +10 -0
- package/manager/FWPerformanceManager.ts +198 -0
- package/manager/FWPerformanceManager.ts.meta +10 -0
- package/manager/FWPromiseManager.ts +504 -0
- package/manager/FWPromiseManager.ts.meta +10 -0
- package/manager/FWResManager.ts +299 -0
- package/manager/FWResManager.ts.meta +10 -0
- package/manager/FWSocketManager.ts +93 -0
- package/manager/FWSocketManager.ts.meta +10 -0
- package/manager/FWStateManager.ts +100 -0
- package/manager/FWStateManager.ts.meta +10 -0
- package/manager/FWTaskManager.ts +41 -0
- package/manager/FWTaskManager.ts.meta +10 -0
- package/manager/FWTimeManager.ts +442 -0
- package/manager/FWTimeManager.ts.meta +10 -0
- package/manager/FWUiManager.ts +217 -0
- package/manager/FWUiManager.ts.meta +10 -0
- package/manager.meta +13 -0
- package/package.json +11 -0
- package/package.json.meta +6 -0
- package/registry/FWRegistry.ts +62 -0
- package/registry/FWRegistry.ts.meta +10 -0
- package/registry.meta +13 -0
- package/render/FWRenderAssembler.ts +620 -0
- package/render/FWRenderAssembler.ts.meta +10 -0
- package/render.meta +13 -0
- package/scene/FWScene.ts +23 -0
- package/scene/FWScene.ts.meta +10 -0
- package/scene.meta +13 -0
- package/service/FWService.ts +11 -0
- package/service/FWService.ts.meta +10 -0
- package/service/http/FWHttp.ts +103 -0
- package/service/http/FWHttp.ts.meta +10 -0
- package/service/http.meta +13 -0
- package/service/socket/FWSocket.ts +367 -0
- package/service/socket/FWSocket.ts.meta +10 -0
- package/service/socket/FWSocketHandle.ts +16 -0
- package/service/socket/FWSocketHandle.ts.meta +10 -0
- package/service/socket/FWSocketSender.ts +14 -0
- package/service/socket/FWSocketSender.ts.meta +10 -0
- package/service/socket/mock/FWSocketMock.ts +202 -0
- package/service/socket/mock/FWSocketMock.ts.meta +10 -0
- package/service/socket/mock.meta +13 -0
- package/service/socket.meta +13 -0
- package/service.meta +13 -0
- package/state/FWState.ts +8 -0
- package/state/FWState.ts.meta +10 -0
- package/state.meta +13 -0
- package/types/Creator.d.ts +121 -0
- package/types/Creator.d.ts.meta +6 -0
- package/types/FW.d.ts +3016 -0
- package/types/FW.d.ts.meta +6 -0
- package/types/Global.d.ts +22 -0
- package/types/Global.d.ts.meta +10 -0
- package/types.meta +13 -0
- package/utils/FWLodash.ts +105 -0
- package/utils/FWLodash.ts.meta +10 -0
- package/utils/FWMask.ts +222 -0
- package/utils/FWMask.ts.meta +10 -0
- package/utils/FWObject.ts +27 -0
- package/utils/FWObject.ts.meta +10 -0
- package/utils/FWObjectPool.ts +177 -0
- package/utils/FWObjectPool.ts.meta +10 -0
- package/utils/FWQueue.ts +55 -0
- package/utils/FWQueue.ts.meta +10 -0
- package/utils/FWResLoader.ts +139 -0
- package/utils/FWResLoader.ts.meta +10 -0
- package/utils/FWTask.ts +227 -0
- package/utils/FWTask.ts.meta +10 -0
- package/utils/FWUtils.ts +15 -0
- package/utils/FWUtils.ts.meta +10 -0
- package/utils.meta +13 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { FWObjectPool } from "../utils/FWObjectPool";
|
|
2
|
+
import { FWManager } from "./FWManager";
|
|
3
|
+
|
|
4
|
+
export default class FWObjectManager
|
|
5
|
+
extends FWManager
|
|
6
|
+
implements FW.ObjectManager
|
|
7
|
+
{
|
|
8
|
+
public initialize(): void {
|
|
9
|
+
this.poolMap = new Map<string, FWObjectPool>();
|
|
10
|
+
this.poolIdCounter = 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public onDestroy(): void {
|
|
14
|
+
this.poolMap.forEach((pool, tag) => {
|
|
15
|
+
try {
|
|
16
|
+
pool.onDestroy();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
FW.Log.error(`销毁对象池失败: ${tag}`, error);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
this.poolMap.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private poolMap: Map<string, FWObjectPool>;
|
|
25
|
+
private poolIdCounter: number = 0;
|
|
26
|
+
|
|
27
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
28
|
+
node: cc.Node,
|
|
29
|
+
parent: cc.Node,
|
|
30
|
+
tag?: string,
|
|
31
|
+
): Promise<FWObjectPool>;
|
|
32
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
33
|
+
prefab: cc.Prefab,
|
|
34
|
+
parent: cc.Node,
|
|
35
|
+
tag?: string,
|
|
36
|
+
): Promise<FWObjectPool>;
|
|
37
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
38
|
+
assetProperty: FW.AssetProperty,
|
|
39
|
+
parent: cc.Node,
|
|
40
|
+
tag?: string,
|
|
41
|
+
): Promise<FWObjectPool>;
|
|
42
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
43
|
+
node: cc.Node,
|
|
44
|
+
parent: cc.Node,
|
|
45
|
+
type?: number,
|
|
46
|
+
): Promise<FWObjectPool>;
|
|
47
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
48
|
+
prefab: cc.Prefab,
|
|
49
|
+
parent: cc.Node,
|
|
50
|
+
type?: number,
|
|
51
|
+
): Promise<FWObjectPool>;
|
|
52
|
+
async createObjectPool<T extends FW.Object = FW.Object>(
|
|
53
|
+
assetProperty: FW.AssetProperty,
|
|
54
|
+
parent: cc.Node,
|
|
55
|
+
type?: number,
|
|
56
|
+
): Promise<FWObjectPool>;
|
|
57
|
+
async createObjectPool<
|
|
58
|
+
T extends FW.Object = FW.Object,
|
|
59
|
+
>(): Promise<FWObjectPool> {
|
|
60
|
+
if (arguments.length < 2 || arguments.length > 3) {
|
|
61
|
+
FW.Log.error("createObjectPool 参数数量错误,需要2-3个参数");
|
|
62
|
+
throw new Error("Invalid arguments count");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let objectNode: cc.Node = null;
|
|
66
|
+
let objectPrefab: cc.Prefab = null;
|
|
67
|
+
let objectAssetProperty: FW.AssetProperty = null;
|
|
68
|
+
let objectParent: cc.Node;
|
|
69
|
+
let objectTag: string;
|
|
70
|
+
let objectType: FW.SystemDefine.FWObjectType;
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const resources = arguments[0];
|
|
74
|
+
if (resources instanceof cc.Node) {
|
|
75
|
+
objectNode = resources;
|
|
76
|
+
} else if (resources instanceof cc.Prefab) {
|
|
77
|
+
objectPrefab = resources;
|
|
78
|
+
objectNode = cc.instantiate(objectPrefab);
|
|
79
|
+
} else {
|
|
80
|
+
objectAssetProperty = resources;
|
|
81
|
+
objectPrefab =
|
|
82
|
+
await FW.Entry.resMgr.loadAsset<cc.Prefab>(objectAssetProperty);
|
|
83
|
+
if (!objectPrefab) {
|
|
84
|
+
throw new Error(`加载预制体失败: ${objectAssetProperty.path}`);
|
|
85
|
+
}
|
|
86
|
+
objectNode = cc.instantiate(objectPrefab);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
objectParent = arguments[1];
|
|
90
|
+
if (!(objectParent instanceof cc.Node)) {
|
|
91
|
+
throw new Error("第二个参数必须是 cc.Node 类型");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const arg = arguments[2];
|
|
95
|
+
if (typeof arg === "string") {
|
|
96
|
+
objectTag = arg;
|
|
97
|
+
objectType = FW.SystemDefine.FWObjectType.OPACITY;
|
|
98
|
+
} else if (typeof arg === "number") {
|
|
99
|
+
objectTag = `pool_${this.poolIdCounter++}`;
|
|
100
|
+
objectType = arg;
|
|
101
|
+
} else {
|
|
102
|
+
objectTag = `pool_${this.poolIdCounter++}`;
|
|
103
|
+
objectType = FW.SystemDefine.FWObjectType.OPACITY;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (this.poolMap.has(objectTag)) {
|
|
107
|
+
this.destroyObjectPool(objectTag);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const pool = new FWObjectPool<T>(objectNode, objectParent, objectType);
|
|
111
|
+
this.poolMap.set(objectTag, pool);
|
|
112
|
+
|
|
113
|
+
return pool;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
FW.Log.error("创建对象池失败:", error);
|
|
116
|
+
|
|
117
|
+
if (objectNode && objectNode.isValid) {
|
|
118
|
+
objectNode.destroy();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getObjectPool(tag: string): FWObjectPool | undefined {
|
|
126
|
+
if (!this.poolMap.has(tag)) {
|
|
127
|
+
FW.Log.warn(`对象池不存在: ${tag}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return this.poolMap.get(tag);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
destroyObjectPool(tag: string): boolean {
|
|
134
|
+
if (!this.poolMap.has(tag)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const pool = this.poolMap.get(tag);
|
|
140
|
+
pool.onDestroy();
|
|
141
|
+
this.poolMap.delete(tag);
|
|
142
|
+
return true;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
getPoolStats(): { total: number; tags: string[] } {
|
|
149
|
+
return {
|
|
150
|
+
total: this.poolMap.size,
|
|
151
|
+
tags: Array.from(this.poolMap.keys()),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
clearAllPools(): void {
|
|
156
|
+
const tags = Array.from(this.poolMap.keys());
|
|
157
|
+
tags.forEach((tag) => {
|
|
158
|
+
this.destroyObjectPool(tag);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { FWManager } from './FWManager';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 性能管理器
|
|
5
|
+
*/
|
|
6
|
+
export class FWPerformanceManager extends FWManager implements FW.PerformanceManager {
|
|
7
|
+
private metrics: FW.PerformanceMetric[] = [];
|
|
8
|
+
private moduleStats: Map<
|
|
9
|
+
string,
|
|
10
|
+
{
|
|
11
|
+
totalDuration: number;
|
|
12
|
+
operationCount: number;
|
|
13
|
+
minDuration: number;
|
|
14
|
+
maxDuration: number;
|
|
15
|
+
}
|
|
16
|
+
> = new Map();
|
|
17
|
+
|
|
18
|
+
private performanceOptions: FW.PerformanceModuleOptions;
|
|
19
|
+
|
|
20
|
+
public async initialize(): Promise<void> {
|
|
21
|
+
this.performanceOptions = {
|
|
22
|
+
autoCollect: true,
|
|
23
|
+
dataRetentionTime: 5 * 60 * 1000,
|
|
24
|
+
samplingRate: 1.0,
|
|
25
|
+
warningThreshold: 1000,
|
|
26
|
+
};
|
|
27
|
+
if (this.performanceOptions.autoCollect) {
|
|
28
|
+
this.autoClear();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public onDestroy(): void {
|
|
33
|
+
this.metrics = [];
|
|
34
|
+
this.moduleStats.clear();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected onCleanup(): void {}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 记录操作性能指标
|
|
41
|
+
*/
|
|
42
|
+
public recordOperationMetric(module: string, operation: string, duration: number): void {
|
|
43
|
+
if (Math.random() > this.performanceOptions.samplingRate!) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const metric: FW.PerformanceMetric = {
|
|
47
|
+
module,
|
|
48
|
+
operation,
|
|
49
|
+
duration,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
this.metrics.push(metric);
|
|
54
|
+
this.updateModuleStats(module, duration);
|
|
55
|
+
|
|
56
|
+
if (duration > this.performanceOptions.warningThreshold!) {
|
|
57
|
+
FW.Log.warn(`Performance warning: ${module}.${operation} took ${duration}ms`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 获取指定模块的性能报告
|
|
63
|
+
*/
|
|
64
|
+
public getModuleReport(module: string): FW.PerformanceReport | null {
|
|
65
|
+
const stats = this.moduleStats.get(module);
|
|
66
|
+
if (!stats) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const recentMetrics = this.metrics.filter((m) => m.module === module).slice(-500);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
module,
|
|
74
|
+
totalOperations: stats.operationCount,
|
|
75
|
+
averageDuration: stats.totalDuration / stats.operationCount,
|
|
76
|
+
minDuration: stats.minDuration,
|
|
77
|
+
maxDuration: stats.maxDuration,
|
|
78
|
+
recentMetrics,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取所有管理器的性能报告
|
|
84
|
+
*/
|
|
85
|
+
public getAllReports(): Map<string, FW.PerformanceReport> {
|
|
86
|
+
const reports = new Map<string, FW.PerformanceReport>();
|
|
87
|
+
|
|
88
|
+
this.moduleStats.forEach((stats, module) => {
|
|
89
|
+
const recentMetrics = this.metrics.filter((m) => m.module === module).slice(-500);
|
|
90
|
+
reports.set(module, {
|
|
91
|
+
module,
|
|
92
|
+
totalOperations: stats.operationCount,
|
|
93
|
+
averageDuration: stats.totalDuration / stats.operationCount,
|
|
94
|
+
minDuration: stats.minDuration,
|
|
95
|
+
maxDuration: stats.maxDuration,
|
|
96
|
+
recentMetrics,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return reports;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 获取性能摘要
|
|
105
|
+
*/
|
|
106
|
+
public getPerformanceSummary(): {
|
|
107
|
+
totalOperations: number;
|
|
108
|
+
averageOperationTime: number;
|
|
109
|
+
slowestModule: string;
|
|
110
|
+
mostActiveModule: string;
|
|
111
|
+
} {
|
|
112
|
+
let totalOperations = 0;
|
|
113
|
+
let totalDuration = 0;
|
|
114
|
+
let slowestModule = '';
|
|
115
|
+
let maxAvgDuration = 0;
|
|
116
|
+
let mostActiveModule = '';
|
|
117
|
+
let maxOperations = 0;
|
|
118
|
+
|
|
119
|
+
this.moduleStats.forEach((stats, module) => {
|
|
120
|
+
totalOperations += stats.operationCount;
|
|
121
|
+
totalDuration += stats.totalDuration;
|
|
122
|
+
|
|
123
|
+
const avgDuration = stats.totalDuration / stats.operationCount;
|
|
124
|
+
if (avgDuration > maxAvgDuration) {
|
|
125
|
+
maxAvgDuration = avgDuration;
|
|
126
|
+
slowestModule = module;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (stats.operationCount > maxOperations) {
|
|
130
|
+
maxOperations = stats.operationCount;
|
|
131
|
+
mostActiveModule = module;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
totalOperations,
|
|
137
|
+
averageOperationTime: totalOperations > 0 ? totalDuration / totalOperations : 0,
|
|
138
|
+
slowestModule: slowestModule,
|
|
139
|
+
mostActiveModule: mostActiveModule,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 清理数据
|
|
145
|
+
*/
|
|
146
|
+
public clearPerformanceData(
|
|
147
|
+
retentionTime: number = this.performanceOptions.dataRetentionTime!,
|
|
148
|
+
): number {
|
|
149
|
+
const cutoffTime = Date.now() - retentionTime;
|
|
150
|
+
const initialLength = this.metrics.length;
|
|
151
|
+
|
|
152
|
+
this.metrics = this.metrics.filter((metric) => metric.timestamp > cutoffTime);
|
|
153
|
+
|
|
154
|
+
const removedCount = initialLength - this.metrics.length;
|
|
155
|
+
if (removedCount > 0) {
|
|
156
|
+
FW.Log.debug(`Cleaned up ${removedCount} old performance records`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return removedCount;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 重置所有性能数据
|
|
164
|
+
*/
|
|
165
|
+
public resetAllData(): void {
|
|
166
|
+
this.metrics = [];
|
|
167
|
+
this.moduleStats.clear();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 更新管理器统计信息
|
|
172
|
+
*/
|
|
173
|
+
private updateModuleStats(module: string, duration: number): void {
|
|
174
|
+
if (!this.moduleStats.has(module)) {
|
|
175
|
+
this.moduleStats.set(module, {
|
|
176
|
+
totalDuration: 0,
|
|
177
|
+
operationCount: 0,
|
|
178
|
+
minDuration: Infinity,
|
|
179
|
+
maxDuration: -Infinity,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const stats = this.moduleStats.get(module)!;
|
|
184
|
+
stats.totalDuration += duration;
|
|
185
|
+
stats.operationCount++;
|
|
186
|
+
stats.minDuration = Math.min(stats.minDuration, duration);
|
|
187
|
+
stats.maxDuration = Math.max(stats.maxDuration, duration);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 启动自动清理任务
|
|
192
|
+
*/
|
|
193
|
+
private autoClear(): void {
|
|
194
|
+
FW.Entry.timeMgr.schedule(() => {
|
|
195
|
+
this.clearPerformanceData();
|
|
196
|
+
}, 300);
|
|
197
|
+
}
|
|
198
|
+
}
|