LensStudio:Preview.IPreviewProfiling
ClassRecords performance traces of a preview.
Records performance traces of a preview. Obtain it from the preview's profiling property.
Index
Properties
Methods
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
readonlyactiveTraceSession:TraceSession
Trace session that is currently recording, or null if none is.
Methods
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
outputPath | Path |