Module: GrapeRailsLogger::Timings
- Defined in:
- lib/grape_rails_logger/timings.rb
Overview
Thread-safe storage for DB timing metrics per request
Class Method Summary collapse
- .append_db_runtime(event) ⇒ Object
- .db_calls ⇒ Object
- .db_runtime ⇒ Object
- .execution_state ⇒ Object
- .reset_db_runtime ⇒ Object
Class Method Details
.append_db_runtime(event) ⇒ Object
30 31 32 33 34 |
# File 'lib/grape_rails_logger/timings.rb', line 30 def self.append_db_runtime(event) state = execution_state state[:grape_db_runtime] = (state[:grape_db_runtime] || 0) + event.duration state[:grape_db_calls] = (state[:grape_db_calls] || 0) + 1 end |
.db_calls ⇒ Object
26 27 28 |
# File 'lib/grape_rails_logger/timings.rb', line 26 def self.db_calls execution_state[:grape_db_calls] ||= 0 end |
.db_runtime ⇒ Object
22 23 24 |
# File 'lib/grape_rails_logger/timings.rb', line 22 def self.db_runtime execution_state[:grape_db_runtime] ||= 0 end |
.execution_state ⇒ Object
7 8 9 |
# File 'lib/grape_rails_logger/timings.rb', line 7 def self.execution_state ActiveSupport::IsolatedExecutionState end |
.reset_db_runtime ⇒ Object
16 17 18 19 20 |
# File 'lib/grape_rails_logger/timings.rb', line 16 def self.reset_db_runtime state = execution_state state[:grape_db_runtime] = 0 state[:grape_db_calls] = 0 end |