zenprofile 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/Manifest.txt +1 -0
- data/Rakefile +10 -8
- data/lib/memory_profiler.rb +108 -0
- data/lib/zenprofiler.rb +5 -5
- data/misc/factorial.rb +1 -1
- metadata +5 -14
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'hoe'
|
5
|
-
require './lib/zenprofiler.rb'
|
6
5
|
|
7
|
-
Hoe.
|
8
|
-
|
9
|
-
p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
|
6
|
+
Hoe.plugin :seattlerb
|
7
|
+
Hoe.plugin :inline
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
Hoe.spec 'zenprofile' do
|
10
|
+
developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
|
11
|
+
|
12
|
+
self.rubyforge_name = 'seattlerb'
|
13
|
+
|
14
|
+
extra_deps << 'ZenTest'
|
15
|
+
extra_deps << 'event_hook'
|
14
16
|
end
|
15
17
|
|
16
|
-
# vim: syntax=
|
18
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
class MemoryProfiler
|
3
|
+
|
4
|
+
# profile is a CLEAN, totally minimal memory profiler:
|
5
|
+
#
|
6
|
+
# * 1 thread
|
7
|
+
# * 2 hashes (curr, prev)
|
8
|
+
# * classes as keys
|
9
|
+
# * fixnums as values.
|
10
|
+
#
|
11
|
+
# No extra memory required if I can help it. Keep it as simple as
|
12
|
+
# possible. The code at the link above is WAY to complex for such a
|
13
|
+
# simple task. It does use a sort_by, so that produces a bit extra
|
14
|
+
# junk... but that shouldn't be more than an extra array and hash
|
15
|
+
# per iteration.
|
16
|
+
#
|
17
|
+
# Just fire it up as MemoryProfiler.profile or use it with a block
|
18
|
+
# of code:
|
19
|
+
#
|
20
|
+
# MemoryProfiler.profile do
|
21
|
+
# # ...
|
22
|
+
# end
|
23
|
+
|
24
|
+
def self.profile(delay = 2, limit=10, output=$stderr)
|
25
|
+
Thread.abort_on_exception = true
|
26
|
+
totals = Hash.new(0)
|
27
|
+
t = Thread.new do
|
28
|
+
prev = Hash.new(0)
|
29
|
+
curr = Hash.new(0)
|
30
|
+
loop do
|
31
|
+
curr.clear
|
32
|
+
ObjectSpace.each_object do |o|
|
33
|
+
curr[o.class] += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
curr.each do |k,v|
|
37
|
+
curr[k] -= prev[k]
|
38
|
+
end
|
39
|
+
|
40
|
+
puts
|
41
|
+
curr.sort_by { |k,v| -v }.first(limit).each do |k,v|
|
42
|
+
output.printf "%+5d: %s\n", v, k.name unless v == 0
|
43
|
+
end
|
44
|
+
|
45
|
+
prev.clear
|
46
|
+
prev.update curr
|
47
|
+
curr.each do |k,n| totals[k] += n end
|
48
|
+
sleep delay
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if block_given? then
|
52
|
+
yield
|
53
|
+
t.exit
|
54
|
+
end
|
55
|
+
totals
|
56
|
+
end
|
57
|
+
|
58
|
+
@@locations = {}
|
59
|
+
@@allocations = Hash.new { |h,k| h[k] = Hash.new(0) }
|
60
|
+
|
61
|
+
def self.log(o)
|
62
|
+
loc = caller[1]
|
63
|
+
unless @@locations.has_key? loc then
|
64
|
+
@@locations[loc] = @@locations.size
|
65
|
+
end
|
66
|
+
loc = @@locations[loc]
|
67
|
+
@@allocations[o.class][loc] += 1
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.spy_on *klasses
|
71
|
+
klasses.each do |klass|
|
72
|
+
hook klass, :initialize
|
73
|
+
if klass == String then
|
74
|
+
hook klass, :%
|
75
|
+
hook klass, :strip
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.hook klass, meth
|
81
|
+
klass.module_eval do
|
82
|
+
old = meth.to_s.sub(/%/, 'pct').sub(/^/, 'old_')
|
83
|
+
alias_method old, meth
|
84
|
+
eval "def #{meth}(*args, &block)
|
85
|
+
MemoryProfiler.log(self)
|
86
|
+
#{old}(*args, &block)
|
87
|
+
end"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.report
|
92
|
+
keys = @@locations.invert
|
93
|
+
|
94
|
+
puts
|
95
|
+
puts "############################################################"
|
96
|
+
puts "Spy Report:"
|
97
|
+
|
98
|
+
@@allocations.each do |klass, locations|
|
99
|
+
puts
|
100
|
+
puts klass
|
101
|
+
puts
|
102
|
+
locations.sort_by { |k,v| -v }.first(10).each do |location, count|
|
103
|
+
printf "%6d: %s\n", count, keys[location]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
p @@locations, @@allocations, keys if $DEBUG
|
107
|
+
end
|
108
|
+
end
|
data/lib/zenprofiler.rb
CHANGED
@@ -17,12 +17,12 @@ require 'event_hook'
|
|
17
17
|
# % ruby -rzenprofile misc/factorial.rb
|
18
18
|
|
19
19
|
class ZenProfiler < EventHook
|
20
|
-
VERSION = '1.0
|
20
|
+
VERSION = '1.1.0'
|
21
21
|
|
22
|
-
@@start
|
23
|
-
@@stack
|
24
|
-
@@map
|
25
|
-
@@map["#toplevel"]
|
22
|
+
@@start = nil
|
23
|
+
@@stack = [[0, 0, [nil, :toplevel]], [0, 0, [nil, :dummy]]]
|
24
|
+
@@map = Hash.new { |h,k| h[k] = [0, 0.0, 0.0, k] }
|
25
|
+
@@map["#toplevel"] = [1, 0.0, 0.0, [nil, "#toplevel"]]
|
26
26
|
@@percent_time_threshold = 0.5
|
27
27
|
|
28
28
|
def self.run(fp = $stdout, opts = {})
|
data/misc/factorial.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenprofile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
FBHgymkyj/AOSqKRIpXPhjC6
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-
|
33
|
+
date: 2009-06-23 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -53,16 +53,6 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: "0"
|
55
55
|
version:
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: RubyInline
|
58
|
-
type: :runtime
|
59
|
-
version_requirement:
|
60
|
-
version_requirements: !ruby/object:Gem::Requirement
|
61
|
-
requirements:
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: "0"
|
65
|
-
version:
|
66
56
|
- !ruby/object:Gem::Dependency
|
67
57
|
name: hoe
|
68
58
|
type: :development
|
@@ -71,7 +61,7 @@ dependencies:
|
|
71
61
|
requirements:
|
72
62
|
- - ">="
|
73
63
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
64
|
+
version: 2.3.0
|
75
65
|
version:
|
76
66
|
description: |-
|
77
67
|
zenprofiler helps answer WHAT is being called the most. spy_on helps
|
@@ -120,6 +110,7 @@ files:
|
|
120
110
|
- README.txt
|
121
111
|
- Rakefile
|
122
112
|
- bin/zenprofile
|
113
|
+
- lib/memory_profiler.rb
|
123
114
|
- lib/spy_on.rb
|
124
115
|
- lib/zenprofile.rb
|
125
116
|
- lib/zenprofiler.rb
|
@@ -150,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
141
|
requirements: []
|
151
142
|
|
152
143
|
rubyforge_project: seattlerb
|
153
|
-
rubygems_version: 1.3.
|
144
|
+
rubygems_version: 1.3.4
|
154
145
|
signing_key:
|
155
146
|
specification_version: 3
|
156
147
|
summary: zenprofiler helps answer WHAT is being called the most
|
metadata.gz.sig
CHANGED
Binary file
|