Class: RailsAi::Performance::PerformanceMonitor
- Inherits:
-
Object
- Object
- RailsAi::Performance::PerformanceMonitor
- Defined in:
- lib/rails_ai/performance.rb
Overview
Performance monitoring
Instance Method Summary collapse
-
#initialize ⇒ PerformanceMonitor
constructor
A new instance of PerformanceMonitor.
- #measure(operation, &block) ⇒ Object
- #metrics ⇒ Object
Constructor Details
#initialize ⇒ PerformanceMonitor
Returns a new instance of PerformanceMonitor.
161 162 163 |
# File 'lib/rails_ai/performance.rb', line 161 def initialize @metrics = Concurrent::Hash.new end |
Instance Method Details
#measure(operation, &block) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rails_ai/performance.rb', line 165 def measure(operation, &block) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) memory_before = memory_usage result = block.call duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time memory_after = memory_usage record_metric(operation, duration, memory_after - memory_before) result end |
#metrics ⇒ Object
178 179 180 |
# File 'lib/rails_ai/performance.rb', line 178 def metrics @metrics.dup end |