Module: Datadog::Profiling::Ext::DirClassMonkeyPatches

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#[](*args, **kwargs, &block) ⇒ Object

Steep: Workaround that defines args, kwargs and block only for Ruby 3.x.



38
39
40
41
42
43
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 38

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

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



45
46
47
48
49
50
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 45

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

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

See note on methods that yield above.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 58

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

#empty?(*args, **kwargs, &block) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 81

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

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



88
89
90
91
92
93
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 88

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

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

See note on methods that yield above.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 96

def foreach(*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

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

See note on methods that yield above.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 120

def glob(*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
    begin
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_hold_signals
      super
    ensure
      Datadog::Profiling::Collectors::CpuAndWallTimeWorker._native_resume_signals
    end
  end
end

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



146
147
148
149
150
151
# File 'lib/datadog/profiling/ext/dir_monkey_patches.rb', line 146

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