Class: WasTracer::TraceLine

Inherits:
Object
  • Object
show all
Defined in:
lib/was_tracer/trace_line.rb

Constant Summary collapse

BASE_YEAR =
2000
PARSE_REGEX =
/
    \[(\d{1,2})\/(\d{1,2})\/(\d{2})\s # dd-mm-yy 1, 2, 3
    (\d{1,2}):(\d{1,2}):(\d{1,2}):(\d{3})\s # hh-mm-ss-uuu 4, 5, 6, 7
    \w{3}\]\s*
    ([\w]{8})\s* # threadid 8
    ([^\s]*)\s* # traceid 9
    (.)\s* # kind 10
    (.*)$ # data 11
/x
METHOD_REGEX =
/
  ([^\s\(]*)\s* # class name 1
  (.*)\s* # method name 2
  (ENTRY|RETURN)\s*
  (.*)$ # params 4
/x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_data, line, line_number) ⇒ TraceLine

Returns a new instance of TraceLine.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/was_tracer/trace_line.rb', line 28

def initialize(file_data, line, line_number)
  @time = Time.mktime(BASE_YEAR + file_data[2].to_i, file_data[0], file_data[1], 
                  file_data[3], file_data[4], file_data[5], file_data[6].to_i * 1000)
  @time_str = "#{file_data[3]}:#{file_data[4]}:#{file_data[5]}:#{file_data[6]}"
  @thread_id = file_data[7]
  @trace_name = file_data[8]
  @kind = file_data[9]
  @data = file_data[10]
  @line = line
  @line_number = line_number
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def data
  @data
end

#kindObject

Returns the value of attribute kind.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def kind
  @kind
end

#lineObject

Returns the value of attribute line.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def line
  @line
end

#line_numberObject

Returns the value of attribute line_number.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def line_number
  @line_number
end

#thread_idObject

Returns the value of attribute thread_id.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def thread_id
  @thread_id
end

#timeObject

Returns the value of attribute time.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def time
  @time
end

#time_strObject

Returns the value of attribute time_str.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def time_str
  @time_str
end

#trace_nameObject

Returns the value of attribute trace_name.



26
27
28
# File 'lib/was_tracer/trace_line.rb', line 26

def trace_name
  @trace_name
end

Class Method Details

.from_line(line, line_number) ⇒ Object



21
22
23
24
# File 'lib/was_tracer/trace_line.rb', line 21

def self.from_line(line, line_number)
  match_group = line.chomp.match PARSE_REGEX
  TraceLine.new(match_group.captures, line, line_number) if match_group
end

Instance Method Details

#entering?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/was_tracer/trace_line.rb', line 65

def entering?
  @kind == '>'
end

#exiting?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/was_tracer/trace_line.rb', line 69

def exiting?
  @kind == '<'
end

#method_nameObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/was_tracer/trace_line.rb', line 40

def method_name
  return @data unless entering? or exiting?
  return @method_name if @method_name
  m = @data.match METHOD_REGEX
  @method_params = m[4]
  if m[2] =~ /^\(/
    @method_name = "#{m[1]}()"
  else
    @method_name = "#{m[1]}.#{m[2]}()"
  end
end

#method_paramsObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/was_tracer/trace_line.rb', line 52

def method_params
  return '' unless entering? or exiting?
  return @method_params if @method_params
  m = @data.match METHOD_REGEX
  if m[2] =~ /^\(/
    @method_name = "#{m[1]}()"
  else
    @method_name = "#{m[1]}.#{m[2]}()"
  end
  @method_params = m[4]
end