Module: Memory
- Defined in:
- lib/memory/cache.rb,
lib/memory.rb,
lib/memory/deque.rb,
lib/memory/report.rb,
lib/memory/sampler.rb,
lib/memory/version.rb,
lib/memory/aggregate.rb,
lib/memory/rspec/profiler.rb
Overview
Released under the MIT License. Copyright, 2020-2023, by Samuel Williams.
Defined Under Namespace
Modules: RSpec
Classes: Aggregate, Allocation, Cache, Deque, Report, Sampler, ValueAggregate, Wrapper
Constant Summary
collapse
- VERSION =
"0.4.2"
- UNITS =
{
0 => 'B',
3 => 'KiB',
6 => 'MiB',
9 => 'GiB',
12 => 'TiB',
15 => 'PiB',
18 => 'EiB',
21 => 'ZiB',
24 => 'YiB'
}.freeze
Class Method Summary
collapse
Class Method Details
.capture(report = nil, &block) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/memory.rb', line 16
def self.capture(report = nil, &block)
sampler = Sampler.new
sampler.run(&block)
report ||= Report.general
report.add(sampler)
return report
end
|
19
20
21
22
23
24
25
|
# File 'lib/memory/aggregate.rb', line 19
def self.formatted_bytes(bytes)
return "0 B" if bytes.zero?
scale = Math.log2(bytes).div(10) * 3
scale = 24 if scale > 24
"%.2f #{UNITS[scale]}" % (bytes / 10.0**scale)
end
|
.report(&block) ⇒ Object
26
27
28
|
# File 'lib/memory.rb', line 26
def self.report(&block)
self.capture(&block)
end
|