gvl_timing 0.1.2 → 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: 6501413dc9601f05b7595fa0494ed21ef9de1638554ced822efb689f7970a51a
4
- data.tar.gz: 23ed94187a9048aa54bbbb33fcd20bbfa1c1e4169c788d65bcf4c9fc078ceedb
3
+ metadata.gz: db733cb6bbf991888c58e4d4aede834efaaec117a02c7ca2822f19ef1c842eec
4
+ data.tar.gz: a86891666732c57f85b46e9eaf8fb88cc5f265449a282f6d1bc1e444b4dd6ac4
5
5
  SHA512:
6
- metadata.gz: dacfe66754ee03d97d509f8c6c30243675e0663e53616972628cd58c0b5b02d73f6943d0c3803e8879e1e9273031cb42ff9e06565d706ed21784df75ec166725
7
- data.tar.gz: c4c3be6acf8a456e604ee29016f2f129621e1508955dff64671cce172ea727272f83caf90367af235f9d0535597f1b22fedfd24f26358b38183f0f310769ca94
6
+ metadata.gz: 89b22673ab84fba5fb065f34180fbe8bd83b23b77432f60e0736bd7f5a137fc0c285aff73f8527207ffd6ec3593301e434047a7dbd70f3b80c19bf265f2b6dd5
7
+ data.tar.gz: '09fcfe0991aa902049de16ac2b3e9d8cfe5f9142641258cddcb6b60d8159b00636579231a70a7ccb09544977e415dadc5bc9334b0513db4e9b4eac06316028ad'
data/README.md CHANGED
@@ -1,24 +1,30 @@
1
- # GvlTiming
1
+ # gvl\_timing
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Measures timings for the current thread's GVL state for CRuby.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gvl_timing`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ This will add some (small) overhead to all GVL activity, so may be better to
6
+ development/test or sampled use rather than continuous timing.
6
7
 
7
8
  ## Installation
8
9
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
10
  Install the gem and add to the application's Gemfile by executing:
12
11
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
12
+ $ bundle add gvl_timing
18
13
 
19
14
  ## Usage
20
15
 
21
- TODO: Write usage instructions here
16
+ ```
17
+ >> timer = GVLTiming.measure { sleep 0.1 }
18
+ => #<GVLTiming::Timer total=0.10s running=0.00s idle=0.10s stalled=0.00s>
19
+ >> timer.duration
20
+ => 0.101082
21
+ >> timer.cpu_duration
22
+ => 7.4667e-05
23
+ >> timer.idle_duration
24
+ => 0.101048
25
+ >> timer.stalled_duration
26
+ => 1.0e-06
27
+ ```
22
28
 
23
29
  ## Development
24
30
 
@@ -159,12 +159,12 @@ Init_gvl_timing(void)
159
159
  rb_define_method(rb_cTimer, "start", gvl_timer_start, 0);
160
160
  rb_define_method(rb_cTimer, "stop", gvl_timer_stop, 0);
161
161
 
162
- rb_define_method(rb_cTimer, "monotonic_start", gvl_timer_monotonic_start, 0);
163
- rb_define_method(rb_cTimer, "monotonic_stop", gvl_timer_monotonic_stop, 0);
164
- rb_define_method(rb_cTimer, "cputime_start", gvl_timer_cputime_start, 0);
165
- rb_define_method(rb_cTimer, "cputime_stop", gvl_timer_cputime_stop, 0);
166
-
167
- rb_define_method(rb_cTimer, "running_duration", gvl_timer_running_duration, 0);
168
- rb_define_method(rb_cTimer, "stalled_duration", gvl_timer_stalled_duration, 0);
169
- rb_define_method(rb_cTimer, "idle_duration", gvl_timer_idle_duration, 0);
162
+ rb_define_method(rb_cTimer, "monotonic_start_ns", gvl_timer_monotonic_start, 0);
163
+ rb_define_method(rb_cTimer, "monotonic_stop_ns", gvl_timer_monotonic_stop, 0);
164
+ rb_define_method(rb_cTimer, "cputime_start_ns", gvl_timer_cputime_start, 0);
165
+ rb_define_method(rb_cTimer, "cputime_stop_ns", gvl_timer_cputime_stop, 0);
166
+
167
+ rb_define_method(rb_cTimer, "running_duration_ns", gvl_timer_running_duration, 0);
168
+ rb_define_method(rb_cTimer, "stalled_duration_ns", gvl_timer_stalled_duration, 0);
169
+ rb_define_method(rb_cTimer, "idle_duration_ns", gvl_timer_idle_duration, 0);
170
170
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GVLTiming
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/gvl_timing.rb CHANGED
@@ -20,21 +20,58 @@ module GVLTiming
20
20
  class Timer
21
21
  NANOSECONDS_PER_SECOND_F = 1000000000.0
22
22
 
23
- def duration
24
- monotonic_stop - monotonic_start
23
+ def duration_ns
24
+ monotonic_stop_ns - monotonic_start_ns
25
25
  end
26
26
 
27
- def cpu_duration
28
- cputime_stop - cputime_start
27
+ def cpu_duration_ns
28
+ cputime_stop_ns - cputime_start_ns
29
29
  end
30
30
 
31
+ [
32
+ :duration, :cpu_duration,
33
+ :monotonic_start, :monotonic_stop,
34
+ :cputime_start, :cputime_start,
35
+ :running_duration, :stalled_duration, :idle_duration
36
+ ].each do |name|
37
+ class_eval <<~RUBY
38
+ def #{name}(unit = :float_second)
39
+ scale_ns(#{name}_ns, unit)
40
+ end
41
+ RUBY
42
+ end
43
+
44
+
31
45
  def inspect
32
46
  "#<#{self.class} total=%.2fs running=%.2fs idle=%.2fs stalled=%.2fs>" % [
33
- duration / NANOSECONDS_PER_SECOND_F,
34
- running_duration / NANOSECONDS_PER_SECOND_F,
35
- idle_duration / NANOSECONDS_PER_SECOND_F,
36
- stalled_duration / NANOSECONDS_PER_SECOND_F
47
+ duration,
48
+ running_duration,
49
+ idle_duration,
50
+ stalled_duration,
37
51
  ]
38
52
  end
53
+
54
+ private
55
+
56
+ def scale_ns(value_ns, unit)
57
+ case unit
58
+ when :float_second
59
+ value_ns / 1_000_000_000.0
60
+ when :float_millisecond
61
+ value_ns / 1_000_000.0
62
+ when :float_microsecond
63
+ value_ns / 1000.0
64
+ when :second
65
+ value_ns / 1_000_000_000
66
+ when :millisecond
67
+ value_ns / 1_000_000
68
+ when :microsecond
69
+ value_ns / 1000
70
+ when :nanosecond
71
+ value_ns
72
+ else
73
+ raise ArgumentError, "unexpected unit: #{unit.inspect}"
74
+ end
75
+ end
39
76
  end
40
77
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvl_timing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Report time spent in different GVL states
13
+ description: Measure time spent in different GVL states
14
14
  email:
15
15
  - john@hawthorn.email
16
16
  executables:
@@ -54,5 +54,5 @@ requirements: []
54
54
  rubygems_version: 3.4.19
55
55
  signing_key:
56
56
  specification_version: 4
57
- summary: Report time spent in different GVL states
57
+ summary: Measure time spent in different GVL states
58
58
  test_files: []