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



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

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.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 280

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.



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 304

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



342
343
344
345
346
347
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 342

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



335
336
337
338
339
340
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 335

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