Class: Vivarium::Correlator
- Inherits:
-
Object
- Object
- Vivarium::Correlator
- Defined in:
- lib/vivarium/correlator.rb
Overview
Client-side consumer of the vivariumd event stream. Connects to the daemon’s Unix domain socket, reads chunked raw event_t records, accumulates them, and renders a tree on stop. It never touches BPF maps or the ring buffer directly.
Defined Under Namespace
Classes: RawEvent
Constant Summary collapse
- DRAIN_SLEEP =
Grace period after stop to let trailing events drain through the stream.
0.3
Instance Method Summary collapse
-
#initialize(socket_path: Vivarium.socket_path, observer_pid:, main_tid:, filter: nil, dest: $stdout) ⇒ Correlator
constructor
A new instance of Correlator.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(socket_path: Vivarium.socket_path, observer_pid:, main_tid:, filter: nil, dest: $stdout) ⇒ Correlator
Returns a new instance of Correlator.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vivarium/correlator.rb', line 18 def initialize(socket_path: Vivarium.socket_path, observer_pid:, main_tid:, filter: nil, dest: $stdout) @socket_path = socket_path @observer_pid = observer_pid @main_tid = main_tid @filter = filter @dest = dest @client = DaemonClient.new(socket_path: socket_path) @events = [] @events_mutex = Mutex.new @stop_flag = false @started = false @stopped = false end |
Instance Method Details
#start ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/vivarium/correlator.rb', line 34 def start return if @started @session_start_iso = Time.now.utc.iso8601(3) @session_start_ktime = Vivarium.monotonic_ktime_ns @sock = @client.open_event_stream @thread = Thread.new { run } @started = true end |
#stop ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vivarium/correlator.rb', line 44 def stop return unless @started return if @stopped sleep DRAIN_SLEEP @stop_flag = true @sock&.close @thread&.join(2) @session_stop_iso = Time.now.utc.iso8601(3) @session_stop_ktime = Vivarium.monotonic_ktime_ns events_snapshot = @events_mutex.synchronize { @events.dup } @stopped = true TreeRenderer.new( events: events_snapshot, observer_pid: @observer_pid, main_tid: @main_tid, session_start_iso: @session_start_iso, session_start_ktime: @session_start_ktime, session_stop_iso: @session_stop_iso, session_stop_ktime: @session_stop_ktime, filter: @filter, dest: @dest ).render end |