Class: Groonga::QueryLog::Analyzer::Statistic

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/query-log/analyzer/statistic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_id) ⇒ Statistic

Returns a new instance of Statistic.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 28

def initialize(context_id)
  @context_id = context_id
  @start_time = nil
  @command = nil
  @raw_command = nil
  @operations = []
  @elapsed = nil
  @return_code = 0
  @slow_operation_threshold = 0.1
  @slow_response_threshold = 0.2
end

Instance Attribute Details

#context_idObject (readonly)

Returns the value of attribute context_id.



25
26
27
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 25

def context_id
  @context_id
end

#elapsedObject (readonly)

Returns the value of attribute elapsed.



26
27
28
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 26

def elapsed
  @elapsed
end

#raw_commandObject (readonly)

Returns the value of attribute raw_command.



25
26
27
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 25

def raw_command
  @raw_command
end

#return_codeObject (readonly)

Returns the value of attribute return_code.



26
27
28
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 26

def return_code
  @return_code
end

#slow_operation_thresholdObject

Returns the value of attribute slow_operation_threshold.



27
28
29
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 27

def slow_operation_threshold
  @slow_operation_threshold
end

#slow_response_thresholdObject

Returns the value of attribute slow_response_threshold.



27
28
29
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 27

def slow_response_threshold
  @slow_response_threshold
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



25
26
27
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 25

def start_time
  @start_time
end

Instance Method Details

#add_operation(operation) ⇒ Object



102
103
104
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 102

def add_operation(operation)
  @operations << operation
end

#commandObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 50

def command
  Groonga::Command::Parser.parse(@raw_command) do |status, command|
    case status
    when :on_load_start
      @loading = false
      @command ||= command
    when :on_command
      @command ||= command
    end
  end
  @command
end

#each_operationObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 75

def each_operation
  previous_elapsed = 0
  ensure_parse_command
  operation_context_context = {
    :filter_index => 0,
    :drilldown_index => 0,
  }
  @operations.each_with_index do |operation, i|
    relative_elapsed = operation[:elapsed] - previous_elapsed
    relative_elapsed_in_seconds = nano_seconds_to_seconds(relative_elapsed)
    previous_elapsed = operation[:elapsed]
    parsed_operation = {
      :i => i,
      :elapsed => operation[:elapsed],
      :elapsed_in_seconds => nano_seconds_to_seconds(operation[:elapsed]),
      :relative_elapsed => relative_elapsed,
      :relative_elapsed_in_seconds => relative_elapsed_in_seconds,
      :name => operation[:name],
      :context => operation_context(operation[:name],
                            operation_context_context),
      :n_records => operation[:n_records],
      :slow? => slow_operation?(relative_elapsed_in_seconds),
    }
    yield parsed_operation
  end
end

#elapsed_in_secondsObject



63
64
65
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 63

def elapsed_in_seconds
  nano_seconds_to_seconds(@elapsed)
end

#finish(elapsed, return_code) ⇒ Object



45
46
47
48
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 45

def finish(elapsed, return_code)
  @elapsed = elapsed
  @return_code = return_code
end

#last_timeObject



67
68
69
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 67

def last_time
  @start_time + elapsed_in_seconds
end

#operationsObject



106
107
108
109
110
111
112
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 106

def operations
  _operations = []
  each_operation do |operation|
    _operations << operation
  end
  _operations
end

#select_command?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 114

def select_command?
  command.name == "select"
end

#slow?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 71

def slow?
  elapsed_in_seconds >= @slow_response_threshold
end

#start(start_time, command) ⇒ Object



40
41
42
43
# File 'lib/groonga/query-log/analyzer/statistic.rb', line 40

def start(start_time, command)
  @start_time = start_time
  @raw_command = command
end