Class: TSegmentTimer
Defined in: debug/segment-timer.ts:193
Constructors
Constructor
new TSegmentTimer(
debugPanel,label):TSegmentTimer
Defined in: debug/segment-timer.ts:204
Parameters
debugPanel
label
string
Returns
TSegmentTimer
Methods
createCustomSegment()
createCustomSegment(
name,durationFunction,parentSegment?):TCustomSegment
Defined in: debug/segment-timer.ts:257
Create a segment that can be updated with custom duration values. This allows you to initialize a segment once and then provide duration updates via a function.
Parameters
name
string
Name of this segment (e.g., "CustomTimer")
durationFunction
() => number
Function that returns the current duration in milliseconds
parentSegment?
TSegment | null
Optional parent segment for hierarchical organization
Returns
A segment that can be updated with custom durations
Example
// Root-level custom segment
const customSegment = segmentTimer.createCustomSegment("MyTimer", () => {
return myCustomDuration; // Return duration in milliseconds
});
// Child custom segment
const parentSegment = segmentTimer.startSegment("Update");
const childCustomSegment = segmentTimer.createCustomSegment("Physics", () => {
return physicsDuration;
}, parentSegment.getSegment());
parentSegment.end();
// Later, update the segment with new duration
customSegment.updateDuration();
childCustomSegment.updateDuration();
getAlpha()
getAlpha():
number
Defined in: debug/segment-timer.ts:445
Get the alpha value for exponential moving average
Returns
number
getMaxSamples()
getMaxSamples():
number
Defined in: debug/segment-timer.ts:452
Get the maximum number of samples to keep
Returns
number
getSegments()
getSegments():
ReadonlyMap<string,Readonly<TSegment>>
Defined in: debug/segment-timer.ts:425
Get all segments sorted by their hierarchical path for external use
Returns
ReadonlyMap<string, Readonly<TSegment>>
reset()
reset():
void
Defined in: debug/segment-timer.ts:432
Reset all timing data (useful for profiling specific scenarios)
Returns
void
startChildSegment()
startChildSegment(
name,parent):TSegmentTimingContext
Defined in: debug/segment-timer.ts:274
Internal method to start a child segment
Parameters
name
string
parent
Returns
startSegment()
startSegment(
name):TSegmentTimingContext
Defined in: debug/segment-timer.ts:226
Start timing a root-level segment. Returns a context object that can be used to create child segments or end the timing.
Parameters
name
string
Name of this segment (e.g., "Update")
Returns
Timing context with methods to create children or end timing
Example
const updateSegment = segmentTimer.startSegment("Update");
// ... do work ...
const physicsSegment = updateSegment.startSegment("Physics");
// ... physics work ...
physicsSegment.end();
updateSegment.end();
updateAllCustomSegments()
updateAllCustomSegments(
maxUpdateRate?):void
Defined in: debug/segment-timer.ts:474
Update all custom segments with their current duration values. Call this once per frame in your engine's update loop for automatic updates.
Parameters
maxUpdateRate?
number = 60
Maximum updates per second (default: 60fps)
Returns
void
Example
// In your engine's main update loop
function gameLoop() {
// ... your game logic ...
// Update all custom segments automatically
segmentTimer.updateAllCustomSegments();
// ... rest of frame ...
requestAnimationFrame(gameLoop);
}
updateCustomSegment()
updateCustomSegment(
segment,duration):void
Defined in: debug/segment-timer.ts:347
Internal method to update a custom segment with a new duration value
Parameters
segment
TSegment
duration
number
Returns
void