memory 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest DELETED
@@ -1,8 +0,0 @@
1
- CHANGELOG
2
- lib/memory/object.rb
3
- lib/memory/profile.rb
4
- lib/memory/usage.rb
5
- lib/memory.rb
6
- LICENSE
7
- Manifest
8
- README
data/README DELETED
@@ -1,14 +0,0 @@
1
-
2
- Memory
3
-
4
- Some libraries for reporting memory usage.
5
-
6
- == Requirements
7
-
8
- * Linux or OS X
9
-
10
- == License
11
-
12
- Copyright 2007, 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. Portions copyright 2005 John Carter and used with permission.
13
-
14
- The public certificate for the gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem].
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
-
2
- require 'echoe'
3
-
4
- Echoe.new("memory") do |p|
5
- p.author = "Evan Weaver"
6
- p.project = "fauna"
7
- p.summary = "Some libraries for reporting memory usage."
8
- p.url = "http://blog.evanweaver.com/files/doc/fauna/memory/"
9
- p.docs_host = 'blog.evanweaver.com:~/www/bax/public/files/doc/'
10
- p.require_signed = true
11
- end
@@ -1,66 +0,0 @@
1
-
2
- include ObjectSpace
3
-
4
- MEMORY_PROFILE_BAD_SIZE_METHOD = {FileTest => true, File => true, File::Stat => true}
5
-
6
- class Object
7
- def memory_profile_size_of_object(seen={})
8
- return 0 if seen.has_key? object_id
9
- seen[object_id] = true
10
- count = 1
11
- if kind_of? Hash
12
- each_pair do |key,value|
13
- count += key.memory_profile_size_of_object(seen)
14
- count += value.memory_profile_size_of_object(seen)
15
- end
16
- elsif kind_of? Array
17
- count += size
18
- each do |element|
19
- count += element.memory_profile_size_of_object(seen)
20
- end
21
- end
22
-
23
- count += instance_variables.size
24
- instance_variables.each do |var|
25
- count += instance_variable_get(var.to_sym).memory_profile_size_of_object(seen)
26
- end
27
-
28
- count
29
- end
30
-
31
- def memory_profile_inspect(seen={},level=0)
32
- return object_id.to_s if seen.has_key? object_id
33
- seen[object_id] = true
34
- result = ' '*level
35
- if kind_of? Hash
36
- result += "{\n" + ' '*level
37
- each_pair do |key,value|
38
- result += key.memory_profile_inspect(seen,level+1) + "=>\n"
39
- result += value.memory_profile_inspect(seen,level+2) + ",\n" + ' '*level
40
- end
41
- result += "}\n" + ' '*level
42
- elsif kind_of? Array
43
- result += "[\n" + ' '*level
44
- each do |element|
45
- result += element.memory_profile_inspect(seen,level+1) + ",\n" + ' '*level
46
- end
47
- result += "]\n" + ' '*level
48
- elsif kind_of? String
49
- result += self
50
- elsif kind_of? Numeric
51
- result += self.to_s
52
- elsif kind_of? Class
53
- result += to_s
54
- else
55
- result += "---"+self.class.to_s + "---\n" + ' '*level
56
- end
57
-
58
-
59
- instance_variables.each do |var|
60
- result += var + "=" + instance_variable_get(var.to_sym).memory_profile_inspect(seen,level+1) + "\n" + ' '*level
61
- end
62
-
63
- result
64
- end
65
-
66
- end
@@ -1,94 +0,0 @@
1
-
2
- require "#{File.dirname(__FILE__)}/object"
3
-
4
- module Memory
5
- module Profile
6
-
7
- LOG_FILE = "/tmp/memory_profile.log"
8
-
9
- def self.report
10
- Dir.chdir "/tmp"
11
- ObjectSpace::garbage_collect
12
- sleep 10 # Give the GC thread a chance
13
- all = []
14
- ObjectSpace.each_object do |obj|
15
- next if obj.object_id == all.object_id
16
-
17
- all << obj
18
- end
19
-
20
- tally = Hash.new(0)
21
- max_obj = nil
22
- max_count = 0
23
- all.each do |obj|
24
- count = obj.memory_profile_size_of_object
25
- if max_count < count
26
- max_obj = obj
27
- max_count = count
28
- end
29
-
30
- tally[obj.class]+=count
31
- end
32
-
33
- open( LOG_FILE, 'a') do |outf|
34
- outf.puts '+'*70
35
- tally.keys.sort{|a,b|
36
- if tally[a] == tally[b]
37
- a.to_s <=> b.to_s
38
- else
39
- -1*(tally[a]<=>tally[b])
40
- end
41
- }.each do |klass|
42
- outf.puts "#{klass}\t#{tally[klass]}"
43
- end
44
-
45
- outf.puts '-'*70
46
- outf.puts "Max obj was #{max_obj.class} at #{max_count}"
47
- outf.puts "Maximum object is..."
48
- outf.puts max_obj.memory_profile_inspect
49
- end
50
- end
51
-
52
- def self.simple_count
53
- Dir.chdir "/tmp"
54
- ObjectSpace::garbage_collect
55
- sleep 10 # Give the GC thread a chance
56
-
57
- tally = Hash.new(0)
58
- ObjectSpace.each_object do |obj|
59
- next if obj.object_id == tally.object_id
60
- tally[obj.class]+=1
61
- end
62
-
63
- open( LOG_FILE, 'a') do |outf|
64
- outf.puts '='*70
65
- outf.puts "Memory::Profile report for #{$0}"
66
- outf.puts `cat /proc/#{Process.pid}/status`
67
-
68
- tally.keys.sort{|a,b|
69
- if tally[a] == tally[b]
70
- a.to_s <=> b.to_s
71
- else
72
- -1*(tally[a]<=>tally[b])
73
- end
74
- }.each do |klass|
75
- outf.puts "#{klass}\t#{tally[klass]}"
76
- end
77
- end
78
- end
79
- end
80
- end
81
-
82
- # if $0 == __FILE__ then
83
- # File.unlink Memory::Profile::LOG_FILE if File.exist? Memory::Profile::LOG_FILE
84
- #
85
- # at_exit{ system("cat #{Memory::Profile::LOG_FILE}")}
86
- # end
87
-
88
- at_exit do
89
- Memory::Profile::simple_count
90
- Memory::Profile::report
91
- end
92
-
93
-
94
-
@@ -1,65 +0,0 @@
1
-
2
- module System
3
- LINUX_PAGE_SIZE = 1024
4
-
5
- class << self
6
- def memory
7
- result = {}
8
- if RUBY_PLATFORM =~ /darwin/
9
- # OS X
10
- output = `vm_stat`.split("\n")
11
- result['page size'] = output.shift[/page size of (\d+) bytes/, 1].to_i
12
- output.each do |line|
13
- line =~ /([\w\s]+)"{0,1}:\s*(\d+)/
14
- key, value = $1, $2
15
-
16
- key.downcase!
17
- key = case key
18
- when /Pages (.*)/
19
- $1 + " memory"
20
- when "pageouts"
21
- "pages paged out"
22
- when "pageins"
23
- "pages paged in"
24
- else
25
- key
26
- end
27
- result[key] = value.to_i
28
- end
29
- else
30
- # Linux
31
- output = `vmstat -s -S K`.split("\n")
32
- page_size = 1
33
- output.each do |line|
34
- line =~ /(\d+)\s*([\w\s]+)/
35
- key, value = $2, $1
36
- key.gsub!(/^K /, '')
37
- result[key] = value.to_i
38
- end
39
- end
40
- normalize_pages(result)
41
- end
42
-
43
- private
44
-
45
- def normalize_pages(hash)
46
- hash.each do |key, value|
47
- if key =~ /memory/
48
- hash[key] = value * (hash['page size'] or LINUX_PAGE_SIZE)
49
- end
50
- end
51
- hash
52
- end
53
-
54
- end
55
- end
56
-
57
- module Process
58
- class << self
59
- def memory
60
- a = `ps -o vsz,rss -p #{Process.pid}`.split(/\s+/)[-2..-1].map{|el| el.to_i}
61
- {:virtual => a.first - a.last, :total => a.first, :real => a.last, }
62
- end
63
- end
64
- end
65
-
@@ -1,32 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{memory}
5
- s.version = "0.0.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Evan Weaver"]
9
- s.cert_chain = ["/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-public_cert.pem"]
10
- s.date = %q{2009-11-18}
11
- s.description = %q{Some libraries for reporting memory usage.}
12
- s.email = %q{}
13
- s.extra_rdoc_files = ["CHANGELOG", "lib/memory/object.rb", "lib/memory/profile.rb", "lib/memory/usage.rb", "lib/memory.rb", "LICENSE", "README"]
14
- s.files = ["CHANGELOG", "lib/memory/object.rb", "lib/memory/profile.rb", "lib/memory/usage.rb", "lib/memory.rb", "LICENSE", "Manifest", "README", "memory.gemspec", "Rakefile"]
15
- s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/memory/}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Memory", "--main", "README"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{fauna}
19
- s.rubygems_version = %q{1.3.5}
20
- s.signing_key = %q{/Users/eweaver/p/configuration/gem_certificates/evan_weaver-original-private_key.pem}
21
- s.summary = %q{Some libraries for reporting memory usage.}
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 3
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- else
29
- end
30
- else
31
- end
32
- end
metadata.gz.sig DELETED
Binary file