diff --git a/incremental/common/src/Utils.ts b/incremental/common/src/Utils.ts deleted file mode 100644 index d3867998d247418c5dcc31e6d3037c00c2d365b3..0000000000000000000000000000000000000000 --- a/incremental/common/src/Utils.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Utils { - static begin_: (str:string) => void = (str: string)=> { - } - static end_: () => void = () =>{ - } - - static Init(begin:(str:string) => void, end:() => void) { - Utils.begin_ = begin - Utils.end_ = end - } - - static traceBegin(str:string):void { - Utils.begin_(str) - } - static traceEnd(): void { - Utils.end_() - } -} diff --git a/incremental/common/src/index.ts b/incremental/common/src/index.ts index 45bd3d454c903864bdca34d57fc580da66c39cea..0533296ef8e6b1a150114df1a463e6d371fec255 100644 --- a/incremental/common/src/index.ts +++ b/incremental/common/src/index.ts @@ -53,4 +53,3 @@ export * from "./Finalization" export { SHA1Hash, createSha1 } from "./sha1" export { UniqueId } from "./uniqueId" export * from "./koalaKey" -export * from "./Utils" diff --git a/incremental/runtime/src/common/RuntimeProfiler.ts b/incremental/runtime/src/common/RuntimeProfiler.ts index a9c7b41cd6fc71ed413f94797759d7151ed5185f..b1998baeb201badb7961376032380edc310b3c0f 100644 --- a/incremental/runtime/src/common/RuntimeProfiler.ts +++ b/incremental/runtime/src/common/RuntimeProfiler.ts @@ -21,8 +21,17 @@ import { float64toInt32, int32 } from "@koalaui/common" */ const DEBUG_WITH_NODE_STATS = false +export interface RuntimeTracer { + /** called on enter to the specified section */ + begin(name: string): void + /** called to log the specified message */ + log(message: string): void + /** called on exit from the specified section */ + end(name: string): void +} + export class RuntimeProfiler { - private static readonly map: Map > | undefined = DEBUG_WITH_NODE_STATS + private static readonly map: Map> | undefined = DEBUG_WITH_NODE_STATS ? new Map>() : undefined @@ -43,6 +52,7 @@ export class RuntimeProfiler { if (!set.delete(node)) console.log("node is already disposed") } + public static tracer: RuntimeTracer | undefined = undefined public static instance: RuntimeProfiler | undefined = undefined private invalidations = 0 @@ -131,7 +141,7 @@ export class RuntimeProfiler { `layouts: ${this.layouts}`, `FPS: ${this.lastFPS}`, ) - RuntimeProfiler.map?.forEach((set:Set, kind:int32) => { + RuntimeProfiler.map?.forEach((set: Set, kind: int32) => { if (set.size > 0) array.push(kind + ":" + set.size) }) return array.join("\n") @@ -143,7 +153,7 @@ export class RuntimeProfiler { node() { this.nodes++ } realDraw() { this.realDraws++ } cachedDraw() { this.cachedDraws++ } - layout() { this.layouts++ } + layout() { this.layouts++ } measure() { this.measures++ } frame(ms: number) { if (ms - this.lastTime <= 1000) { diff --git a/incremental/runtime/src/index.ts b/incremental/runtime/src/index.ts index 97fe1925da5d3b299140e43c7a319eb69aec6e21..581d61d97466fd3fdd6f7ba7e66fa86bcb7152a2 100644 --- a/incremental/runtime/src/index.ts +++ b/incremental/runtime/src/index.ts @@ -67,7 +67,10 @@ export { transition, } from "./animation/TimeAnimation" -export { RuntimeProfiler } from "./common/RuntimeProfiler" +export { + RuntimeProfiler, + RuntimeTracer, +} from "./common/RuntimeProfiler" export { memoBind, diff --git a/incremental/runtime/src/states/State.ts b/incremental/runtime/src/states/State.ts index 9eb0f6be914490b490a1ad9ce3c21db78f6f4efb..93b460a87c16b66a91d09d0cd5b8b0d20689b7dd 100644 --- a/incremental/runtime/src/states/State.ts +++ b/incremental/runtime/src/states/State.ts @@ -26,7 +26,6 @@ import { refEqual, trackableProperties, uint32, - Utils, } from "@koalaui/common" import { Dependency, ScopeToStates, StateToScopes } from "./Dependency" import { Disposable, disposeContent, disposeContentBackward } from "./Disposable" @@ -943,7 +942,7 @@ export /* Improve:HQ private as public*/ class StateManagerImpl implements State context.parentManager = this context.contextData = this.contextData const task = () => { - Utils.traceBegin(`Do parallel task`); + RuntimeProfiler.tracer?.begin("parallel task") const old = StateManagerLocal.get() StateManagerLocal.set(context) builder(context); @@ -952,7 +951,7 @@ export /* Improve:HQ private as public*/ class StateManagerImpl implements State if (complete) { complete(); } - Utils.traceEnd(); + RuntimeProfiler.tracer?.end("parallel task") return undefined } launchJob(task).then(() => { }).catch((err: Error) => { @@ -964,7 +963,7 @@ export /* Improve:HQ private as public*/ class StateManagerImpl implements State merge(main: StateContext, rootScope: ComputableState, compute: () => void): void { const mainContext = main as StateManagerImpl - Utils.traceBegin(`merge`) + RuntimeProfiler.tracer?.begin("merge") mainContext.childManager.push(this) const current = rootScope as ScopeImpl const scope = main!.scopeEx(0, 1, () => { @@ -973,16 +972,16 @@ export /* Improve:HQ private as public*/ class StateManagerImpl implements State compute() if (scope.unchanged) { scope.cached - Utils.traceEnd() + RuntimeProfiler.tracer?.end("merge") return } current.cascadeParent = scope scope.recache() - Utils.traceEnd() + RuntimeProfiler.tracer?.end("merge") } terminate(rootScope: ComputableState): void { - Utils.traceBegin(`sub manager terminate`) + RuntimeProfiler.tracer?.begin("sub manager terminate") const root = rootScope as ScopeImpl const cascadeScope = root.cascadeParent as ScopeImpl cascadeScope.node = undefined @@ -990,7 +989,7 @@ export /* Improve:HQ private as public*/ class StateManagerImpl implements State root.dispose(); this.parentManager?.removeChild(this); this.parentManager = undefined; - Utils.traceEnd() + RuntimeProfiler.tracer?.end("sub manager terminate") } }