gctime 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/gctime.gemspec +27 -0
- data/lib/gctime.rb +28 -0
- data/lib/gctime/version.rb +5 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 005b9e06310decdc1c0fb6db3c4bd4a12eb1ef09f76d2ff3fb3bc95fda6ee470
|
4
|
+
data.tar.gz: 7df3592962b65d76c7c8dd4015e3918e1499a63ff7a878c84b57399778b18517
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10e639bbc964593d78fd0cd3a6e74acc634d38d110e7563d0f9d797229015dffa33f3412cde819a3703caf654f92241ebcf1a4a3cfecd3b3c1c99f1a73d0a679
|
7
|
+
data.tar.gz: 9a337cdebcb677659f4725ab67fb9d536167bd84ce2bb58a0a59021e70bd2f797ac7148dc674aa4d29b4852314a2ac7db89f1e634e13808dc1685121f305ef3e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gctime (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.14.4)
|
10
|
+
rake (13.0.6)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
x86_64-darwin-20
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
gctime!
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 13.0)
|
19
|
+
|
20
|
+
BUNDLED WITH
|
21
|
+
2.2.25
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jean Boussier
|
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,65 @@
|
|
1
|
+
# GCTime
|
2
|
+
|
3
|
+
Exposes a monotonically increasing GC total_time metric.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gctime'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gctime
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'gctime'
|
25
|
+
>> GCTime.total_time
|
26
|
+
=> 0.0
|
27
|
+
>> GCTime.enable
|
28
|
+
=> nil
|
29
|
+
>> 4.times { GC.start }
|
30
|
+
=> 4
|
31
|
+
>> GCTime.total_time
|
32
|
+
=> 0.12742100000000012
|
33
|
+
>> GCTime.disable
|
34
|
+
=> nil
|
35
|
+
```
|
36
|
+
|
37
|
+
## Incompatibilities
|
38
|
+
|
39
|
+
`CGTime` relies on the built-in [`GC::Profiler`](https://ruby-doc.org/core-3.0.0/GC/Profiler.html) which is a stateful datastructure. Which mean any other gem or application code using it
|
40
|
+
is likely incompatoble with `GCTime` and will likely lead to incorrect timings.
|
41
|
+
|
42
|
+
Known incompatible gems are:
|
43
|
+
|
44
|
+
- [`newrelic_rpm`](https://github.com/newrelic/newrelic-ruby-agent/blob/4baffe79b87e6ec725dfae9f5e76113a1f1d01ba/lib/new_relic/agent/vm/monotonic_gc_profiler.rb#L22-L38)
|
45
|
+
|
46
|
+
## Memory Leak
|
47
|
+
|
48
|
+
It is important to note that the underlying `GC::Profiler` keeps internal records of all GC triggers. Every time `GCTime.total_time` is called the datastructure is reset,
|
49
|
+
but if it isn't called on a regular basis, it might lead to a memory leak.
|
50
|
+
|
51
|
+
Make sure to either call it on a regular basis, or to disable it when it's no longer needed.
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/gctime.
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "gctime"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gctime.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/gctime/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "gctime"
|
7
|
+
spec.version = GCTime::VERSION
|
8
|
+
spec.authors = ["Jean Boussier"]
|
9
|
+
spec.email = ["jean.boussier@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Exposes a monotonically increasing GC total_time metric."
|
12
|
+
spec.homepage = "https://github.com/Shopify/gctime"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
data/lib/gctime.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gctime/version"
|
4
|
+
|
5
|
+
module GCTime
|
6
|
+
@mutex = Mutex.new
|
7
|
+
@total_time = 0.0
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def enable
|
11
|
+
GC::Profiler.enable
|
12
|
+
end
|
13
|
+
|
14
|
+
def disable
|
15
|
+
GC::Profiler.disable
|
16
|
+
end
|
17
|
+
|
18
|
+
def total_time
|
19
|
+
if GC::Profiler.total_time > 0.0
|
20
|
+
@mutex.synchronize do
|
21
|
+
@total_time += GC::Profiler.total_time
|
22
|
+
GC::Profiler.clear
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@total_time
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gctime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean Boussier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- jean.boussier@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- gctime.gemspec
|
29
|
+
- lib/gctime.rb
|
30
|
+
- lib/gctime/version.rb
|
31
|
+
homepage: https://github.com/Shopify/gctime
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
allowed_push_host: https://rubygems.org
|
36
|
+
homepage_uri: https://github.com/Shopify/gctime
|
37
|
+
source_code_uri: https://github.com/Shopify/gctime
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.2.22
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Exposes a monotonically increasing GC total_time metric.
|
57
|
+
test_files: []
|