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



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

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.



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

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.



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

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



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

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



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

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