Class: GroongaQueryLog::Statistic
- Inherits:
-
Object
- Object
- GroongaQueryLog::Statistic
- Defined in:
- lib/groonga-query-log/statistic.rb
Constant Summary collapse
- DEFAULT_SLOW_OPERATION_THRESHOLD =
0.1
- DEFAULT_SLOW_RESPONSE_THRESHOLD =
0.2
Instance Attribute Summary collapse
-
#context_id ⇒ Object
readonly
Returns the value of attribute context_id.
-
#elapsed ⇒ Object
readonly
Returns the value of attribute elapsed.
-
#raw_command ⇒ Object
readonly
Returns the value of attribute raw_command.
-
#return_code ⇒ Object
readonly
Returns the value of attribute return_code.
-
#slow_operation_threshold ⇒ Object
Returns the value of attribute slow_operation_threshold.
-
#slow_response_threshold ⇒ Object
Returns the value of attribute slow_response_threshold.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #add_operation(operation) ⇒ Object
- #cache_used? ⇒ Boolean
- #command ⇒ Object
- #each_operation ⇒ Object
- #elapsed_in_seconds ⇒ Object
- #finish(elapsed, return_code) ⇒ Object
-
#initialize(context_id) ⇒ Statistic
constructor
A new instance of Statistic.
- #last_time ⇒ Object
- #operations ⇒ Object
- #select_family_command? ⇒ Boolean
- #slow? ⇒ Boolean
- #start(start_time, command) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(context_id) ⇒ Statistic
Returns a new instance of Statistic.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/groonga-query-log/statistic.rb', line 27 def initialize(context_id) @context_id = context_id @start_time = nil @raw_command = nil @operations = [] @elapsed = nil @return_code = 0 @slow_operation_threshold = DEFAULT_SLOW_OPERATION_THRESHOLD @slow_response_threshold = DEFAULT_SLOW_RESPONSE_THRESHOLD end |
Instance Attribute Details
#context_id ⇒ Object (readonly)
Returns the value of attribute context_id.
24 25 26 |
# File 'lib/groonga-query-log/statistic.rb', line 24 def context_id @context_id end |
#elapsed ⇒ Object (readonly)
Returns the value of attribute elapsed.
25 26 27 |
# File 'lib/groonga-query-log/statistic.rb', line 25 def elapsed @elapsed end |
#raw_command ⇒ Object (readonly)
Returns the value of attribute raw_command.
24 25 26 |
# File 'lib/groonga-query-log/statistic.rb', line 24 def raw_command @raw_command end |
#return_code ⇒ Object (readonly)
Returns the value of attribute return_code.
25 26 27 |
# File 'lib/groonga-query-log/statistic.rb', line 25 def return_code @return_code end |
#slow_operation_threshold ⇒ Object
Returns the value of attribute slow_operation_threshold.
26 27 28 |
# File 'lib/groonga-query-log/statistic.rb', line 26 def slow_operation_threshold @slow_operation_threshold end |
#slow_response_threshold ⇒ Object
Returns the value of attribute slow_response_threshold.
26 27 28 |
# File 'lib/groonga-query-log/statistic.rb', line 26 def slow_response_threshold @slow_response_threshold end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
24 25 26 |
# File 'lib/groonga-query-log/statistic.rb', line 24 def start_time @start_time end |
Instance Method Details
#add_operation(operation) ⇒ Object
100 101 102 |
# File 'lib/groonga-query-log/statistic.rb', line 100 def add_operation(operation) @operations << operation end |
#cache_used? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/groonga-query-log/statistic.rb', line 64 def cache_used? each_operation.any? do |operation| operation[:name] == "cache" end end |
#command ⇒ Object
48 49 50 |
# File 'lib/groonga-query-log/statistic.rb', line 48 def command @command ||= parse_command end |
#each_operation ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/groonga-query-log/statistic.rb', line 70 def each_operation return to_enum(__method__) unless block_given? previous_elapsed = 0 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, operation_context_context), :n_records => operation[:n_records], :extra => operation[:extra], :slow? => slow_operation?(relative_elapsed_in_seconds), :raw_message => operation[:raw_message], } yield parsed_operation end end |
#elapsed_in_seconds ⇒ Object
52 53 54 |
# File 'lib/groonga-query-log/statistic.rb', line 52 def elapsed_in_seconds nano_seconds_to_seconds(@elapsed) end |
#finish(elapsed, return_code) ⇒ Object
43 44 45 46 |
# File 'lib/groonga-query-log/statistic.rb', line 43 def finish(elapsed, return_code) @elapsed = elapsed @return_code = return_code end |
#last_time ⇒ Object
56 57 58 |
# File 'lib/groonga-query-log/statistic.rb', line 56 def last_time @start_time + elapsed_in_seconds end |
#operations ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/groonga-query-log/statistic.rb', line 104 def operations _operations = [] each_operation do |operation| _operations << operation end _operations end |
#select_family_command? ⇒ Boolean
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/groonga-query-log/statistic.rb', line 112 def select_family_command? case command.command_name when "select", "range_filter" true when "logical_select", "logical_range_filter" true else false end end |
#slow? ⇒ Boolean
60 61 62 |
# File 'lib/groonga-query-log/statistic.rb', line 60 def slow? elapsed_in_seconds >= @slow_response_threshold end |
#start(start_time, command) ⇒ Object
38 39 40 41 |
# File 'lib/groonga-query-log/statistic.rb', line 38 def start(start_time, command) @start_time = start_time @raw_command = command end |
#to_hash ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/groonga-query-log/statistic.rb', line 123 def to_hash data = { "start_time" => start_time.to_f, "last_time" => last_time.to_f, "elapsed" => elapsed_in_seconds, "return_code" => return_code, "slow" => slow?, } if command data["command"] = { "raw" => raw_command, "name" => command.name, "parameters" => command_arguments, } else data["command"] = { "raw" => raw_command } end operations = [] each_operation do |operation| operation_data = {} operation_data["name"] = operation[:name] operation_data["relative_elapsed"] = operation[:relative_elapsed_in_seconds] operation_data["context"] = operation[:context] operation_data["slow"] = operation[:slow?] operations << operation_data end data["operations"] = operations data end |