hotch 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/hotch/memory.rb +54 -17
- data/lib/hotch/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91a709e2c682f3fdb58f2c6c4a6a819f0e9c6395
|
4
|
+
data.tar.gz: e24a3beacb055a62464c27a50c81c029679abd16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d65c21413d4d0fb1bfaa8de21da4caf996f48d545904d880b05db53df8aed646c6837b05179b3e33273602066de7d5181550c9723c4b06cccf8588c5d2cfaf8
|
7
|
+
data.tar.gz: 9dc92d4e2d05c918a8ec19ecc07633d6e9f957109493cf28c7e692cc31b5e39c7328212cb3dd18c2a3a60ed44c0d68f68ed5262a89c6ca786bb4e95cf91bc863
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ dry/struct/class_interface.rb:77 T_OBJECT 2000 0 0 0
|
|
62
62
|
Add this line to your application's Gemfile:
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
gem 'hotch', '~> 0.4.
|
65
|
+
gem 'hotch', '~> 0.4.1'
|
66
66
|
```
|
67
67
|
|
68
68
|
And then execute:
|
@@ -198,5 +198,5 @@ Follow these steps to release this gem:
|
|
198
198
|
edit lib/hotch/version.rb
|
199
199
|
edit README.md
|
200
200
|
# Commit
|
201
|
-
git commit -
|
201
|
+
git commit -am "Release vX.Y.Z"
|
202
202
|
rake release
|
data/lib/hotch/memory.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'allocation_tracer'
|
2
2
|
|
3
3
|
class Hotch
|
4
|
-
def self.memory(name: $0)
|
4
|
+
def self.memory(name: $0, &block)
|
5
5
|
caller = Kernel.caller_locations(1).first
|
6
6
|
name = "#{name}:#{caller.path}:#{caller.lineno}"
|
7
7
|
memory = Memory.new(name)
|
8
8
|
|
9
9
|
memory.report_at_exit
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
if block
|
12
|
+
memory.run(&block)
|
13
|
+
else
|
14
|
+
memory.start
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
@@ -16,11 +19,12 @@ class Hotch
|
|
16
19
|
def initialize(name, ignore_paths: [])
|
17
20
|
@name = name
|
18
21
|
@ignore_paths = Array(ignore_paths || [])
|
19
|
-
@
|
22
|
+
@reports = []
|
20
23
|
@started = nil
|
21
24
|
end
|
22
25
|
|
23
26
|
def start
|
27
|
+
return if @started
|
24
28
|
ObjectSpace::AllocationTracer.setup [:path, :line, :type]
|
25
29
|
ObjectSpace::AllocationTracer.start
|
26
30
|
@started = true
|
@@ -30,7 +34,7 @@ class Hotch
|
|
30
34
|
return unless @started
|
31
35
|
results = ObjectSpace::AllocationTracer.stop
|
32
36
|
@started = nil
|
33
|
-
@
|
37
|
+
@reports << Report.new(results, @ignore_paths)
|
34
38
|
end
|
35
39
|
|
36
40
|
def run
|
@@ -42,7 +46,9 @@ class Hotch
|
|
42
46
|
|
43
47
|
def report
|
44
48
|
# TODO make it persistent (as CSV)
|
45
|
-
|
49
|
+
report = @reports.inject(:sum)
|
50
|
+
yield report
|
51
|
+
@reports.clear
|
46
52
|
end
|
47
53
|
|
48
54
|
def report_at_exit
|
@@ -66,17 +72,28 @@ class Hotch
|
|
66
72
|
end
|
67
73
|
|
68
74
|
class Report
|
75
|
+
attr_reader :lines
|
76
|
+
|
69
77
|
def initialize(results, ignore_paths)
|
70
78
|
@header = Line.new(*Line.members)
|
71
|
-
@total = Line::Total.new
|
72
79
|
@lines = results.map do |result|
|
73
|
-
|
74
|
-
@total.sum(line)
|
75
|
-
line
|
76
|
-
end
|
80
|
+
Line.from_result(result, ignore_paths)
|
77
81
|
end.compact
|
78
82
|
end
|
79
83
|
|
84
|
+
def sum(other)
|
85
|
+
by_key = Hash[@lines.map { |line| [line.key, line] }]
|
86
|
+
other.lines.each do |line|
|
87
|
+
if existing = by_key[line.key]
|
88
|
+
existing.sum(line)
|
89
|
+
else
|
90
|
+
by_key[line.key] = line
|
91
|
+
@lines << line
|
92
|
+
end
|
93
|
+
end
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
80
97
|
def format
|
81
98
|
# TODO refactor
|
82
99
|
max_lengths = Array.new(Line.members.size, 0)
|
@@ -89,12 +106,28 @@ class Hotch
|
|
89
106
|
end
|
90
107
|
|
91
108
|
def puts(io)
|
109
|
+
total!
|
92
110
|
fmt = format
|
93
111
|
@header.puts(io, fmt)
|
94
112
|
@lines.sort_by(&:count).each { |line| line.puts(io, fmt) }
|
95
113
|
@total.puts(io, fmt)
|
96
114
|
end
|
97
115
|
|
116
|
+
def to_s
|
117
|
+
io = StringIO.new
|
118
|
+
puts(io)
|
119
|
+
io.string
|
120
|
+
end
|
121
|
+
|
122
|
+
private def total!
|
123
|
+
return if defined? @total
|
124
|
+
|
125
|
+
@total = Line::Total.new
|
126
|
+
@lines.each do |line|
|
127
|
+
@total.sum(line)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
98
131
|
class Line < Struct.new(:filename, :type, :count, :old_count, :total_age,
|
99
132
|
:min_age, :max_age, :total_memsize)
|
100
133
|
# [
|
@@ -108,6 +141,10 @@ class Hotch
|
|
108
141
|
new(filename, *args)
|
109
142
|
end
|
110
143
|
|
144
|
+
def key
|
145
|
+
[filename, type]
|
146
|
+
end
|
147
|
+
|
111
148
|
def puts(io, fmt)
|
112
149
|
send = method(:send)
|
113
150
|
io.puts fmt % members.map(&send)
|
@@ -117,6 +154,12 @@ class Hotch
|
|
117
154
|
members.map { |member| self[member].to_s.size }
|
118
155
|
end
|
119
156
|
|
157
|
+
def sum(other)
|
158
|
+
other.to_a.each.with_index do |value, i|
|
159
|
+
self[i] += value if Numeric === value
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
120
163
|
private
|
121
164
|
|
122
165
|
MAX_PATH_LENGTH = 50
|
@@ -135,12 +178,6 @@ class Hotch
|
|
135
178
|
def initialize
|
136
179
|
super("TOTAL", "", 0, 0, 0, 0, 0, 0)
|
137
180
|
end
|
138
|
-
|
139
|
-
def sum(other)
|
140
|
-
other.to_a.each.with_index do |value, i|
|
141
|
-
self[i] += value if Numeric === value
|
142
|
-
end
|
143
|
-
end
|
144
181
|
end
|
145
182
|
end
|
146
183
|
end
|
data/lib/hotch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stackprof
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.5.
|
111
|
+
rubygems_version: 2.5.2
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Profile helper
|