LogFileTracer
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
No description
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.
Close a span, opened by {self::openSpan()} before.
Creates a point-in-time marker AFTER an operation completes, within the current span.
No description
Details
__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.
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();
}
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.
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.
__destruct()
No description