Module: Datadog::Profiling::Ext::DirInstanceMonkeyPatches

Defined in:
lib/datadog/profiling/ext/dir_monkey_patches.rb,
lib/datadog/profiling/ext/dir_monkey_patches.rb

Overview

Monkey patches for Dir (Ruby 3 version). See DirMonkeyPatches above for more details.

Instance Method Summary collapse

Instance Method Details

#children(*args, **kwargs, &block) ⇒ Object



314
315
316
317
318
319
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 314

def children(*args, &block)
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
  super
ensure
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
end

#each(*args, **kwargs, &block) ⇒ Object

See note on methods that yield above.



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 267

def each(*args, &block)
  if block
    begin
      # <-- Begin critical region
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
      super do |entry_name|
        Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
        # <-- We're safe now while running customer code
        yield entry_name
        # <-- We'll go back to the Dir internals, critical region again
        Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
      end
    ensure
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals # <-- End critical region
    end
  else
    # This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
    # other branch once it gets going.
    super
  end
end

#each_child(*args, **kwargs, &block) ⇒ Object

See note on methods that yield above.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 291

def each_child(*args, &block)
  if block
    begin
      # <-- Begin critical region
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
      super do |entry_name|
        Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
        # <-- We're safe now while running customer code
        yield entry_name
        # <-- We'll go back to the Dir internals, critical region again
        Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
      end
    ensure
      # <-- End critical region
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
    end
  else
    # This returns an enumerator. We don't want/need to intercede here, the enumerator will eventually call the
    # other branch once it gets going.
    super
  end
end

#pos(*args, **kwargs, &block) ⇒ Object



329
330
331
332
333
334
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 329

def pos(*args, &block)
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
  super
ensure
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
end

#tell(*args, **kwargs, &block) ⇒ Object



322
323
324
325
326
327
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 322

def tell(*args, &block)
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
  super
ensure
  Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
end