bumbler 0.2.1 → 0.3.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: fdafd8de66c8e6e9fecbc41654d7408d1f8ab1af
4
- data.tar.gz: e56cae51bb0e6a97aec7a3e4f9ac5fc7145ab38b
3
+ metadata.gz: 9da205e5dde7cac9a1568c557993872636cd0ffd
4
+ data.tar.gz: ab7b2b5b97f952eb6dc299e579ca9fe7e17e6604
5
5
  SHA512:
6
- metadata.gz: 242b08d8a00f098058d1d387498581a45c8f7748100120fe86d8796bb23fb6455136d128836a9f845bcf8743858f6542ba5e719f58865b27c0ceabdb3976be95
7
- data.tar.gz: 857dc10735d0cc90f34fec7e4b8d8ddae9647347b7dc6181152a1334e2f2b5d3602be89ff236fea0356b636666dad84b3b966a8764546df200805a4ea2a54520
6
+ metadata.gz: c48658e26dc52a97035412c716265bfbdf43336f33a6262e8152830194ed3af9919f0700e49963c383ef461d1a72ee0804df1b3778c3cf6b487c875add7000fc
7
+ data.tar.gz: 154dae20f53893ad2636675018013b07ef921ce67e885739ab5a9f0653e8ed015f651a7aab22a15a2ed22b069b6c6ab00163fd3b7944db8a6548130ce7db53c6
@@ -4,6 +4,7 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  require 'optparse'
5
5
  require 'bumbler'
6
6
 
7
+ options = {}
7
8
  OptionParser.new do |parser|
8
9
  parser.banner = <<BANNER
9
10
  Bumbler shows how long loading your bundle components take.
@@ -13,11 +14,22 @@ Usage:
13
14
 
14
15
  Options:
15
16
  BANNER
16
- parser.on("-h", "--help","Show this.") { puts parser; exit }
17
- parser.on('-v', '--version','Show Version'){ puts Bumbler::VERSION; exit}
17
+ parser.on("-t", "--threshold MILISECONDS", Integer, "Threshold in ms to be listed as slow") { |t| options[:threshold] = t }
18
+ parser.on("--initializers", "Show load time of initializers") { options[:initializers] = true }
19
+ parser.on("-h", "--help", "Show this.") { puts parser; exit }
20
+ parser.on('-v', '--version', 'Show Version'){ puts Bumbler::VERSION; exit}
18
21
  end.parse!
19
22
 
20
- require 'bumbler/go'
21
- require './config/environment'
23
+ Bumbler::Hooks.slow_threshold = options[:threshold] if options[:threshold]
24
+
25
+ if options[:initializers]
26
+ require './config/application'
27
+ require 'bumbler/track_initializers'
28
+ require './config/environment'
29
+ else
30
+ require 'bumbler/go'
31
+ require './config/environment'
32
+ end
33
+
22
34
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') # bundler kicks us out
23
35
  Bumbler::Stats.all_slow_items
@@ -1,19 +1,23 @@
1
1
  module Bumbler
2
2
  module Hooks
3
- SLOW_REQUIRE_THRESHOLD = 100.0
3
+ @slow_threshold = 100.0
4
4
  @previous_gems = {}
5
5
  @slow_requires = {}
6
-
6
+
7
7
  # Everything's a class method (we're a singleton)
8
8
  class << self
9
+ def slow_threshold=(time)
10
+ @slow_threshold = time
11
+ end
12
+
9
13
  def slow_requires
10
14
  @slow_requires
11
15
  end
12
-
16
+
13
17
  # Inject our custom handling of require into the Kernel.
14
18
  def hook_require!
15
19
  @hooking_require = true
16
-
20
+
17
21
  # There are two independent require methods. Joy!
18
22
  ::Kernel.module_eval do
19
23
  class << self
@@ -24,7 +28,7 @@ module Bumbler
24
28
  end
25
29
  end
26
30
  end
27
-
31
+
28
32
  orig_instance_require = self.instance_method(:require)
29
33
  define_method(:require) do |path, *args|
30
34
  ::Bumbler::Hooks.handle_require(path) do
@@ -32,10 +36,10 @@ module Bumbler
32
36
  end
33
37
  end
34
38
  end
35
-
39
+
36
40
  @hooking_require = nil
37
41
  end
38
-
42
+
39
43
  # Even better: Other gems hook require as well. The instance method one at least.
40
44
  def watch_require!
41
45
  ::Kernel.module_eval do
@@ -48,35 +52,38 @@ module Bumbler
48
52
  end
49
53
  end
50
54
  end
51
-
55
+
52
56
  def hooking_require?
53
57
  @hooking_require
54
58
  end
55
-
59
+
56
60
  # Actually do something about a require here.
57
- def handle_require(path)
61
+ def handle_require(path, &block)
58
62
  # break out early if we're already handling this
59
63
  return yield if path == @previous_require
60
64
  @previous_require = path
61
-
65
+
62
66
  # Shortcut unless we're tracking the gem
63
67
  gem_name = Bumbler::Bundler.gem_for_require(path)
64
68
  return yield unless gem_name
65
-
69
+
66
70
  # Track load starts
67
71
  Bumbler::Bundler.require_started(path) unless @previous_gems[gem_name]
68
72
  @previous_gems[gem_name] = true
69
-
70
- # Let's time them
73
+
74
+ time, result = benchmark(path, &block)
75
+
76
+ Bumbler::Bundler.require_finished(path, time) if result
77
+
78
+ result
79
+ end
80
+
81
+ def benchmark(key)
71
82
  start = Time.now.to_f
72
83
  result = yield
73
- require_time = (Time.now.to_f - start) * 1000 # ms
74
-
75
- @slow_requires[path] = require_time if require_time > SLOW_REQUIRE_THRESHOLD
76
-
77
- Bumbler::Bundler.require_finished(path, require_time) if result
78
-
79
- return result
84
+ time = (Time.now.to_f - start) * 1000 # ms
85
+ @slow_requires[key] = time if time > @slow_threshold
86
+ return time, result
80
87
  end
81
88
  end
82
89
  end
@@ -0,0 +1,14 @@
1
+ Rails::Engine.class_eval do
2
+ def load(initializer)
3
+ initializer = initializer.sub(Rails.root.to_s, ".")
4
+ Bumbler::Hooks.benchmark(initializer) { super }.last
5
+ end
6
+ end
7
+
8
+ Rails::Initializable::Initializer.class_eval do
9
+ alias_method :run_without_bumbler, :run
10
+ def run(*args)
11
+ name = (@name.is_a?(Symbol) ? @name.inspect : @name)
12
+ Bumbler::Hooks.benchmark(name) { run_without_bumbler(*args) }.last
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Bumbler
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian MacLeod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-27 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -82,9 +82,11 @@ files:
82
82
  - lib/bumbler/hooks.rb
83
83
  - lib/bumbler/progress.rb
84
84
  - lib/bumbler/stats.rb
85
+ - lib/bumbler/track_initializers.rb
85
86
  - lib/bumbler/version.rb
86
87
  homepage: https://github.com/nevir/Bumbler
87
- licenses: []
88
+ licenses:
89
+ - MIT
88
90
  metadata: {}
89
91
  post_install_message:
90
92
  rdoc_options: []