gvltools 0.2.0 → 0.3.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: ed2a6e0154120c8b048e3b92db8e6f6c4a87d2b653b105b90a06a171ca61895b
4
- data.tar.gz: a976aab0ebf0da04af47d53587c144b7e89eeeef8f078c5b115d037db0fe3f6b
3
+ metadata.gz: 5ffb320bec5fdc8a0d4940d8b370af1607a20383e1a9a8f939cc759588ca6627
4
+ data.tar.gz: 223bee0c124c17296b8386bbdda94406f91b84ad0adcf3acd09921424bb8eaf8
5
5
  SHA512:
6
- metadata.gz: baca86f153a68a90ca36213775bd22d5263325e98fdf3cd3332c4b3db953014c7c9a8e14c9ddee27ad0b19de5300065fd77d79d795d7ad8f931d45838f797921
7
- data.tar.gz: be738a183964c4b6e0ef4f9ff5b9aac5e1a9b983d3fffe38034a338416260dc8be5fd95fcc23fe35697c2cc9d79ab8b1e8689deb3907e07468fe8e9985247911
6
+ metadata.gz: 1c988c2e9d2c17925b178e4201f99530e75328cda648b3e3b50664e1d751ff5ad086139293a22dab5a54ae18e86bdd7d6e14064f4a4833eae18d3d948f134f20
7
+ data.tar.gz: 3b56ad91bf7784d0c61e4d321964eeaaae8ca97ec6c6c86c1934e8e95ad9d720b00933a7b0f7e91ec45e7ffd2a07665800c6f616250b7251318dc889a5ba94ca
data/.rubocop.yml CHANGED
@@ -22,6 +22,15 @@ Style/GlobalVars:
22
22
  Exclude:
23
23
  - ext/**/extconf.rb
24
24
 
25
+ Style/EmptyMethod:
26
+ Enabled: false
27
+
28
+ Style/IfUnlessModifier:
29
+ Enabled: false
30
+
31
+ Style/GuardClause:
32
+ Enabled: false
33
+
25
34
  Style/Documentation:
26
35
  Enabled: false
27
36
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-04-11
4
+
5
+ - Automatically reset the `WaitingThreads` counter when enabling it (#7).
6
+ - Disallow resetting the `WaitingThreads` counter when it is active (#7).
7
+
3
8
  ## [0.2.0] - 2023-03-28
4
9
 
5
10
  - Use C11 atomics instead of MRI's `rb_atomic_t`.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gvltools (0.2.0)
4
+ gvltools (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -93,12 +93,15 @@ static VALUE local_timer_reset(VALUE module) {
93
93
 
94
94
  // Thread counts
95
95
  static _Atomic counter_t waiting_threads_total = 0;
96
+ static _Atomic counter_t waiting_threads_current_generation = 1;
97
+ static THREAD_LOCAL_SPECIFIER counter_t waiting_threads_ready_generation = 0;
96
98
 
97
99
  static VALUE waiting_threads_count(VALUE module) {
98
100
  return ULL2NUM(waiting_threads_total);
99
101
  }
100
102
 
101
103
  static VALUE waiting_threads_reset(VALUE module) {
104
+ waiting_threads_current_generation++;
102
105
  waiting_threads_total = 0;
103
106
  return Qtrue;
104
107
  }
@@ -122,6 +125,7 @@ static void gt_thread_callback(rb_event_flag_t event, const rb_internal_thread_e
122
125
  if (!was_ready) was_ready = true;
123
126
 
124
127
  if (ENABLED(WAITING_THREADS)) {
128
+ waiting_threads_ready_generation = waiting_threads_current_generation;
125
129
  waiting_threads_total++;
126
130
  }
127
131
 
@@ -134,7 +138,9 @@ static void gt_thread_callback(rb_event_flag_t event, const rb_internal_thread_e
134
138
  if (!was_ready) break; // In case we registered the hook while some threads were already waiting on the GVL
135
139
 
136
140
  if (ENABLED(WAITING_THREADS)) {
137
- waiting_threads_total--;
141
+ if (waiting_threads_ready_generation == waiting_threads_current_generation) {
142
+ waiting_threads_total--;
143
+ }
138
144
  }
139
145
 
140
146
  if (ENABLED(TIMER_GLOBAL | TIMER_LOCAL)) {
@@ -172,6 +178,6 @@ void Init_instrumentation(void) {
172
178
  rb_define_singleton_method(rb_mLocalTimer, "monotonic_time", local_timer_monotonic_time, 0);
173
179
 
174
180
  VALUE rb_mWaitingThreads = rb_const_get(rb_mGVLTools, rb_intern("WaitingThreads"));
175
- rb_define_singleton_method(rb_mWaitingThreads, "reset", waiting_threads_reset, 0);
181
+ rb_define_singleton_method(rb_mWaitingThreads, "_reset", waiting_threads_reset, 0);
176
182
  rb_define_singleton_method(rb_mWaitingThreads, "count", waiting_threads_count, 0);
177
183
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GVLTools
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/gvltools.rb CHANGED
@@ -96,8 +96,27 @@ module GVLTools
96
96
  end
97
97
  alias_method :count, :count
98
98
 
99
+ def enable
100
+ unless enabled?
101
+ reset
102
+ end
103
+ super
104
+ end
105
+
106
+ def reset
107
+ if enabled?
108
+ raise Error, "can't reset WaitingThreads counter while it is active"
109
+ else
110
+ _reset
111
+ end
112
+ end
113
+
99
114
  private
100
115
 
116
+ def _reset
117
+ end
118
+ alias_method :_reset, :_reset # to be redefined from C.
119
+
101
120
  def metric
102
121
  WAITING_THREADS
103
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvltools
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
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-28 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.4.6
70
+ rubygems_version: 3.4.10
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Set of GVL instrumentation tools