A set of tools for profiling memory in Ruby.
- Fast memory capture for million+ allocations.
- Persist results to disk for vast aggregations and comparisons over time.
Add this line to your application's Gemfile:
$ bundle add 'memory'Please see the project documentation for more details.
- Getting Started - This guide explains how to get started with
memory, a Ruby gem for profiling memory allocations in your applications.
memory_sampler = nil
config.before(:all) do |example_group|
name = example_group.class.description.gsub(/[^\w]+/, "-")
path = "#{name}.mprof"
skip if File.exist?(path)
memory_sampler = Memory::Sampler.new
memory_sampler.start
end
config.after(:all) do |example_group|
name = example_group.class.description.gsub(/[^\w]+/, "-")
path = "#{name}.mprof"
if memory_sampler
memory_sampler.stop
File.open(path, "w", encoding: Encoding::BINARY) do |io|
memory_sampler.dump(io)
end
memory_sampler = nil
end
end
config.after(:suite) do
memory_sampler = Memory::Sampler.new
Dir.glob("*.mprof") do |path|
$stderr.puts "Loading #{path}..."
memory_sampler.load(File.read(path, encoding: Encoding::BINARY))
end
$stderr.puts "Memory usage:"
memory_sampler.report.print
endbefore = nil
config.before(:suite) do |example|
3.times{GC.start}
GC.disable
before = ObjectSpace.count_objects
end
config.after(:suite) do |example|
after = ObjectSpace.count_objects
GC.enable
$stderr.puts
$stderr.puts "Object Allocations:"
after.each do |key, b|
a = before.fetch(key, 0)
$stderr.puts "#{key}: #{a} -> #{b} = #{b-a} allocations"
end
endPlease see the project releases for all releases.
- Compresed
Memory::Graph::NodeJSON representation for leaf nodes.
- Remove support for
Memory::Usage.of(..., via:)and instead useMemory::Graph.forwhich collects more detailed usage until the specified depth, at which point it delgates toMemory::Usage.of. This should be more practical.
- Add support for
Memory::Usage.of(..., via:)for tracking reachability of objects. - Introduce
Memory::Graphfor computing paths between parent/child objects.
- Explicit
ignore:andseen:parameters forMemory::Usage.ofto allow customization of ignored types and tracking of seen objects.
- Fix bugs when printing reports due to interface mismatch with
Memory::Usage.
- Handle
Memory::Usage.of(number)without error.
- Fix several formatting issues.
- Skip over
ObjectSpace::InternalObjectWrapperinstances inMemory::Usage.ofto avoid unbounded recursion.
- Removed old
RSpecintegration. - Introduced
Memory::UsageandMemory::Usage.of(object)which recursively computes memory usage of an object and its contents.
- Ensure aggregate keys are safe for serialization (and printing).
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin my-new-feature). - Create new Pull Request.
In order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.