mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-18 21:21:17 +00:00
### Description Try to move 'env.wasm.trace' to 'env.trace' to make it less confusing, because it also works in webgpu. Marked 'env.wasm.trace' as deprecated.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import {env} from './env-impl.js';
|
|
|
|
export const TRACE = (deviceType: string, label: string) => {
|
|
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
|
|
return;
|
|
}
|
|
// eslint-disable-next-line no-console
|
|
console.timeStamp(`${deviceType}::ORT::${label}`);
|
|
};
|
|
|
|
const TRACE_FUNC = (msg: string, extraMsg?: string) => {
|
|
const stack = new Error().stack?.split(/\r\n|\r|\n/g) || [];
|
|
let hasTraceFunc = false;
|
|
for (let i = 0; i < stack.length; i++) {
|
|
if (hasTraceFunc && !stack[i].includes('TRACE_FUNC')) {
|
|
let label = `FUNC_${msg}::${stack[i].trim().split(' ')[1]}`;
|
|
if (extraMsg) {
|
|
label += `::${extraMsg}`;
|
|
}
|
|
TRACE('CPU', label);
|
|
return;
|
|
}
|
|
if (stack[i].includes('TRACE_FUNC')) {
|
|
hasTraceFunc = true;
|
|
}
|
|
}
|
|
};
|
|
|
|
export const TRACE_FUNC_BEGIN = (extraMsg?: string) => {
|
|
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
|
|
return;
|
|
}
|
|
TRACE_FUNC('BEGIN', extraMsg);
|
|
};
|
|
|
|
export const TRACE_FUNC_END = (extraMsg?: string) => {
|
|
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
|
|
return;
|
|
}
|
|
TRACE_FUNC('END', extraMsg);
|
|
};
|