google-cloud-debugger 0.25.0 → 0.26.1

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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heng Xiong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: google-cloud-logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: google-gax
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.1'
75
+ version: '1.2'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.1'
82
+ version: '1.2'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: minitest
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -255,7 +269,6 @@ files:
255
269
  - lib/google-cloud-debugger.rb
256
270
  - lib/google/cloud/debugger.rb
257
271
  - lib/google/cloud/debugger/agent.rb
258
- - lib/google/cloud/debugger/async_actor.rb
259
272
  - lib/google/cloud/debugger/breakpoint.rb
260
273
  - lib/google/cloud/debugger/breakpoint/evaluator.rb
261
274
  - lib/google/cloud/debugger/breakpoint/source_location.rb
@@ -1,290 +0,0 @@
1
- # Copyright 2017 Google Inc. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require "set"
16
-
17
-
18
- module Google
19
- module Cloud
20
- module Debugger
21
- ##
22
- # # AsyncActor
23
- #
24
- # @private An module that provides a class asynchronous capability when
25
- # included. It can create a child thread to run background jobs, and
26
- # help make sure the child thread terminates properly when process
27
- # is interrupted.
28
- #
29
- # To use AsyncActor, the classes that are including this module need to
30
- # define a run_backgrounder method that does the background job. The
31
- # classes can then control the child thread job through instance methods
32
- # like async_start, async_stop, etc.
33
- #
34
- # @example
35
- # class Foo
36
- # include AsyncActor
37
- #
38
- # def initialize
39
- # super()
40
- # end
41
- #
42
- # def run_backgrounder
43
- # # run async job
44
- # end
45
- # end
46
- #
47
- # foo = Foo.new
48
- # foo.async_start
49
- #
50
- module AsyncActor
51
- include MonitorMixin
52
-
53
- CLEANUP_TIMEOUT = 10.0
54
- WAIT_INTERVAL = 1.0
55
-
56
- @cleanup_list = nil
57
- @exit_lock = Monitor.new
58
-
59
- ##
60
- # @private The async actor state
61
- attr_reader :async_state
62
-
63
- ##
64
- # Starts the child thread and asynchronous job
65
- def async_start
66
- ensure_thread
67
- end
68
-
69
- ##
70
- # Nicely ask the child thread to stop by setting the state to
71
- # :stopping if it's not stopped already.
72
- #
73
- # @return [Boolean] False if child thread is already stopped. Otherwise
74
- # true.
75
- def async_stop
76
- ensure_thread
77
- synchronize do
78
- if async_state != :stopped
79
- @async_state = :stopping
80
- @lock_cond.broadcast
81
- true
82
- else
83
- false
84
- end
85
- end
86
- end
87
-
88
- ##
89
- # Set the state to :suspend if the current state is :running.
90
- #
91
- # @return [Boolean] Returns true if the state has been set to
92
- # :suspended. Otherwise return false.
93
- #
94
- def async_suspend
95
- ensure_thread
96
- synchronize do
97
- if async_state == :running
98
- @async_state = :suspended
99
- @lock_cond.broadcast
100
- true
101
- else
102
- false
103
- end
104
- end
105
- end
106
-
107
- ##
108
- # Set the state to :running if the current state is :suspended.
109
- #
110
- # @return [Boolean] True if the state has been set to :running.
111
- # Otherwise return false.
112
- #
113
- def async_resume
114
- ensure_thread
115
- synchronize do
116
- if async_state == :suspended
117
- @async_state = :running
118
- @lock_cond.broadcast
119
- true
120
- else
121
- false
122
- end
123
- end
124
- end
125
-
126
- ##
127
- # Check if async job is running
128
- #
129
- # @return [Boolean] True if state equals :running. Otherwise false.
130
- def async_running?
131
- synchronize do
132
- async_state == :running
133
- end
134
- end
135
-
136
- ##
137
- # Check if async job is suspended
138
- #
139
- # @return [Boolean] True if state equals :suspended. Otherwise false.
140
- def async_suspended?
141
- synchronize do
142
- async_state == :suspended
143
- end
144
- end
145
-
146
- ##
147
- # Check if async job is working.
148
- #
149
- # @return [Boolean] True if state is either :running or :suspended.
150
- # Otherwise false.
151
- def async_working?
152
- synchronize do
153
- async_state == :suspended || async_state == :running
154
- end
155
- end
156
-
157
- ##
158
- # Check if async job has stopped
159
- #
160
- # @return [Boolean] True if state equals :stopped. Otherwise false.
161
- def async_stopped?
162
- synchronize do
163
- async_state == :stopped
164
- end
165
- end
166
-
167
- ##
168
- # Ask async job to stop. Then forcefully kill thread if it doesn't stop
169
- # after timeout if needed.
170
- #
171
- # @param [Boolean] force If true, forcefully kill thread after timeout.
172
- # Default to false.
173
- #
174
- # @return [Symbol] :stopped if async job already stopped. :waited if
175
- # async job terminates within timeout range. :timeout if async job
176
- # doesn't terminate after timeout. :forced if thread is killed by
177
- # force after timeout.
178
- def async_stop! timeout, force: false
179
- return :stopped unless async_stop
180
- return :waited if wait_until_async_stopped timeout
181
- return :timeout unless force
182
- @thread.kill
183
- @thread.join
184
- :forced
185
- end
186
-
187
- ##
188
- # @private Cleanup this async job when process exists
189
- #
190
- def self.register_for_cleanup actor
191
- @exit_lock.synchronize do
192
- unless @cleanup_list
193
- @cleanup_list = []
194
- at_exit { run_cleanup }
195
- end
196
- @cleanup_list.push actor
197
- end
198
- end
199
-
200
- ##
201
- # @private Take this async job off exit cleanup list
202
- #
203
- def self.unregister_for_cleanup actor
204
- @exit_lock.synchronize do
205
- @cleanup_list.delete actor if @cleanup_list
206
- end
207
- end
208
-
209
- ##
210
- # @private Cleanup the async job
211
- #
212
- def self.run_cleanup
213
- @exit_lock.synchronize do
214
- if @cleanup_list
215
- until @cleanup_list.empty?
216
- @cleanup_list.shift.async_stop! CLEANUP_TIMEOUT, force: true
217
- end
218
- end
219
- end
220
- end
221
-
222
- private_class_method :run_cleanup
223
-
224
- private
225
-
226
- ##
227
- # @private Helper method to async_stop! to wait for async job to
228
- # terminate.
229
- #
230
- # @return [Boolean] True if async job terminated. False if timeout.
231
- #
232
- def wait_until_async_stopped timeout = nil
233
- ensure_thread
234
- deadline = timeout ? ::Time.new.to_f + timeout : nil
235
- synchronize do
236
- until async_state == :stopped
237
- cur_time = ::Time.new.to_f
238
- return false if deadline && cur_time >= deadline
239
- interval = deadline ? deadline - cur_time : WAIT_INTERVAL
240
- interval = WAIT_INTERVAL if interval > WAIT_INTERVAL
241
- @lock_cond.wait interval
242
- end
243
- end
244
- true
245
- end
246
-
247
- ##
248
- # @private Constructor to initialize MonitorMixin
249
- #
250
- def initialize
251
- super()
252
- @startup_lock = Mutex.new
253
- end
254
-
255
- ##
256
- # @private Wrapper method for running the async job. It requires classes
257
- # that include AsyncActor module to define a run_backgrounder method.
258
- # Then it runs a loop that checks for the state is workable (:running
259
- # or :suspended), which calls the run_backgrounder method. It ensures
260
- # the state variable gets set to :stopped when this method exists.
261
- def async_run_job
262
- fail "run_backgrounder method not defined" unless
263
- respond_to? :run_backgrounder
264
- run_backgrounder while async_working?
265
- ensure
266
- @async_state = :stopped
267
- end
268
-
269
- ##
270
- # @private Ensures the child thread is started and kick off the job
271
- # to run async_run_job. Also make calls register_for_cleanup on the
272
- # async job to make sure it exits properly.
273
- def ensure_thread
274
- fail "async_actor not initialized" if @startup_lock.nil?
275
- @startup_lock.synchronize do
276
- if (@thread.nil? || !@thread.alive?) && @async_state != :stopped
277
- @lock_cond = new_cond
278
- AsyncActor.register_for_cleanup self
279
- @thread = Thread.new do
280
- async_run_job
281
- AsyncActor.unregister_for_cleanup self
282
- end
283
- @async_state = :running
284
- end
285
- end
286
- end
287
- end
288
- end
289
- end
290
- end