Class: KMDB::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/kmdb/parser.rb

Defined Under Namespace

Classes: ProgressBar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kmdb/parser.rb', line 16

def initialize(options = {})
  @processed_bytes = nil
  @total_bytes = nil
  @exclude_regexps = []
  @include_regexps = []
  @filters = []
  @verbose        = options.delete(:verbose)
  @resume_job     = options.delete(:resume)
  @abort_on_error = options.delete(:abort_on_error)

  if @resume_job && @verbose && Dumpfile.count > 0
    log "Using restart information"
  end
end

Instance Attribute Details

#abort_on_errorObject (readonly)

Returns the value of attribute abort_on_error.



14
15
16
# File 'lib/kmdb/parser.rb', line 14

def abort_on_error
  @abort_on_error
end

#resume_jobObject (readonly)

Returns the value of attribute resume_job.



12
13
14
# File 'lib/kmdb/parser.rb', line 12

def resume_job
  @resume_job
end

#verboseObject (readonly)

Returns the value of attribute verbose.



13
14
15
# File 'lib/kmdb/parser.rb', line 13

def verbose
  @verbose
end

Instance Method Details

#add_filter(&block) ⇒ Object



41
42
43
44
# File 'lib/kmdb/parser.rb', line 41

def add_filter(&block)
  @filters << block
  self
end

#exclude(regexp) ⇒ Object



31
32
33
34
# File 'lib/kmdb/parser.rb', line 31

def exclude(regexp)
  @exclude_regexps << regexp
  self
end

#only(regexp) ⇒ Object



36
37
38
39
# File 'lib/kmdb/parser.rb', line 36

def only(regexp)
  @include_regexps << regexp
  self
end

#run(argv) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kmdb/parser.rb', line 46

def run(argv)
  inputs = list_files_in(argv)
  total_bytes = total_size_of_files(inputs)
  log "total bytes : #{total_bytes}"
  total_bytes -= inputs.map { |p| Dumpfile.get(p, @resume_job) }.compact.map(&:offset).sum
  log "left to process : #{total_bytes}"
  
  @processed_bytes = 0
  @progress = ProgressBar.new("-" * 20, total_bytes)
  @progress.long_running if @progress.respond_to?(:long_running)
  
  inputs.sort.each do |input|
    process_events_in_file(input)
  end

  @progress.finish
end