File: heap_inspect_spec.rb

package info (click to toggle)
ruby-heapy 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 97,184 kB
  • sloc: ruby: 394; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 2,236 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe Heapy do
  it 'has a version number' do
    expect(Heapy::VERSION).not_to be nil
  end

  describe "heap diffs" do
    it "diffs 2 heaps" do
      out = run("#{RbConfig.ruby} bin/heapy diff #{fixtures('dumps/diff/my_dump_1.json')} #{fixtures('dumps/diff/my_dump_2.json')}")
      expect(out).to match("Allocated STRING 9991 objects")
    end

    it "diffs 3 heaps" do
      out = run("#{RbConfig.ruby} bin/heapy diff #{fixtures('dumps/diff/my_dump_1.json')} #{fixtures('dumps/diff/my_dump_2.json')} #{fixtures('dumps/diff/my_dump_3.json')}")

      expect(out).to match("Retained STRING 9991 objects")
    end

    it "outputs the diff" do
      Dir.mktmpdir do |tmp_dir|
        file = "#{tmp_dir}/output.dump"
        run("#{RbConfig.ruby} bin/heapy diff #{fixtures('dumps/diff/my_dump_1.json')} #{fixtures('dumps/diff/my_dump_2.json')} --output_diff=#{file}")

        expect(`cat #{file} | wc -l`).to match("10006")
      end
    end
  end

  it "drills down all" do
    out = run("#{RbConfig.ruby} bin/heapy read #{ fixtures('dumps/00-heap.dump') } all")
    expect(out).to match("4325616  /Users/richardschneeman/.gem/ruby/2.2.3/gems/activesupport-4.2.3/lib/active_support/core_ext/marshal.rb:6")
  end

  it "drills down" do
    out = run("#{RbConfig.ruby} bin/heapy read #{ fixtures('dumps/00-heap.dump') } 36")

    # memory count
    expect(out).to match("377065  /Users/richardschneeman/Documents/projects/codetriage/app/views/layouts/application.html.slim:1")

    # string counts
    expect(out).to match("4  \"application\"")

    # ref counts
    expect(out).to match("1672  /Users/richardschneeman/.gem/ruby/2.2.3/gems/activerecord-4.2.3/lib/active_record/attribute.rb:5")
  end

  context 'with no generation specified' do
    let(:cmd) { "#{RbConfig.ruby} bin/heapy read #{ fixtures('dumps/00-heap.dump') }" }
    it 'analyzes' do
      out = run(cmd)
      expect(out).to match("Generation: nil object count: 209189")
    end

    it "summarizes" do
      out = run(cmd)
      expect(out).to include("Heap total")
      expect(out).to include("Generations (active): 5")
      expect(out).to include("Count: 278443")
      expect(out).to include("Memory: 8004.6 kb")
    end
  end
end