hotch 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +31 -1
- data/examples/simple.rb +23 -0
- data/lib/hotch.rb +77 -17
- data/lib/hotch/run.rb +8 -0
- data/lib/hotch/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38cc02398ab2755f8c90da8ae6ea973db46de9b7
|
4
|
+
data.tar.gz: 938117da7ad53717ba52d5507c9b4b8575317068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91eaa4af1f66add4591182e39b47192325b5842e7bb87176aba19491e071880394d6421288590943683f2103e970e143f07bd535b3eb758fc393ba1919187f17
|
7
|
+
data.tar.gz: 485b40654f50784ec3e08483fac13b4b01b41fefa47790e8d25abf9cf99d32ab720f49169517cda9b662de3ddd72128415c52054b28f1c0850b2313be4e1a8c2
|
data/README.md
CHANGED
@@ -27,10 +27,40 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
### Profile complete program
|
31
|
+
|
32
|
+
$ ruby -rhotch/run my_program.rb
|
31
33
|
Profile SVG: /tmp/hotch.my_program20150104-17330-18t4171/profile.svg
|
32
34
|
$ view /tmp/hotch.my_program20150104-17330-18t4171/profile.svg
|
33
35
|
|
36
|
+
### Profile blocks in your program
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'hotch'
|
40
|
+
|
41
|
+
def expensive_method
|
42
|
+
# ...
|
43
|
+
end
|
44
|
+
|
45
|
+
Hotch() do
|
46
|
+
1000.times do
|
47
|
+
expensive_method
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Hotch(aggregate: false) do
|
52
|
+
1000.times do
|
53
|
+
# this run is not aggregated
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Hotch() do
|
58
|
+
1000.times do
|
59
|
+
# aggregated again
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
34
64
|
### Auto-view
|
35
65
|
|
36
66
|
Set envvar `HOTCH_VIEWER` to enable auto-view after profiling.
|
data/examples/simple.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'hotch'
|
2
|
+
|
3
|
+
COUNT = ENV.fetch('COUNT', 10_000)
|
4
|
+
|
5
|
+
def foo
|
6
|
+
"x" * 23
|
7
|
+
end
|
8
|
+
|
9
|
+
def bar
|
10
|
+
["x"] * 23
|
11
|
+
end
|
12
|
+
|
13
|
+
Hotch(aggregate: false) do
|
14
|
+
COUNT.times do
|
15
|
+
foo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Hotch() do
|
20
|
+
COUNT.times do
|
21
|
+
bar
|
22
|
+
end
|
23
|
+
end
|
data/lib/hotch.rb
CHANGED
@@ -1,32 +1,92 @@
|
|
1
1
|
require 'stackprof'
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
|
-
|
4
|
+
class Hotch
|
5
|
+
attr_reader :name
|
5
6
|
|
6
|
-
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@reports = []
|
10
|
+
end
|
7
11
|
|
8
|
-
|
12
|
+
def start(*args)
|
13
|
+
StackProf.start(*args) unless StackProf.running?
|
14
|
+
end
|
9
15
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
16
|
+
def stop
|
17
|
+
if StackProf.running?
|
18
|
+
StackProf.stop
|
19
|
+
@reports << StackProf::Report.new(results)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(*args)
|
24
|
+
start(*args)
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
stop
|
28
|
+
end
|
29
|
+
|
30
|
+
def results
|
31
|
+
StackProf.results
|
32
|
+
end
|
33
|
+
|
34
|
+
def report
|
35
|
+
report = @reports.inject(:+) or return
|
36
|
+
|
37
|
+
dir = Dir.mktmpdir("hotch.#{name}.")
|
38
|
+
dump = File.open(File.join(dir, "profile.dump"), "wb")
|
39
|
+
svg = File.join(File.join(dir, "profile.svg"))
|
40
|
+
|
41
|
+
|
42
|
+
report.print_graphviz(nil, dump)
|
13
43
|
|
14
|
-
|
15
|
-
StackProf.stop
|
44
|
+
dump.close
|
16
45
|
|
17
|
-
|
18
|
-
dump = File.open(File.join(dir, "profile.dump"), "wb")
|
19
|
-
svg = File.join(File.join(dir, "profile.svg"))
|
46
|
+
system! "dot", "-Tsvg", "-o", svg, dump.path
|
20
47
|
|
21
|
-
|
48
|
+
yield svg
|
49
|
+
end
|
50
|
+
|
51
|
+
def system!(*args)
|
52
|
+
Kernel.system(*args) or raise "system call failed: #{args.join(' ')}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def report_at_exit(viewer=ENV['HOTCH_VIEWER'])
|
56
|
+
return if defined? @at_exit_installed
|
57
|
+
|
58
|
+
at_exit do
|
59
|
+
stop
|
60
|
+
|
61
|
+
report do |svg|
|
62
|
+
puts "Profile SVG: #{svg}"
|
22
63
|
|
23
|
-
|
64
|
+
if viewer
|
65
|
+
system viewer, svg
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
24
69
|
|
25
|
-
|
70
|
+
@at_exit_installed = true
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def name
|
76
|
+
@name.gsub(/\W+/, '_')
|
77
|
+
end
|
78
|
+
end
|
26
79
|
|
27
|
-
|
80
|
+
def Hotch(aggregate: true)
|
81
|
+
hotch = if aggregate
|
82
|
+
$hotch ||= Hotch.new($0)
|
83
|
+
else
|
84
|
+
caller = Kernel.caller_locations(1).first
|
85
|
+
Hotch.new("#$0:#{caller.path}:#{caller.lineno}")
|
86
|
+
end
|
28
87
|
|
29
|
-
|
30
|
-
|
88
|
+
hotch.report_at_exit
|
89
|
+
hotch.run do
|
90
|
+
yield
|
31
91
|
end
|
32
92
|
end
|
data/lib/hotch/run.rb
ADDED
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stackprof
|
@@ -64,8 +64,10 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
|
+
- examples/simple.rb
|
67
68
|
- hotch.gemspec
|
68
69
|
- lib/hotch.rb
|
70
|
+
- lib/hotch/run.rb
|
69
71
|
- lib/hotch/version.rb
|
70
72
|
homepage: https://github.com/splattael/hotch
|
71
73
|
licenses:
|
@@ -87,9 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
89
|
version: '0'
|
88
90
|
requirements: []
|
89
91
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.2.2
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: Profile helper
|
94
96
|
test_files: []
|
95
|
-
has_rdoc:
|