bundler-timing-plugin 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 32dbf1bb3290b1c2a33914de2a2fc1ddc1372e5d52abb4ed6a4b4810561ceb0d
4
+ data.tar.gz: 61a59426465d4f5a4cd63f549cd81c799a55fd58477511b2accff0c0011ffb77
5
+ SHA512:
6
+ metadata.gz: 004a16474d5516ae225c6368fa4bba47f66c91bf71dd8982e2498e849fb8c0c14cbd849859a3ec7a5b06d9da2b3508400a632433dd206605df0b32289939627b
7
+ data.tar.gz: c06940750df9ff93a709a03e2606a75c1c7a91871d018a7cd368d8f5215c626a153486be9269540521cc691069bed9a5890fe0a4e2b73b608f8e1eb3216666f3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Hiroshi SHIBATA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # bundler-timing-plugin
2
+
3
+ Bundler plugin that displays the elapsed time of each gem fetch and install during `bundle install`. It also prints the elapsed time of git source fetches.
4
+
5
+ ## Requirements
6
+
7
+ Bundler 4.1.0.dev or higher. Earlier Bundler versions do not emit the `before-fetch`/`after-fetch`/`before-git-fetch`/`after-git-fetch` hooks this plugin relies on.
8
+
9
+ ## Installation
10
+
11
+ Install the plugin globally:
12
+
13
+ ```
14
+ $ bundler plugin install bundler-timing-plugin
15
+ ```
16
+
17
+ Or declare it in your `Gemfile`:
18
+
19
+ ```ruby
20
+ plugin "bundler-timing-plugin"
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Once installed, the plugin is fully automatic. Running `bundle install` will print one line per gem download, install, and git source fetch:
26
+
27
+ ```
28
+ $ bundle install
29
+ Fetching gem metadata from https://rubygems.org/...
30
+ Downloaded rails in: 0.482s
31
+ Installed rails in: 0.137s
32
+ Downloaded rake in: 0.094s
33
+ Installed rake in: 0.066s
34
+ Fetched https://github.com/example/my_gem.git in: 1.203s
35
+ ```
36
+
37
+ Gems that are already fully cached and skip the download step only emit the install line. If a gem install fails, the timing line for that gem is omitted.
38
+
39
+ ## How it works
40
+
41
+ The plugin registers six Bundler plugin hooks and uses `Process::CLOCK_MONOTONIC` to measure elapsed time:
42
+
43
+ | Hook | Use |
44
+ |---|---|
45
+ | `before-fetch` / `after-fetch` | Time `Source::Rubygems#download_gem` |
46
+ | `before-install` / `after-install` | Time `ParallelInstaller` install per gem |
47
+ | `before-git-fetch` / `after-git-fetch` | Time `Source::Git` fetch and checkout |
48
+
49
+ State is held in a `Mutex`-protected hash so the plugin is safe under Bundler's parallel installer.
50
+
51
+ ## License
52
+
53
+ [MIT](LICENSE.txt)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+
5
+ module Bundler
6
+ module Timing
7
+ class Tracker
8
+ def initialize(ui: nil)
9
+ @ui = ui
10
+ @mutex = Mutex.new
11
+ @starts = {}
12
+ end
13
+
14
+ def start_fetch(spec)
15
+ record(fetch_key(spec))
16
+ end
17
+
18
+ def finish_fetch(spec)
19
+ elapsed = pop(fetch_key(spec))
20
+ return unless elapsed
21
+ ui.confirm(format("Downloaded %s in: %.3fs", spec.name, elapsed))
22
+ @mutex.synchronize { @starts[install_key(spec)] = now }
23
+ end
24
+
25
+ def start_install(spec_install)
26
+ @mutex.synchronize { @starts[install_key(spec_install)] ||= now }
27
+ end
28
+
29
+ def finish_install(spec_install)
30
+ elapsed = pop(install_key(spec_install))
31
+ return unless elapsed
32
+ ui.confirm(format("Installed %s in: %.3fs", spec_install.name, elapsed))
33
+ end
34
+
35
+ def start_git_fetch(source)
36
+ record(git_key(source))
37
+ end
38
+
39
+ def finish_git_fetch(source)
40
+ elapsed = pop(git_key(source))
41
+ return unless elapsed
42
+ ui.confirm(format("Fetched %s in: %.3fs", git_label(source), elapsed))
43
+ end
44
+
45
+ private
46
+
47
+ def ui
48
+ @ui || Bundler.ui
49
+ end
50
+
51
+ def now
52
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
53
+ end
54
+
55
+ def record(key)
56
+ @mutex.synchronize { @starts[key] = now }
57
+ end
58
+
59
+ def pop(key)
60
+ t0 = @mutex.synchronize { @starts.delete(key) }
61
+ return nil unless t0
62
+ now - t0
63
+ end
64
+
65
+ def fetch_key(spec)
66
+ [:fetch, spec.full_name]
67
+ end
68
+
69
+ def install_key(obj)
70
+ [:install, obj.full_name]
71
+ end
72
+
73
+ def git_key(source)
74
+ [:git, source.object_id]
75
+ end
76
+
77
+ def git_label(source)
78
+ if source.respond_to?(:uri) && source.uri
79
+ source.uri
80
+ elsif source.respond_to?(:name) && source.name
81
+ source.name
82
+ else
83
+ source.to_s
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bundler
4
+ module Timing
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "timing/version"
4
+ require_relative "timing/tracker"
5
+
6
+ module Bundler
7
+ module Timing
8
+ end
9
+ end
data/plugins.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+ require "bundler/timing"
5
+
6
+ tracker = Bundler::Timing::Tracker.new
7
+
8
+ Bundler::Plugin.add_hook("before-fetch") { |spec| tracker.start_fetch(spec) }
9
+ Bundler::Plugin.add_hook("after-fetch") { |spec| tracker.finish_fetch(spec) }
10
+ Bundler::Plugin.add_hook("before-install") { |si| tracker.start_install(si) }
11
+ Bundler::Plugin.add_hook("after-install") { |si| tracker.finish_install(si) }
12
+ Bundler::Plugin.add_hook("before-git-fetch") { |source| tracker.start_git_fetch(source) }
13
+ Bundler::Plugin.add_hook("after-git-fetch") { |source| tracker.finish_git_fetch(source) }
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ module Timing
3
+ VERSION: String
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-timing-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi SHIBATA
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0.dev
20
+ type: :runtime
21
+ prerelease: true
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 4.1.0.dev
28
+ description: "Bundler plugin that prints the elapsed time of each gem download, install, and git source fetch via Bundler plugin hooks."
29
+ email:
30
+ - hsbt@ruby-lang.org
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/bundler/timing.rb
39
+ - lib/bundler/timing/tracker.rb
40
+ - lib/bundler/timing/version.rb
41
+ - plugins.rb
42
+ - sig/bundler/timing.rbs
43
+ homepage: "https://github.com/hsbt/bundler-timing-plugin"
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: "https://github.com/hsbt/bundler-timing-plugin"
48
+ source_code_uri: "https://github.com/hsbt/bundler-timing-plugin"
49
+ rubygems_mfa_required: "true"
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ -
56
+ - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.2.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ -
62
+ - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ requirements: []
66
+ rubygems_version: 4.1.0.dev
67
+ specification_version: 4
68
+ summary: Display elapsed time of each gem fetch and install during bundle install.
69
+ test_files: []