dbg_tags 1.1.1 → 1.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/lib/dbg_tags.rb +49 -4
- data/spec/01_tag_spec.rb +71 -17
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8e0401ca437e4c46fe63c0fa1aeb0a952e0bb26bb9470b72cf630201cc9e0fd
|
|
4
|
+
data.tar.gz: a148a7f14a0a8eeac1109f00ec9a8f0b768f391c2c218f1fc03fa3b61c8abed2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82fa4fd016e062e9901d306dc44597ddf6eaad44201721ea874228e59114eb371e4322d3799c6e1aab1fda467534490f32109fb26ff0aa09db48368e485ae3be
|
|
7
|
+
data.tar.gz: cb6d061257ee53ddb4962468aa03dd507499a4aebe400483818210b729c04c4af0eca967617fe8d594deead9500aef05ae068a7e379c38c8728b29ddc0113e9c
|
data/lib/dbg_tags.rb
CHANGED
|
@@ -187,14 +187,41 @@ module Tag
|
|
|
187
187
|
|
|
188
188
|
class << self
|
|
189
189
|
|
|
190
|
+
private # class methods of Tag
|
|
191
|
+
|
|
192
|
+
# @param value [Bool] Value to set
|
|
193
|
+
# Primarily for rspec stuff. Use {disable_thread_local_state} instead
|
|
194
|
+
def no_thread_local_state= value
|
|
195
|
+
@no_thread_local_state = value
|
|
196
|
+
end # Tag::no_thread_local_state=
|
|
197
|
+
|
|
190
198
|
public # class methods of Tag
|
|
191
199
|
|
|
192
|
-
# @return [
|
|
200
|
+
# @return [Bool,nil] True if we should store global state inside the Tag class itself.
|
|
201
|
+
attr :no_thread_local_state
|
|
202
|
+
alias no_thread_local_state? no_thread_local_state
|
|
203
|
+
|
|
204
|
+
# DEPRECATED
|
|
205
|
+
alias no_fiber_local_state? no_thread_local_state? # for B.C.
|
|
206
|
+
|
|
207
|
+
# @return [Bool] True (the default) if we should store global state
|
|
208
|
+
# in each thread of the application.
|
|
209
|
+
def use_thread_local_state?; !no_thread_local_state? end
|
|
210
|
+
|
|
211
|
+
# DEPRECATED
|
|
212
|
+
alias use_fiber_local_state? use_thread_local_state? # for B.C.
|
|
213
|
+
|
|
214
|
+
# @return [GlobalState] Either thread local data (default) or truly global.
|
|
193
215
|
def global_state
|
|
194
|
-
if
|
|
195
|
-
|
|
216
|
+
if @no_thread_local_state
|
|
217
|
+
@global_state ||= GlobalState.new
|
|
196
218
|
else
|
|
197
|
-
Thread.current
|
|
219
|
+
ct = Thread.current
|
|
220
|
+
unless state = ct.thread_variable_get(:dbg_tags_global_state)
|
|
221
|
+
state = GlobalState.new
|
|
222
|
+
ct.thread_variable_set :dbg_tags_global_state, state
|
|
223
|
+
end
|
|
224
|
+
state
|
|
198
225
|
end
|
|
199
226
|
end # Tag::global_state
|
|
200
227
|
|
|
@@ -278,5 +305,23 @@ module Tag
|
|
|
278
305
|
# @return [bool] Reflects explicit enable calls only. The :all feature is IGNORED
|
|
279
306
|
def enabled? feature; (global_state.enabled[feature] || NONE) > NONE; end
|
|
280
307
|
|
|
308
|
+
# shortcut for no_thread_local_state = true
|
|
309
|
+
# By default thread local state is enabled and this means that
|
|
310
|
+
# 'enabling' of tags in some thread does effect in others.
|
|
311
|
+
# So: when using threads leave this enabled, as it will cause race conditions
|
|
312
|
+
# otherwise.
|
|
313
|
+
# When not using threads, it is more efficient to disable it.
|
|
314
|
+
def disable_thread_local_state; self.no_thread_local_state = true end
|
|
315
|
+
|
|
316
|
+
# DEPRECATED
|
|
317
|
+
alias disable_fiber_local_state disable_thread_local_state # for B.C.
|
|
318
|
+
|
|
319
|
+
# shortcut for no_thread_local_state := false
|
|
320
|
+
# For rspec use mostly.
|
|
321
|
+
def enable_thread_local_state; self.no_thread_local_state = false end
|
|
322
|
+
|
|
323
|
+
# DEPRECATED
|
|
324
|
+
alias enable_fiber_local_state enable_thread_local_state # for B.C.
|
|
325
|
+
|
|
281
326
|
end # singleton class Tag
|
|
282
327
|
end # module Tag
|
data/spec/01_tag_spec.rb
CHANGED
|
@@ -255,6 +255,7 @@ describe 'tag' do
|
|
|
255
255
|
end # context 'Nested levels'
|
|
256
256
|
|
|
257
257
|
it 'has thread local data to prevent mix ups (tag_300)' do
|
|
258
|
+
Tag.enable_thread_local_state # NOTE enabled by default, but other examples may botch it
|
|
258
259
|
t1 = Thread.new do
|
|
259
260
|
Tag.enable threads: :trc do
|
|
260
261
|
Tag.trc(:threads) {
|
|
@@ -274,49 +275,101 @@ describe 'tag' do
|
|
|
274
275
|
end # it
|
|
275
276
|
|
|
276
277
|
it 'each thread has a private tag system (tag_301)' do
|
|
278
|
+
Tag.enable_thread_local_state # NOTE enabled by default, but other examples may botch it
|
|
279
|
+
executed = false
|
|
277
280
|
Tag.enable threads: :trc do
|
|
278
|
-
expect(Tag.enabled).to eq({threads:
|
|
281
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
279
282
|
t1 = Thread.new do
|
|
280
283
|
expect(Tag.enabled).to eq({})
|
|
281
284
|
Tag.enable threads: :log do
|
|
282
|
-
expect(Tag.enabled).to eq({threads:
|
|
283
|
-
Tag.
|
|
285
|
+
expect(Tag.enabled).to eq({threads: Tag::LOG})
|
|
286
|
+
Tag.log(:threads) {
|
|
284
287
|
expect(Tag.inside?).to be true
|
|
285
288
|
sleep 1
|
|
289
|
+
executed = true
|
|
286
290
|
nil
|
|
287
291
|
}
|
|
288
292
|
end
|
|
289
293
|
end
|
|
290
294
|
t1.join
|
|
291
|
-
expect(Tag.enabled).to eq({threads:
|
|
295
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
292
296
|
end
|
|
297
|
+
expect(executed).to be true
|
|
293
298
|
end # it
|
|
294
299
|
|
|
295
|
-
it 'each
|
|
300
|
+
it 'each thread has a private tag system (tag_302)' do
|
|
301
|
+
Tag.enable_thread_local_state # NOTE enabled by default, but other examples may botch it
|
|
302
|
+
executed = false
|
|
296
303
|
Tag.enable threads: :trc do
|
|
297
|
-
expect(Tag.enabled).to eq({threads:
|
|
298
|
-
t1 =
|
|
304
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
305
|
+
t1 = Thread.new do
|
|
299
306
|
expect(Tag.enabled).to eq({})
|
|
300
307
|
Tag.enable threads: :log do
|
|
301
|
-
expect(Tag.enabled).to eq({threads:
|
|
302
|
-
Tag.
|
|
308
|
+
expect(Tag.enabled).to eq({threads: Tag::LOG})
|
|
309
|
+
Tag.log(:threads) {
|
|
303
310
|
expect(Tag.inside?).to be true
|
|
304
|
-
|
|
311
|
+
executed = true
|
|
312
|
+
nil
|
|
313
|
+
}
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
t1.join
|
|
317
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
318
|
+
end
|
|
319
|
+
expect(executed).to be true
|
|
320
|
+
end # it
|
|
321
|
+
|
|
322
|
+
it 'Fibers share the tag state (tag_303)' do
|
|
323
|
+
Tag.enable_thread_local_state # NOTE enabled by default, but other examples may botch it
|
|
324
|
+
executed = false
|
|
325
|
+
Tag.enable threads: :trc do
|
|
326
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
327
|
+
t1 = Fiber.new do
|
|
328
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
329
|
+
Tag.enable threads: :log do
|
|
330
|
+
expect(Tag.enabled).to eq({threads: Tag::LOG})
|
|
331
|
+
Tag.log(:threads) {
|
|
332
|
+
expect(Tag.inside?).to be true
|
|
333
|
+
executed = true
|
|
305
334
|
nil
|
|
306
335
|
}
|
|
307
336
|
end
|
|
308
337
|
end
|
|
309
338
|
t1.resume
|
|
310
|
-
expect(Tag.enabled).to eq({threads:
|
|
339
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
311
340
|
end
|
|
341
|
+
expect(executed).to be true
|
|
312
342
|
end # it
|
|
313
343
|
|
|
314
|
-
it '
|
|
344
|
+
it 'allows to disable thread local state (tag_305)' do
|
|
345
|
+
Tag.disable_thread_local_state
|
|
346
|
+
executed = false
|
|
347
|
+
Tag.enable threads: :trc do
|
|
348
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
349
|
+
t1 = Thread.new do
|
|
350
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
351
|
+
Tag.enable threads: :log do
|
|
352
|
+
expect(Tag.enabled).to eq({threads: Tag::LOG})
|
|
353
|
+
Tag.log(:threads) {
|
|
354
|
+
expect(Tag.inside?).to be true
|
|
355
|
+
executed = true
|
|
356
|
+
nil
|
|
357
|
+
}
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
t1.join
|
|
361
|
+
expect(Tag.enabled).to eq({threads: Tag::TRC})
|
|
362
|
+
expect(executed).to be true
|
|
363
|
+
end
|
|
364
|
+
end # it
|
|
365
|
+
|
|
366
|
+
it 'does allow restore_state to transfer state into a Thread (tag_310)' do
|
|
367
|
+
Tag.enable_thread_local_state
|
|
315
368
|
did_something = false
|
|
316
369
|
Tag.enable example: :dtl, fiber: :trc do
|
|
317
370
|
state = Tag.state # same as Tag.enabled
|
|
318
371
|
expect(state).to eq({example: Tag::DTL, fiber: Tag::TRC})
|
|
319
|
-
t1 =
|
|
372
|
+
t1 = Thread.new do
|
|
320
373
|
expect(Tag.state).to eq({})
|
|
321
374
|
Tag.enable foo: :trc
|
|
322
375
|
Tag.restore_state state do
|
|
@@ -324,17 +377,18 @@ describe 'tag' do
|
|
|
324
377
|
did_something = true
|
|
325
378
|
end
|
|
326
379
|
end
|
|
327
|
-
t1.
|
|
380
|
+
t1.join
|
|
328
381
|
expect(Tag.state).to eq({example: Tag::DTL, fiber: Tag::TRC})
|
|
329
382
|
end # enable
|
|
330
383
|
expect(did_something).to be true
|
|
331
384
|
end # it
|
|
332
385
|
|
|
333
|
-
it 'does allow a nil-state to transfer
|
|
386
|
+
it 'does allow a nil-state to transfer into a Thread (tag_311)' do
|
|
387
|
+
Tag.enable_thread_local_state
|
|
334
388
|
did_something = false
|
|
335
389
|
state = Tag.state
|
|
336
390
|
expect(state).to eq({})
|
|
337
|
-
t1 =
|
|
391
|
+
t1 = Thread.new do
|
|
338
392
|
expect(Tag.state).to eq({})
|
|
339
393
|
Tag.enable foo: :trc
|
|
340
394
|
Tag.restore_state state do
|
|
@@ -342,7 +396,7 @@ describe 'tag' do
|
|
|
342
396
|
did_something = true
|
|
343
397
|
end
|
|
344
398
|
end
|
|
345
|
-
t1.
|
|
399
|
+
t1.join
|
|
346
400
|
expect(Tag.state).to eq({})
|
|
347
401
|
expect(did_something).to be true
|
|
348
402
|
end # it
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dbg_tags
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eugene Brazwick
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -66,7 +66,7 @@ homepage: https://github.com/Eugene-Brazwick/dbg_tags
|
|
|
66
66
|
licenses:
|
|
67
67
|
- GPL-3.0
|
|
68
68
|
metadata: {}
|
|
69
|
-
post_install_message:
|
|
69
|
+
post_install_message:
|
|
70
70
|
rdoc_options: []
|
|
71
71
|
require_paths:
|
|
72
72
|
- lib
|
|
@@ -81,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
83
|
requirements: []
|
|
84
|
-
rubygems_version: 3.
|
|
85
|
-
signing_key:
|
|
84
|
+
rubygems_version: 3.4.20
|
|
85
|
+
signing_key:
|
|
86
86
|
specification_version: 4
|
|
87
87
|
summary: a versatile dynamic debug tracing system
|
|
88
88
|
test_files:
|