gvl_timing 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db733cb6bbf991888c58e4d4aede834efaaec117a02c7ca2822f19ef1c842eec
4
- data.tar.gz: a86891666732c57f85b46e9eaf8fb88cc5f265449a282f6d1bc1e444b4dd6ac4
3
+ metadata.gz: 11943fd2bd229bb71b905436ff49735fa683355107e773798a0c265e91dc51c9
4
+ data.tar.gz: 28e2c52c9d4aa6eb9d9346c4bf85398c41d70f7cd8dfd70699f3618340779979
5
5
  SHA512:
6
- metadata.gz: 89b22673ab84fba5fb065f34180fbe8bd83b23b77432f60e0736bd7f5a137fc0c285aff73f8527207ffd6ec3593301e434047a7dbd70f3b80c19bf265f2b6dd5
7
- data.tar.gz: '09fcfe0991aa902049de16ac2b3e9d8cfe5f9142641258cddcb6b60d8159b00636579231a70a7ccb09544977e415dadc5bc9334b0513db4e9b4eac06316028ad'
6
+ metadata.gz: ca21dea3e3d9d8bc9b4c46a76c32d33aa7e501f4b56c28f4543e46374e8e5341d90950dc18381f841011fd65cfbc4a47df280e5cec6297655991300574d31ac4
7
+ data.tar.gz: dfa75b00eac2c2c0e23d9c4acbb816a6c3f18224405bfacf40345c6d9d59e0ab22691f3697f70934ca13387520f050aa7d8fc3d706c1d6a2a1bc52cabc34b348
@@ -7,4 +7,7 @@ require "mkmf"
7
7
  # selectively, or entirely remove this flag.
8
8
  append_cflags("-fvisibility=hidden")
9
9
 
10
+ have_header("ruby/thread.h")
11
+ have_struct_member("rb_internal_thread_event_data_t", "thread", ["ruby/thread.h"])
12
+
10
13
  create_makefile("gvl_timing/gvl_timing")
@@ -26,6 +26,8 @@ struct gvl_timer {
26
26
  uint64_t cputime_start;
27
27
  uint64_t cputime_stop;
28
28
 
29
+ uint64_t yields_count;
30
+
29
31
  uint64_t prev_timestamp;
30
32
  enum ruby_gvl_state prev_state;
31
33
  VALUE thread;
@@ -40,16 +42,23 @@ void record_timing(struct gvl_timer *timer, enum ruby_gvl_state new_state) {
40
42
  timer->timings[timer->prev_state] += (timestamp - timer->prev_timestamp);
41
43
  timer->prev_timestamp = timestamp;
42
44
  timer->prev_state = new_state;
45
+
46
+ if (new_state == GVL_STATE_IDLE) {
47
+ timer->yields_count++;
48
+ }
49
+
43
50
  }
44
51
 
45
52
  void internal_thread_event_cb(rb_event_flag_t event, const rb_internal_thread_event_data_t *event_data, void *data) {
46
53
  struct gvl_timer *timer = data;
47
54
 
55
+ VALUE thread;
56
+ #if HAVE_RB_INTERNAL_THREAD_EVENT_DATA_T_THREAD
57
+ thread = event_data->thread;
58
+ #else
48
59
  if (!ruby_native_thread_p()) return;
49
- VALUE thread = rb_thread_current();
50
- //#if HAVE_RB_INTERNAL_THREAD_EVENT_DATA_T_THREAD
51
- //#else
52
- //#endif
60
+ thread = rb_thread_current();
61
+ #endif
53
62
  if (thread != timer->thread) {
54
63
  return;
55
64
  }
@@ -150,6 +159,10 @@ VALUE gvl_timer_idle_duration(VALUE obj) {
150
159
  return ULL2NUM(get_timer(obj)->timings[GVL_STATE_IDLE]);
151
160
  }
152
161
 
162
+ VALUE gvl_timer_yields_count(VALUE obj) {
163
+ return ULL2NUM(get_timer(obj)->yields_count);
164
+ }
165
+
153
166
  RUBY_FUNC_EXPORTED void
154
167
  Init_gvl_timing(void)
155
168
  {
@@ -167,4 +180,6 @@ Init_gvl_timing(void)
167
180
  rb_define_method(rb_cTimer, "running_duration_ns", gvl_timer_running_duration, 0);
168
181
  rb_define_method(rb_cTimer, "stalled_duration_ns", gvl_timer_stalled_duration, 0);
169
182
  rb_define_method(rb_cTimer, "idle_duration_ns", gvl_timer_idle_duration, 0);
183
+
184
+ rb_define_method(rb_cTimer, "yields_count", gvl_timer_yields_count, 0);
170
185
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GVLTiming
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/gvl_timing.rb CHANGED
@@ -31,7 +31,7 @@ module GVLTiming
31
31
  [
32
32
  :duration, :cpu_duration,
33
33
  :monotonic_start, :monotonic_stop,
34
- :cputime_start, :cputime_start,
34
+ :cputime_start, :cputime_stop,
35
35
  :running_duration, :stalled_duration, :idle_duration
36
36
  ].each do |name|
37
37
  class_eval <<~RUBY
@@ -41,13 +41,15 @@ module GVLTiming
41
41
  RUBY
42
42
  end
43
43
 
44
+ alias releases_count yields_count
44
45
 
45
46
  def inspect
46
- "#<#{self.class} total=%.2fs running=%.2fs idle=%.2fs stalled=%.2fs>" % [
47
+ "#<#{self.class} total=%.2fs running=%.2fs idle=%.2fs stalled=%.2fs yields=%d>" % [
47
48
  duration,
48
49
  running_duration,
49
50
  idle_duration,
50
51
  stalled_duration,
52
+ yields_count,
51
53
  ]
52
54
  end
53
55
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvl_timing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
10
+ date: 2025-04-18 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Measure time spent in different GVL states
14
13
  email:
@@ -36,7 +35,6 @@ metadata:
36
35
  homepage_uri: https://github.com/jhawthorn/gvl_timing
37
36
  source_code_uri: https://github.com/jhawthorn/gvl_timing
38
37
  changelog_uri: https://github.com/jhawthorn/gvl_timing
39
- post_install_message:
40
38
  rdoc_options: []
41
39
  require_paths:
42
40
  - lib
@@ -51,8 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
49
  - !ruby/object:Gem::Version
52
50
  version: '0'
53
51
  requirements: []
54
- rubygems_version: 3.4.19
55
- signing_key:
52
+ rubygems_version: 3.6.2
56
53
  specification_version: 4
57
54
  summary: Measure time spent in different GVL states
58
55
  test_files: []