Class: Babeltrace::Context

Inherits:
FFI::ManagedStruct
  • Object
show all
Defined in:
lib/babeltrace/context.rb,
lib/babeltrace/format.rb,
lib/babeltrace/ctf/iterator.rb

Overview

< ManagedStruct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr = Babeltrace.bt_context_create) ⇒ Context

Returns a new instance of Context.



7
8
9
10
# File 'lib/babeltrace/context.rb', line 7

def initialize(ptr = Babeltrace.bt_context_create)
  super(ptr)
  @traces = []
end

Instance Attribute Details

#tracesObject (readonly)

Returns the value of attribute traces.



6
7
8
# File 'lib/babeltrace/context.rb', line 6

def traces
  @traces
end

Class Method Details

.release(ptr) ⇒ Object



12
13
14
# File 'lib/babeltrace/context.rb', line 12

def self.release(ptr)
  Babeltrace.bt_context_put(ptr)
end

Instance Method Details

#add_trace(path:, format: "ctf") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/babeltrace/context.rb', line 16

def add_trace(path:, format: "ctf")
  handle_id = Babeltrace.bt_context_add_trace(self, path, format, nil, nil, nil)
  case format
  when "ctf"
    trace = CTF::Trace::new(self, handle_id)
  else
    trace = Trace::new(self, handle_id)
  end
  @traces.push trace
  trace
end

#add_traces(path:, format: "ctf") ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/babeltrace/context.rb', line 28

def add_traces(path:, format: "ctf")
  traces = []
  Walk.walk(path) do |path, dirs, files|
    trace = add_trace(path: path, format: format) if files.include?("metadata")
    traces.push trace if trace
  end
  traces
end

#get_timestamp_begin(clock_type = :REAL) ⇒ Object



41
42
43
44
# File 'lib/babeltrace/context.rb', line 41

def get_timestamp_begin(clock_type = :REAL)
  return nil if traces.empty?
  traces.collect { |t| t.get_timestamp_begin(clock_type) }.min
end

#get_timestamp_end(clock_type = :REAL) ⇒ Object



46
47
48
49
# File 'lib/babeltrace/context.rb', line 46

def get_timestamp_end(clock_type = :REAL)
  return nil if traces.empty?
  traces.collect { |t| t.get_timestamp_end(clock_type) }.max
end

#iter_create(begin_pos: nil, end_pos: nil) ⇒ Object



3
4
5
# File 'lib/babeltrace/ctf/iterator.rb', line 3

def iter_create(begin_pos: nil, end_pos: nil)
  CTF.bt_ctf_iter_create(self, begin_pos, end_pos)
end

#iter_create_intersectObject



7
8
9
10
11
12
13
14
# File 'lib/babeltrace/ctf/iterator.rb', line 7

def iter_create_intersect
  begin_pos_ptr = FFI::MemoryPointer::new(:pointer)
  end_pos_ptr = FFI::MemoryPointer::new(:pointer)
  iter = CTF.bt_ctf_iter_create_intersect(@context, begin_pos_ptr, end_pos_ptr)
  begin_pos = IterPosManaged::new(begin_pos_ptr.read_pointer)
  end_pos = IterPosManaged::new(end_pos_ptr.read_pointer)
  [iter, begin_pos, end_pos]
end

#remove_trace(trace_id) ⇒ Object



37
38
39
# File 'lib/babeltrace/context.rb', line 37

def remove_trace(trace_id)
  Babeltrace.bt_context_remove_trace(self, trace_id)
end