gctime 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 005b9e06310decdc1c0fb6db3c4bd4a12eb1ef09f76d2ff3fb3bc95fda6ee470
4
- data.tar.gz: 7df3592962b65d76c7c8dd4015e3918e1499a63ff7a878c84b57399778b18517
3
+ metadata.gz: 415713b61297b0808196eb07372db20deda2723a58c449ad2b9b9f5692a619c2
4
+ data.tar.gz: 7f0ffe0e2cc8f5472a5ddc4239bf5fb2eceb6d1a81a14088a00fc5b4546052b2
5
5
  SHA512:
6
- metadata.gz: 10e639bbc964593d78fd0cd3a6e74acc634d38d110e7563d0f9d797229015dffa33f3412cde819a3703caf654f92241ebcf1a4a3cfecd3b3c1c99f1a73d0a679
7
- data.tar.gz: 9a337cdebcb677659f4725ab67fb9d536167bd84ce2bb58a0a59021e70bd2f797ac7148dc674aa4d29b4852314a2ac7db89f1e634e13808dc1685121f305ef3e
6
+ metadata.gz: b92fba315640ddfdb3a3edded95fdf52886e0d546c32d8e985b1c8653fd598382eded803094271e7af3509a33e647c89ed36bf364bbfcd642e3317a7969eef75
7
+ data.tar.gz: 83521f8200beea897272f42b622dff0f54e335364ed9452aad3661ce2ed5640f2a551f76e92b222570e07aa06f266e3919a1e676c4865d1406c59422940e5d76
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ ruby-head, '3.0', '2.7', '2.6', '2.5', 'truffleruby' ]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run test
21
+ run: rake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gctime (0.1.0)
4
+ gctime (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,6 +10,7 @@ GEM
10
10
  rake (13.0.6)
11
11
 
12
12
  PLATFORMS
13
+ ruby
13
14
  x86_64-darwin-20
14
15
 
15
16
  DEPENDENCIES
data/README.md CHANGED
@@ -29,11 +29,13 @@ require 'gctime'
29
29
  >> 4.times { GC.start }
30
30
  => 4
31
31
  >> GCTime.total_time
32
- => 0.12742100000000012
32
+ => 127.42100000000012 # ms
33
33
  >> GCTime.disable
34
34
  => nil
35
35
  ```
36
36
 
37
+ `GCTime.total_time` returns a `Float` representing the total number of milliseconds spent in GC.
38
+
37
39
  ## Incompatibilities
38
40
 
39
41
  `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
@@ -43,6 +45,8 @@ Known incompatible gems are:
43
45
 
44
46
  - [`newrelic_rpm`](https://github.com/newrelic/newrelic-ruby-agent/blob/4baffe79b87e6ec725dfae9f5e76113a1f1d01ba/lib/new_relic/agent/vm/monotonic_gc_profiler.rb#L22-L38)
45
47
 
48
+ If you suspect that one of your gem might be using `GC::Profiler.clear`, you can check with `grep -R 'GC::Profiler.clear' $(bundle show --paths)`.
49
+
46
50
  ## Memory Leak
47
51
 
48
52
  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,
data/lib/gctime.rb CHANGED
@@ -6,23 +6,39 @@ module GCTime
6
6
  @mutex = Mutex.new
7
7
  @total_time = 0.0
8
8
 
9
- class << self
10
- def enable
11
- GC::Profiler.enable
12
- end
9
+ begin
10
+ GC.stat(:time) # Implemented on JRuby and TruffleRuby
11
+ class << self
12
+ def enable
13
+ end
14
+
15
+ def disable
16
+ end
13
17
 
14
- def disable
15
- GC::Profiler.disable
18
+ def total_time
19
+ GC.stat(:time).to_f
20
+ end
16
21
  end
22
+ rescue ArgumentError
23
+ # MRI Implementation
24
+ class << self
25
+ def enable
26
+ GC::Profiler.enable
27
+ end
28
+
29
+ def disable
30
+ GC::Profiler.disable
31
+ end
17
32
 
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
33
+ def total_time
34
+ if GC::Profiler.total_time > 0.0
35
+ @mutex.synchronize do
36
+ @total_time += GC::Profiler.total_time * 1_000.0
37
+ GC::Profiler.clear
38
+ end
23
39
  end
40
+ @total_time
24
41
  end
25
- @total_time
26
42
  end
27
43
  end
28
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GCTime
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gctime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-06 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/ci.yml"
20
21
  - ".gitignore"
21
22
  - Gemfile
22
23
  - Gemfile.lock