summaryrefslogtreecommitdiff
path: root/internal/runtime_builder.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-12 22:36:11 +0300
committerPaul Buetow <paul@buetow.org>2026-05-12 22:36:11 +0300
commita2c067cc49b96968da81031275de9c44c4ba2ee9 (patch)
tree84d0507274599cf3cad0daa9b1be613549b74304 /internal/runtime_builder.go
parent235eb7541d6396e860b23aad63ed44c734cdf767 (diff)
introduce RuntimeBuilder to separate construction from orchestration in ior.go
RuntimeBuilder encapsulates allocation of per-trace-session components (statsengine.Engine, streamrow.RingBuffer, Sequencer, flamegraph.LiveTrie); buildTUIRuntime, buildTestFlamesRuntime, and buildTestLiveFlamesRuntime now delegate construction to RuntimeBuilder.Build() and focus only on wiring. wireRuntimeBindings is extracted to isolate the context-binding wiring step. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/runtime_builder.go')
-rw-r--r--internal/runtime_builder.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/runtime_builder.go b/internal/runtime_builder.go
new file mode 100644
index 0000000..bc1c228
--- /dev/null
+++ b/internal/runtime_builder.go
@@ -0,0 +1,49 @@
+package internal
+
+import (
+ "ior/internal/flags"
+ "ior/internal/flamegraph"
+ "ior/internal/statsengine"
+ "ior/internal/streamrow"
+)
+
+const defaultEngineCapacity = 64
+
+// runtimeComponents holds the freshly allocated trace-session components
+// produced by RuntimeBuilder.Build. All fields are non-nil after a successful
+// build. The caller is responsible for wiring these into the runtime bindings
+// and event-loop callbacks.
+type runtimeComponents struct {
+ engine *statsengine.Engine
+ streamBuf *streamrow.RingBuffer
+ streamSeq *streamrow.Sequencer
+ liveTrie *flamegraph.LiveTrie
+}
+
+// RuntimeBuilder encapsulates the allocation of per-trace-session runtime
+// components. Construct one with newRuntimeBuilder, then call Build to
+// produce a fresh runtimeComponents struct ready for wiring.
+type RuntimeBuilder struct {
+ // cfg holds the configuration used to size and configure the components.
+ cfg flags.Config
+}
+
+// newRuntimeBuilder creates a RuntimeBuilder configured from cfg.
+// The builder captures cfg at construction time; later cfg changes do not affect
+// a builder already created.
+func newRuntimeBuilder(cfg flags.Config) RuntimeBuilder {
+ return RuntimeBuilder{cfg: cfg}
+}
+
+// Build allocates a fresh set of runtime components for one trace session.
+// It creates a new stats engine, stream ring buffer, sequencer, and live trie
+// each time it is called; callers must not share the returned components across
+// concurrent trace sessions.
+func (b RuntimeBuilder) Build() runtimeComponents {
+ return runtimeComponents{
+ engine: statsengine.NewEngine(defaultEngineCapacity),
+ streamBuf: streamrow.NewRingBuffer(),
+ streamSeq: streamrow.NewSequencer(0),
+ liveTrie: flamegraph.NewLiveTrie(b.cfg.CollapsedFields, b.cfg.CountField),
+ }
+}