Skip to main content

LensStudio:Preview.IPreviewProfiling

Class

Records performance traces of a preview.

Records performance traces of a preview. Obtain it from the preview's profiling property.

Index

Example

Record a performance trace of a rendering preview for a fixed time. Only one trace can record at a time, and startTrace() requires the filesystem permission.

import { LensPreview } from 'LensStudio:LensPreview';

export async function tracePreview(preview: LensPreview, traceFile: Editor.Path, durationMs = 1000): Promise<void> {
const profiling = preview.profiling;
if (profiling.activeTraceSession) throw new Error('A trace is already recording');

const session = profiling.startTrace(traceFile);
if (!session) throw new Error('The trace could not start');
// Hold the timer handle until it fires, and clear it on every exit path.
let timer: ReturnType<typeof setTimeout> | undefined;
try {
await new Promise<void>(resolve => { timer = setTimeout(resolve, durationMs); });
} finally {
if (timer !== undefined) clearTimeout(timer);
session.finish(); // the file is written shortly afterwards
}
}

Extends

Properties

activeTraceSession

readonly activeTraceSession: TraceSession

Trace session that is currently recording, or null if none is.

Methods

getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


startTrace()

startTrace(outputPath): TraceSession

Starts recording a performance trace and returns a TraceSession; the trace is written to outputPath when the session finishes. Returns null if a trace is already recording or the path is empty. Requires the filesystem permission.

Parameters

ParameterType
outputPathPath

Returns

TraceSession