final class LogFileTracer implements PerformanceTracerInterface (View source)

internal  
 

Simple file-based tracer that writes human-readable trace logs incrementally.

Format: [timestamp] indentation name (duration)

  • Spans use > (start) and < (end) with duration
  • Marks use • with time since last mark
  • Indentation shows nesting depth
  • fflush() after each write ensures crash-safety

Example: [123.456] > handleCommand {"cmd":"CreateNode"} [123.457] • validation (+1.2 ms) [123.459] < handleCommand (3.0 ms)

Methods

__construct(string $logFilePath, float $minimumMarkDurationMs)

No description

void
openSpan(string $name, array $params = [])

Creates a named span that traces the execution until the corresponding {self::closeSpan()} is called. {self::openSpan()} and {self::closeSpan()} always need to be called in pairs.

void
closeSpan()

Close a span, opened by {self::openSpan()} before.

void
mark(string $name, array $params = [])

Creates a point-in-time marker AFTER an operation completes, within the current span.

__destruct()

No description

Details

__construct(string $logFilePath, float $minimumMarkDurationMs)

No description

Parameters

string $logFilePath
float $minimumMarkDurationMs

void openSpan(string $name, array $params = [])

Creates a named span that traces the execution until the corresponding {self::closeSpan()} is called. {self::openSpan()} and {self::closeSpan()} always need to be called in pairs.

A span represents a unit of work with a defined beginning and end. Any mark() calls made during the closure execution are automatically associated with this span. Spans can be nested, allowing for hierarchical performance analysis.

Suggested pattern:

 $this->performanceTracer?->openSpan('foo');
 try {
     // doFoo -> your code here
     $this->performanceTracer?->mark('doFoo')
     // doBar -> your code here
     $this->performanceTracer?->mark('doBar')
 } finally {
     $this->performanceTracer?->closeSpan();
 }

Parameters

string $name

A descriptive name for this span (e.g., "contentRepository::handle")

array $params

attributes to attach to the span (e.g., ['c' => 'CreateNode'])

Return Value

void

void closeSpan()

Close a span, opened by {self::openSpan()} before.

Return Value

void

void mark(string $name, array $params = [])

Creates a point-in-time marker AFTER an operation completes, within the current span.

Markers measure the elapsed time from the previous mark (or span start) up to and including the operation just completed. Place mark() calls immediately AFTER the operation you want to measure.

Parameters

string $name

A descriptive name identifying the operation that just completed

array $params

attributes to attach to the span (e.g., ['c' => 'CreateNode'])

Return Value

void

__destruct()

No description