Module: RailsMemoryProfiler::ReportStore
- Defined in:
- lib/rails_memory_profiler/report_store.rb
Overview
Thread-safe circular buffer that holds per-request profiling reports. Capacity is controlled by Configuration#store_size. When full, the oldest report is evicted to make room for each new one.
Each report is a Hash with the keys:
-
:id— unique hex string assigned on push -
:path,:method,:controller,:action -
:allocated_objects,:retained_objects -
:duration_ms -
:recorded_at—Timeof capture -
:detail— optional breakdown Hash (present when Configuration#detailed_reports is enabled)
Class Method Summary collapse
-
.all ⇒ Array<Hash>
Returns all stored reports in insertion order (oldest first).
-
.clear ⇒ void
Removes all stored reports.
-
.find(id) ⇒ Hash?
Returns the report with the given id, or
nilif not found or evicted. -
.push(report) ⇒ void
Adds a report to the buffer, assigning a unique
:idkey. -
.size ⇒ Integer
Returns the number of reports currently stored.
Class Method Details
.all ⇒ Array<Hash>
Returns all stored reports in insertion order (oldest first).
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_memory_profiler/report_store.rb', line 43 def all mutex.synchronize do stored = @stored || 0 return [] if stored.zero? if stored < capacity buffer.first(stored) else buffer[@write_pos..] + buffer[0...@write_pos] end end end |
.clear ⇒ void
This method returns an undefined value.
Removes all stored reports.
59 60 61 |
# File 'lib/rails_memory_profiler/report_store.rb', line 59 def clear mutex.synchronize { reset! } end |
.find(id) ⇒ Hash?
Returns the report with the given id, or nil if not found or evicted.
36 37 38 |
# File 'lib/rails_memory_profiler/report_store.rb', line 36 def find(id) all.find { |r| r[:id] == id } end |
.push(report) ⇒ void
This method returns an undefined value.
Adds a report to the buffer, assigning a unique :id key. Evicts the oldest entry when the buffer is at capacity.
23 24 25 26 27 28 29 30 |
# File 'lib/rails_memory_profiler/report_store.rb', line 23 def push(report) mutex.synchronize do ensure_buffer_size buffer[@write_pos] = report.merge(id: SecureRandom.hex(6)) @write_pos = (@write_pos + 1) % capacity @stored = [@stored + 1, capacity].min end end |
.size ⇒ Integer
Returns the number of reports currently stored.
66 67 68 |
# File 'lib/rails_memory_profiler/report_store.rb', line 66 def size mutex.synchronize { @stored || 0 } end |