Class: Vivarium::TreeRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/vivarium/tree_renderer.rb

Defined Under Namespace

Classes: EventNode, ProcNode, Span

Constant Summary collapse

SPAN_EVENT_NAMES =
%w[span_start span_stop].to_set.freeze
FORK_EVENT_NAME =
"proc_fork"
EXEC_EVENT_NAME =
"proc_exec"
SSL_WRITE_EVENT_NAME =
"ssl_write"
LSM_EVENT_NAMES =
%w[
  path_open sock_connect odd_socket
  ptrace_check sb_mount kernel_read_file task_kill
  setid_change capable_check bprm_creds
  file_symlink file_hardlink file_rename file_chmod
].to_set.freeze
TP_EVENT_NAMES =
%w[
  dns_req proc_exec file_getdents proc_fork
].to_set.freeze
UPROBE_EVENT_NAMES =
%w[ssl_write].to_set.freeze
SYNTHETIC_SPAN_NAME =
"<no-span>"
UNRESOLVED_METHOD_PREFIX =
"<method_id="

Instance Method Summary collapse

Constructor Details

#initialize(events:, method_table:, observer_pid:, main_tid:, session_start_iso:, session_start_ktime:, session_stop_iso:, session_stop_ktime:, filter: nil, dest:) ⇒ TreeRenderer

Returns a new instance of TreeRenderer.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vivarium/tree_renderer.rb', line 54

def initialize(events:, method_table:, observer_pid:, main_tid:,
               session_start_iso:, session_start_ktime:,
               session_stop_iso:, session_stop_ktime:, filter: nil, dest:)
  @events = events
  @method_table = method_table
  @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
  @display_filter = Vivarium::DisplayFilter.compile(filter)
  @dest = dest

  @pid_comm = { observer_pid => "ruby" }
  @pid_parent = {}
  @unresolved_method_ids = []
end

Instance Method Details

#renderObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/vivarium/tree_renderer.rb', line 73

def render
  sorted = @events.sort_by { |e| [e.ktime_ns, e.pid, e.tid] }

  real_spans, @children_map = build_real_spans(sorted)
  @child_span_set = @children_map.values.flatten.to_set

  assign_descendants(real_spans, sorted)

  root_real_spans = real_spans.reject { |s| @child_span_set.include?(s) }
  root_with_synthetics = interleave_synthetic_spans(root_real_spans)

  synthetic_spans = root_with_synthetics.select(&:synthetic)
  all_spans_for_assign = (synthetic_spans + real_spans).sort_by { |s| s.start_ktime || 0 }
  assign_events_to_spans(all_spans_for_assign, sorted)

  print_header
  print_warnings
  print_observer_proc(root_with_synthetics)
end