๐ฐ time_travel_debugger
Ultra-Pro time-travel debugging for Dart & Flutter.
Record every state change, then rewind step-by-step to inspect variable values at any point in your execution history.
โจ Features
| Feature | Description |
|---|---|
| ๐ด Live recording | Capture every variable mutation with sub-ms overhead |
| โช Time-travel | rewind(n), fastForward(n), jumpTo(step) |
| ๐ Bookmarks | Annotate key moments for instant navigation |
| ๐ด Conditional breakpoints | Fire on any predicate โ log, pause, throw, or rewind |
| ๐ Watchpoints | Pure observers for live analytics without stopping execution |
| ๐ DiffEngine | Visual diff between any two snapshots |
| ๐พ Session persistence | Save / reload .ttd session files |
| ๐ Reports | HTML, JSON, Markdown, Plain Text output |
| ๐ Delta compression | Deduplicate consecutive snapshots automatically |
| ๐ก Two-tier cache | Hot LRU cache + cold tier + optional disk overflow |
| ๐จ Flutter overlay | Draggable debug panel with timeline scrubber & variable inspector |
๐ฆ Installation
dependencies:
time_travel_debugger: ^1.0.0
dart pub get
๐ Quick Start
import 'package:time_travel_debugger/time_travel_debugger.dart';
void main() async {
final engine = TimeTravelEngine();
engine.startRecording();
// Option A โ explicit record()
int x = 0;
engine.record(name: 'x', oldValue: null, newValue: x,
file: 'main.dart', line: 8);
for (int i = 0; i < 100; i++) {
x = engine.track('x', x, x + i, 'main.dart', 12);
}
// Time-travel โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
final snap = engine.rewind(10); // 10 steps back
print(snap.variable('x')); // value 10 steps ago
final step0 = engine.jumpTo(0); // absolute step
print(step0.variableNames); // all vars at that moment
// Query โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
print(engine.firstChangeOf('x')); // step index
print(engine.allChangesOf('x').length); // total mutations
// Save โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
await engine.saveSession('/tmp/debug.ttd');
engine.dispose();
}
๐ฏ Core API
TimeTravelEngine
| Method | Description |
|---|---|
startRecording() |
Begin capturing mutations |
stopRecording() |
Stop (keeps history intact) |
pauseRecording() / resumeRecording() |
Temporarily suspend |
record({name, oldValue, newValue, file, line, ...}) |
Record a mutation |
track<T>(name, old, new, file, line) |
Record + return new (inline use) |
enterFunction({name, ...}) / exitFunction(...) |
Record function calls |
annotate(label) |
Insert a named bookmark |
rewind(n) |
Move cursor back n steps โ returns snapshot |
fastForward(n) |
Move cursor forward n steps |
jumpTo(step) |
Absolute jump |
currentSnapshot() |
Snapshot at cursor |
latestSnapshot() |
Most recent snapshot |
variablesAt(step) |
Map<String, dynamic> at step |
firstChangeOf(name) / lastChangeOf(name) |
Search step indices |
allChangesOf(name) |
All step indices for a variable |
historyOf(name) |
List<VariableRecord> in hot memory |
bookmarks() |
All annotated snapshots |
searchRecords(query) |
Full-text search in descriptions |
stats() |
PerformanceStats object |
saveSession([path]) / loadSession(path) |
Persist to disk |
clearHistory() |
Reset without stopping |
dispose() |
Release all resources |
StateSnapshot
snap.variable('x') // get value
snap.hasVariable('x') // bool
snap.variableNames // sorted List<String>
snap.filterVariables('pa') // filter by pattern
snap.diff(otherSnap) // Map<name, {before, after}>
snap.callStack // List<CallStackFrame>
snap.currentFunction // String? (innermost frame)
snap.withBookmark('label') // copies with bookmark
๐ด Breakpoints
final bp = BreakpointManager();
bp.addVariableBreakpoint(
variableName: 'health',
condition: (newVal, oldVal) => (newVal as int) < 20,
description: 'health critical',
action: BreakpointAction.log, // or .pause / .throwException / .rewindAndReport
maxHitCount: 5,
);
bp.onBreakpointFired = (event) {
print('Breakpoint fired @ step ${event.step}: '
'${event.trigger.variableName} = ${event.trigger.newValue}');
};
// In your recording loop:
final rec = engine.historyOf('health').last;
bp.evaluateRecord(rec, engine.currentPosition);
๐ Watchpoints
final wm = WatchpointManager();
wm.add(
variableName: 'score',
callback: (r) => analyticsService.track(r.newValue),
filter: (nv, ov) => (nv as int) > (ov as int? ?? 0),
);
// After every record():
wm.notify(engine.historyOf('score').last);
๐ DiffEngine
const diff = DiffEngine();
final before = engine.jumpTo(0);
final after = engine.latestSnapshot();
final result = diff.diff(after, before);
print(result.modified); // List<DiffEntry>
print(result.added);
print(result.toText()); // pretty multi-line string
๐ Reports
final gen = ReportGenerator(
metadata: engine.sessionMetadata,
snapshots: [],
records: engine.historyOf('counter'),
stats: engine.stats(),
);
// HTML (dark-mode, table-based)
await gen.saveReport('report.html', format: ReportFormat.html);
// Markdown
await gen.saveReport('report.md', format: ReportFormat.markdown);
// JSON
final json = gen.generate(format: ReportFormat.json);
// Plain text
print(gen.generate(format: ReportFormat.plainText));
๐จ Flutter Overlay
void main() {
final engine = TimeTravelEngine();
engine.startRecording();
runApp(
TimeTravelWidget(
engine: engine,
child: MyApp(),
),
);
}
The overlay adds a draggable panel with:
- Timeline scrubber (slider + nav buttons + quick-jump field)
- Bookmark strip for instant navigation
- Variables tab (searchable, type-annotated, click-to-copy)
- Call stack tab
- Changes tab (mutations that produced this snapshot)
Open the full variable history with:
Navigator.push(context, MaterialPageRoute(
builder: (_) => VariableInspector(
engine: engine,
variableName: 'counter',
),
));
โ๏ธ Configuration
TimeTravelEngine(
config: TimeTravelConfig(
maxHotRecords: 50000, // records in RAM
maxTimelineSnapshots: 20000, // snapshots in RAM
autoCompressInterval: Duration(seconds: 60), // null = disabled
autoSaveInterval: Duration(minutes: 5),
defaultSessionPath: '/tmp/app.ttd',
appName: 'MyApp',
appVersion: '2.0.0',
),
)
๐ Package Structure
lib/
โโโ time_travel_debugger.dart # Public API (single import)
โโโ src/
โโโ core/
โ โโโ time_travel_engine.dart โ Main public class
โ โโโ state_snapshot.dart โ Immutable state capture
โ โโโ memory_recorder.dart โ Hot record store + index
โ โโโ execution_timeline.dart โ Ordered event + snapshot log
โโโ models/
โ โโโ variable_record.dart โ Single mutation event
โ โโโ call_stack_frame.dart โ Call-stack frame
โ โโโ breakpoint_info.dart โ Breakpoint descriptor
โ โโโ timeline_event.dart โ Typed timeline entry
โ โโโ performance_stats.dart โ Runtime metrics
โ โโโ session_metadata.dart โ Session header
โโโ storage/
โ โโโ history_storage.dart โ Multi-strategy warm cache
โ โโโ memory_cache.dart โ Two-tier LRU cache
โ โโโ disk_persistence.dart โ .ttd file I/O
โโโ debugger/
โ โโโ breakpoint_manager.dart โ Conditional breakpoints
โ โโโ watchpoint_manager.dart โ Pure-observer watchpoints
โ โโโ diff_engine.dart โ Snapshot diffs
โ โโโ report_generator.dart โ HTML/JSON/MD/text reports
โโโ ui/ โ Flutter widgets
โ โโโ time_travel_widget.dart โ Root overlay wrapper
โ โโโ snapshot_viewer.dart โ Variables/Stack/Changes tabs
โ โโโ timeline_ui.dart โ Scrubber + bookmarks
โ โโโ variable_inspector.dart โ Full variable history page
โโโ utils/
โโโ serialization.dart โ JSON helpers
โโโ compression.dart โ Delta + gzip + RLE
โโโ ttd_logger.dart โ Internal logger
โโโ type_inspector.dart โ Runtime type display
๐ Performance Notes
- Recording path:
record()does โ1โ3 ยตs average (rolling 1 000-call window). - Eviction: When
maxHotRecordsis reached, oldest records are evicted via theonEvicthook โ plug in your DiskPersistence there. - Compression: Call
engine.timeline.compress()or rely on theautoCompressIntervalto deduplicate consecutive identical snapshots. - Flutter overlay: rendered only in debug builds unless
showInRelease: true.
๐ License
MIT ยฉ 2026 TIMSoftDZ
Libraries
- time_travel_debugger
- Time Travel Debugger