hotch 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61f71a4ba3bef064a412f8b79c1932a84e0a1316
4
- data.tar.gz: 59554006ec68fe65bae953d22a85462ec5d766e8
3
+ metadata.gz: 919be5a42ce8821e1317ae44c23e16f1853765ca
4
+ data.tar.gz: f841136247fcf929035a0e50995df061388d7ceb
5
5
  SHA512:
6
- metadata.gz: 29420bf9b209a0d2a989763f24549844d3aa86d7a71420e92e48309aa213cd6357071031b9df6a936f8cfaa5e02fe16a31fa422db4a2f325f4cdb159c5f33821
7
- data.tar.gz: 2d9589beac8841df9e8b1e8b9992308310ec3dd142e33a24a53e80a1826a5b92554ad1941d55f72e9526054077fda658ba5f30b7baf174264153b333783b0bdf
6
+ metadata.gz: 6d042be9fac36eafe88762493b6768a9871f8e482417c6eb2e71259202a487a4b46c134272db5c4a4a8d42c95c4edce0a0667848f12b9092479d0a7fcde4d974
7
+ data.tar.gz: 3e47fbfee879dae72763653c216ef60589c25d145dac901e411f746185a027ac1fbc029b5b06109b8d1e468375ad128e1629df4089949b1e9b6af3b8d3b61779
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hotch.gemspec
4
4
  gemspec
5
+
6
+ gem 'stackprof', :github => 'splattael/stackprof', :branch => 'graphviz_filter'
data/README.md CHANGED
@@ -67,6 +67,22 @@ Set envvar `HOTCH_VIEWER` to enable auto-view after profiling.
67
67
 
68
68
  $ export HOTCH_VIEWER=eog # use Gnome viewer
69
69
 
70
+ ### Filter
71
+
72
+ Set envvar `HOTCH_FILTER` to (regexp) filter frames by its name.
73
+
74
+ $ export HOTCH_FILTER=ROM
75
+ $ export HOTCH_FILTER=Bundler
76
+
77
+ ### Minitest integration
78
+
79
+ Load `hotch/minitest` in your `test/test_helper.rb` like this:
80
+
81
+ ```ruby
82
+ require 'minitest/autorun'
83
+ require 'hotch/minitest'
84
+ ```
85
+
70
86
  ## Caveat
71
87
 
72
88
  ### Using with bundler
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ require 'hotch'
3
+
4
+ # run via ruby -rhotch/run bundler.rb
@@ -4,10 +4,12 @@ require 'tmpdir'
4
4
  require 'hotch/monkey_patches'
5
5
 
6
6
  class Hotch
7
- attr_reader :name
7
+ attr_reader :name, :viewer, :filter
8
8
 
9
- def initialize(name)
9
+ def initialize(name, viewer: nil, filter: nil)
10
10
  @name = name
11
+ @viewer = viewer
12
+ @filter = filter
11
13
  @reports = []
12
14
  end
13
15
 
@@ -45,17 +47,18 @@ class Hotch
45
47
  yield svg
46
48
  end
47
49
 
48
- def report_at_exit(viewer=ENV['HOTCH_VIEWER'])
50
+ def report_at_exit
49
51
  return if defined? @at_exit_installed
50
52
 
51
53
  at_exit do
52
54
  stop
53
55
 
54
56
  report do |svg|
55
- puts "Profile SVG: #{svg}"
56
-
57
57
  if viewer
58
+ puts "Profile SVG: #{svg}"
58
59
  Kernel.system viewer, svg
60
+ else
61
+ puts "Profile SVG: view #{svg} # no HOTCH_VIEWER set"
59
62
  end
60
63
  end
61
64
  end
@@ -80,7 +83,7 @@ class Hotch
80
83
  def report_dot(report, dir, file)
81
84
  path = File.join(dir, file)
82
85
  File.open(path, 'wb') do |fh|
83
- report.print_graphviz(nil, fh)
86
+ report.print_graphviz(filter && Regexp.new(filter), fh)
84
87
  end
85
88
  path
86
89
  end
@@ -92,12 +95,12 @@ class Hotch
92
95
  end
93
96
  end
94
97
 
95
- def Hotch(aggregate: true)
98
+ def Hotch(name: $0, aggregate: true, viewer: ENV['HOTCH_VIEWER'], filter: ENV['HOTCH_FILTER'])
96
99
  hotch = if aggregate
97
- $hotch ||= Hotch.new($0)
100
+ $hotch ||= Hotch.new(name, viewer: viewer, filter: filter)
98
101
  else
99
102
  caller = Kernel.caller_locations(1).first
100
- Hotch.new("#$0:#{caller.path}:#{caller.lineno}")
103
+ Hotch.new("#{name}:#{caller.path}:#{caller.lineno}", viewer: viewer, filter: filter)
101
104
  end
102
105
 
103
106
  hotch.report_at_exit
@@ -0,0 +1,20 @@
1
+ class Hotch
2
+ module Minitest
3
+ # Usage in test/test_helper.rb:
4
+ #
5
+ # require 'hotch/minitest'
6
+ #
7
+ def self.aggregate
8
+ Module.new do
9
+ def run_one_method(*args)
10
+ Hotch(aggregate: true) do
11
+ super(*args)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ require "hotch"
20
+ Minitest.singleton_class.prepend Hotch::Minitest.aggregate
@@ -1,8 +1,6 @@
1
1
  require 'hotch'
2
2
 
3
- viewer = ENV['HOTCH_VIEWER']
4
-
5
- hotch = Hotch.new($0)
3
+ hotch = Hotch.new($0, viewer: ENV['HOTCH_VIEWER'], filter: ENV['HOTCH_FILTER'])
6
4
  hotch.start
7
5
 
8
- hotch.report_at_exit(viewer)
6
+ hotch.report_at_exit
@@ -1,3 +1,3 @@
1
- module Hotch
2
- VERSION = "0.0.3"
1
+ class Hotch
2
+ VERSION = "0.1.0"
3
3
  end
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.3
4
+ version: 0.1.0
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-05 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stackprof
@@ -64,9 +64,11 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
+ - examples/bundler.rb
67
68
  - examples/simple.rb
68
69
  - hotch.gemspec
69
70
  - lib/hotch.rb
71
+ - lib/hotch/minitest.rb
70
72
  - lib/hotch/monkey_patches.rb
71
73
  - lib/hotch/run.rb
72
74
  - lib/hotch/version.rb
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubyforge_project:
93
- rubygems_version: 2.2.2
95
+ rubygems_version: 2.4.8
94
96
  signing_key:
95
97
  specification_version: 4
96
98
  summary: Profile helper