Class: RailsAi::Performance::PerformanceMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai/performance.rb

Overview

Performance monitoring

Instance Method Summary collapse

Constructor Details

#initializePerformanceMonitor

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

#metricsObject



178
179
180
# File 'lib/rails_ai/performance.rb', line 178

def metrics
  @metrics.dup
end