gvl_timing 0.2.0 → 0.3.1

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: c074fa63b689a97efe9aace8d5771f2d028c624f321375999cfc2f65e88a90ce
4
+ data.tar.gz: b33d3f6aa788576f5f7265c9336a4f4dabf916a84608e7af3f85d087a6551b1d
5
5
  SHA512:
6
- metadata.gz: 89b22673ab84fba5fb065f34180fbe8bd83b23b77432f60e0736bd7f5a137fc0c285aff73f8527207ffd6ec3593301e434047a7dbd70f3b80c19bf265f2b6dd5
7
- data.tar.gz: '09fcfe0991aa902049de16ac2b3e9d8cfe5f9142641258cddcb6b60d8159b00636579231a70a7ccb09544977e415dadc5bc9334b0513db4e9b4eac06316028ad'
6
+ metadata.gz: 447646c28a9412850137bfca22152c51fe8c002fea31fda3f2b3e999c7f628d699eb09360a451edc7f03621e4dd8a3c0a13854c40cc16ee779f3d7b44ad69abb
7
+ data.tar.gz: ae1217aa724bbc0f1672ce98573af54d54a4e25dc4d413ffa9bd461ef0f0de0ab7ae638b906d130e4edacfcbbc01e57ad836187af9c8d010196f7a682395b15f
@@ -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.1"
5
5
  end
data/lib/gvl_timing.rb CHANGED
@@ -10,8 +10,11 @@ module GVLTiming
10
10
  def measure
11
11
  timer = Timer.new
12
12
  timer.start
13
- yield
14
- timer.stop
13
+ begin
14
+ yield
15
+ ensure
16
+ timer.stop
17
+ end
15
18
  timer
16
19
  end
17
20
  alias_method :time, :measure
@@ -31,7 +34,7 @@ module GVLTiming
31
34
  [
32
35
  :duration, :cpu_duration,
33
36
  :monotonic_start, :monotonic_stop,
34
- :cputime_start, :cputime_start,
37
+ :cputime_start, :cputime_stop,
35
38
  :running_duration, :stalled_duration, :idle_duration
36
39
  ].each do |name|
37
40
  class_eval <<~RUBY
@@ -41,13 +44,15 @@ module GVLTiming
41
44
  RUBY
42
45
  end
43
46
 
47
+ alias releases_count yields_count
44
48
 
45
49
  def inspect
46
- "#<#{self.class} total=%.2fs running=%.2fs idle=%.2fs stalled=%.2fs>" % [
50
+ "#<#{self.class} total=%.2fs running=%.2fs idle=%.2fs stalled=%.2fs yields=%d>" % [
47
51
  duration,
48
52
  running_duration,
49
53
  idle_duration,
50
54
  stalled_duration,
55
+ yields_count,
51
56
  ]
52
57
  end
53
58
 
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.1
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: 1980-01-02 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.7
56
53
  specification_version: 4
57
54
  summary: Measure time spent in different GVL states
58
55
  test_files: []