Skip to content

Commit

Permalink
[js/common] move 'env.wasm.trace' to 'env.trace' (#19617)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
fs-eire authored Feb 27, 2024
1 parent 2e4d1b8 commit 3cb81cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions js/common/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export declare namespace Env {
/**
* set or get a boolean value indicating whether to enable trace.
*
* @deprecated Use `env.trace` instead. If `env.trace` is set, this property will be ignored.
* @defaultValue `false`
*/
trace?: boolean;
Expand Down Expand Up @@ -167,13 +168,21 @@ export interface Env {
* @defaultValue `'warning'`
*/
logLevel?: 'verbose'|'info'|'warning'|'error'|'fatal';

/**
* Indicate whether run in debug mode.
*
* @defaultValue `false`
*/
debug?: boolean;

/**
* set or get a boolean value indicating whether to enable trace.
*
* @defaultValue `false`
*/
trace?: boolean;

/**
* Get version of the current package.
*/
Expand Down
6 changes: 3 additions & 3 deletions js/common/lib/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {env} from './env-impl.js';

export const TRACE = (deviceType: string, label: string) => {
if (!env.wasm.trace) {
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
return;
}
// eslint-disable-next-line no-console
Expand All @@ -30,14 +30,14 @@ const TRACE_FUNC = (msg: string, extraMsg?: string) => {
};

export const TRACE_FUNC_BEGIN = (extraMsg?: string) => {
if (!env.wasm.trace) {
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
return;
}
TRACE_FUNC('BEGIN', extraMsg);
};

export const TRACE_FUNC_END = (extraMsg?: string) => {
if (!env.wasm.trace) {
if (typeof env.trace === 'undefined' ? !env.wasm.trace : !env.trace) {
return;
}
TRACE_FUNC('END', extraMsg);
Expand Down
3 changes: 2 additions & 1 deletion js/web/lib/wasm/jsep/backend-webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ export class WebGpuBackend {
}
setQueryType(): void {
this.queryType = 'none';
if (this.env.webgpu.profiling?.mode === 'default' || this.env.wasm.trace) {
if (this.env.webgpu.profiling?.mode === 'default' ||
(typeof this.env.trace === 'undefined' ? this.env.wasm.trace : this.env.trace)) {
if (this.device.features.has('chromium-experimental-timestamp-query-inside-passes')) {
this.queryType = 'inside-passes';
} else if (this.device.features.has('timestamp-query')) {
Expand Down

0 comments on commit 3cb81cd

Please sign in to comment.