{"id":19316055,"url":"https://github.com/socketry/memory","last_synced_at":"2025-04-22T16:33:10.455Z","repository":{"id":56883297,"uuid":"283535710","full_name":"socketry/memory","owner":"socketry","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-27T06:45:07.000Z","size":261,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-20T17:16:49.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/socketry.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-29T15:28:55.000Z","updated_at":"2024-09-19T18:14:27.000Z","dependencies_parsed_at":"2024-06-27T07:50:35.213Z","dependency_job_id":"d14fadef-cef7-4e64-9967-a8b3719d9e94","html_url":"https://github.com/socketry/memory","commit_stats":{"total_commits":179,"total_committers":25,"mean_commits":7.16,"dds":0.6592178770949721,"last_synced_commit":"bd16183df2a1a35b93a8cc2b9c1e0cf0af369bb2"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fmemory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fmemory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fmemory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/socketry%2Fmemory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/socketry","download_url":"https://codeload.github.com/socketry/memory/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250277434,"owners_count":21404047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T01:09:43.865Z","updated_at":"2025-04-22T16:33:10.209Z","avatar_url":"https://github.com/socketry.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memory\n\nA set of tools for profiling memory in Ruby.\n\n[![Development Status](https://github.com/socketry/memory/workflows/Test/badge.svg)](https://github.com/socketry/memory/actions?workflow=Test)\n\n## Features\n\n  - Fast memory capture for million+ allocations.\n  - Persist results to disk for vast aggregations and comparisons over time.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n``` shell\n$ bundle add 'memory'\n```\n\n## Usage\n\n``` ruby\nrequire 'memory'\n\nreport = Memory.report do\n\t# run your code here\nend\n\nreport.print\n```\n\nOr, you can use the `.start`/`.stop` methods as well:\n\n``` ruby\nrequire 'memory'\n\nsampler = Memory::Sampler.new\n\nsampler.start\n# run your code here\nsampler.stop\n\nreport = sampler.report\nreport.print\n```\n\n### RSpec Integration\n\n``` ruby\nmemory_sampler = nil\nconfig.before(:all) do |example_group|\n\tname = example_group.class.description.gsub(/[^\\w]+/, '-')\n\tpath = \"#{name}.mprof\"\n\n\tskip if File.exist?(path)\n\n\tmemory_sampler = Memory::Sampler.new\n\tmemory_sampler.start\nend\n\nconfig.after(:all) do |example_group|\n\tname = example_group.class.description.gsub(/[^\\w]+/, '-')\n\tpath = \"#{name}.mprof\"\n\n\tif memory_sampler\n\t\tmemory_sampler.stop\n\n\t\tFile.open(path, \"w\", encoding: Encoding::BINARY) do |io|\n\t\t\tmemory_sampler.dump(io)\n\t\tend\n\n\t\tmemory_sampler = nil\n\tend\nend\n\nconfig.after(:suite) do\n\tmemory_sampler = Memory::Sampler.new\n\n\tDir.glob('*.mprof') do |path|\n\t\t$stderr.puts \"Loading #{path}...\"\n\t\tmemory_sampler.load(File.read(path, encoding: Encoding::BINARY))\n\tend\n\n\t$stderr.puts \"Memory usage:\"\n\tmemory_sampler.report.print\nend\n```\n\n#### Raw Object Allocations\n\n``` ruby\nbefore = nil\n\nconfig.before(:suite) do |example|\n\t3.times{GC.start}\n\tGC.disable\n\tbefore = ObjectSpace.count_objects\nend\n\nconfig.after(:suite) do |example|\n\tafter = ObjectSpace.count_objects\n\tGC.enable\n\t\n\t$stderr.puts\n\t$stderr.puts \"Object Allocations:\"\n\t\n\tafter.each do |key, b|\n\t\ta = before.fetch(key, 0)\n\t\t$stderr.puts \"#{key}: #{a} -\u003e #{b} = #{b-a} allocations\"\n\tend\nend\n```\n\n## Contributing\n\nWe welcome contributions to this project.\n\n1.  Fork it.\n2.  Create your feature branch (`git checkout -b my-new-feature`).\n3.  Commit your changes (`git commit -am 'Add some feature'`).\n4.  Push to the branch (`git push origin my-new-feature`).\n5.  Create new Pull Request.\n\n### Developer Certificate of Origin\n\nThis project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.\n\n### Contributor Covenant\n\nThis project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketry%2Fmemory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketry%2Fmemory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketry%2Fmemory/lists"}