babeltrace_ze.in 1.28 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1
#!/usr/bin/env ruby
Brice Videau's avatar
Brice Videau committed
2
3
DATADIR = File.join("@prefix@", "share")
$:.unshift(DATADIR) if File::directory?(DATADIR)
4
require 'optparse'
Brice Videau's avatar
Brice Videau committed
5
6
7
8
require 'babeltrace'
require 'babeltrace/ctf'
require 'yaml'
require 'pp'
Brice Videau's avatar
Brice Videau committed
9
require 'babeltrace_ze_lib'
Brice Videau's avatar
Brice Videau committed
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$options = {
  context: false
}

OptionParser.new do |opts|
  opts.banner = "Usage: babeltrace_ze [OPTIONS] target_trace_directory"

  opts.on("-c", "--[no-]context", "Add context information") do |context|
    $options[:context] = context
  end

  opts.on("-h", "--help", "Prints this help") do
    puts opts
    exit
  end

end.parse!

Brice Videau's avatar
Brice Videau committed
29
30
31
32
33
c = Babeltrace::Context::new
traces = c.add_traces(path: ARGV[0])

puts "#{c.get_timestamp_begin.strftime("%Y-%m-%d %H:%M:%S.%9L %z")} -- #{c.get_timestamp_end.strftime("%Y-%m-%d %H:%M:%S.%9L %z")}"

Brice Videau's avatar
Brice Videau committed
34
35
36
37
38
events = {}
traces.each { |t|
  events[t.handle_id] = t.get_event_decl_list.collect(&:name)
}

Brice Videau's avatar
Brice Videau committed
39
40
it = c.iter_create
it.each { |ev|
Brice Videau's avatar
Brice Videau committed
41
  name = events[ev.handle_id][ev.id]
42
43
44
  str = "#{ev.timestamp.strftime("%H:%M:%S.%9L")}"
  str << " - " << ev.top_level_scope(:STREAM_EVENT_CONTEXT).value.collect { |k, v| "#{k}: #{v}" }.join(", ") if $options[:context]
  str << " - #{name}: "
Brice Videau's avatar
Brice Videau committed
45
  defi = ev.top_level_scope(:EVENT_FIELDS)
Brice Videau's avatar
Brice Videau committed
46
47
  l = $event_lambdas[name]
  if l
48
    str << l.call(defi.value).to_s
Brice Videau's avatar
Brice Videau committed
49
  else
50
    str << defi.value.to_s
Brice Videau's avatar
Brice Videau committed
51
  end
52
  puts str
Brice Videau's avatar
Brice Videau committed
53
54
}