gctime 0.1.0 → 0.2.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 +4 -4
- data/.github/workflows/ci.yml +21 -0
- data/Gemfile.lock +2 -1
- data/README.md +5 -1
- data/lib/gctime.rb +28 -12
- data/lib/gctime/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 415713b61297b0808196eb07372db20deda2723a58c449ad2b9b9f5692a619c2
|
4
|
+
data.tar.gz: 7f0ffe0e2cc8f5472a5ddc4239bf5fb2eceb6d1a81a14088a00fc5b4546052b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
=>
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/gctime/version.rb
CHANGED
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.
|
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-
|
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
|