procon_bypass_man 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +19 -6
- data/.github/workflows/gitleacks.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +5 -3
- data/README.md +28 -41
- data/Steepfile +0 -1
- data/bin/generate_default_app +10 -0
- data/docs/getting_started.md +102 -28
- data/docs/setup_raspi_by_mitamae.md +43 -2
- data/lib/procon_bypass_man/background/job_performer.rb +1 -2
- data/lib/procon_bypass_man/background/job_queue.rb +50 -0
- data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +2 -2
- data/lib/procon_bypass_man/background/jobs/concerns/job_performable.rb +16 -0
- data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb +43 -0
- data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +1 -1
- data/lib/procon_bypass_man/background.rb +3 -4
- data/lib/procon_bypass_man/bypass/bypass_command.rb +16 -20
- data/lib/procon_bypass_man/bypass/bypass_value.rb +6 -0
- data/lib/procon_bypass_man/bypass/procon_to_switch.rb +99 -0
- data/lib/procon_bypass_man/bypass/switch_to_procon.rb +66 -0
- data/lib/procon_bypass_man/bypass.rb +5 -109
- data/lib/procon_bypass_man/commands/print_boot_message_command.rb +0 -2
- data/lib/procon_bypass_man/configuration.rb +18 -39
- data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +12 -3
- data/lib/procon_bypass_man/procon/analog_stick_manipulator.rb +2 -0
- data/lib/procon_bypass_man/procon/layer_changer.rb +2 -0
- data/lib/procon_bypass_man/procon/macro.rb +3 -1
- data/lib/procon_bypass_man/procon/macro_builder.rb +2 -0
- data/lib/procon_bypass_man/procon/macro_registry.rb +2 -0
- data/lib/procon_bypass_man/procon/performance_measurement/last_bypass_at.rb +17 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurement_collection.rb +9 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb +101 -0
- data/lib/procon_bypass_man/procon/performance_measurement/procon_performance_span_transfer_job.rb +8 -0
- data/lib/procon_bypass_man/procon/performance_measurement/queue_over_process.rb +38 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_queue.rb +42 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_transfer_buffer.rb +39 -0
- data/lib/procon_bypass_man/procon/performance_measurement.rb +110 -0
- data/lib/procon_bypass_man/procon/suppress_rumble.rb +2 -0
- data/lib/procon_bypass_man/procon/user_operation.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/analog_stick.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/binary/inbound_procon_binary.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/rumble_binary.rb +2 -0
- data/lib/procon_bypass_man/procon.rb +26 -7
- data/lib/procon_bypass_man/procon_display/bypass_hook.rb +12 -0
- data/lib/procon_bypass_man/procon_display.rb +1 -0
- data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +26 -44
- data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +22 -24
- data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/task.rb +1 -5
- data/lib/procon_bypass_man/remote_macro/task_queue.rb +6 -10
- data/lib/procon_bypass_man/remote_macro.rb +2 -0
- data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +1 -1
- data/lib/procon_bypass_man/remote_pbm_action.rb +2 -0
- data/lib/procon_bypass_man/runner.rb +4 -10
- data/lib/procon_bypass_man/scheduler.rb +15 -6
- data/lib/procon_bypass_man/support/callbacks.rb +79 -34
- data/lib/procon_bypass_man/support/can_over_process.rb +60 -0
- data/lib/procon_bypass_man/support/gc.rb +8 -0
- data/lib/procon_bypass_man/support/http_client.rb +12 -6
- data/lib/procon_bypass_man/support/load_agv.rb +20 -0
- data/lib/procon_bypass_man/support/procon_performance_http_client.rb +7 -0
- data/lib/procon_bypass_man/support/renice_command.rb +17 -0
- data/lib/procon_bypass_man/support/retryable.rb +16 -0
- data/lib/procon_bypass_man/support/signal_handler.rb +1 -1
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/client.rb +2 -2
- data/lib/procon_bypass_man/worker.rb +32 -0
- data/lib/procon_bypass_man.rb +53 -10
- data/procon_bypass_man.gemspec +4 -2
- data/project_template/README.md +0 -5
- data/project_template/app.rb +17 -11
- data/project_template/app.rb.erb +59 -0
- data/project_template/lib/app_generator.rb +31 -0
- data/project_template/web.rb +1 -1
- data/sig/main.rbs +10 -52
- data/tmp/.keep +0 -0
- metadata +43 -10
- data/lib/procon_bypass_man/background/job_runner.rb +0 -45
- data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +0 -5
- data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +0 -16
- data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +0 -15
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -47
- data/lib/procon_bypass_man/io_monitor.rb +0 -108
- data/lib/procon_bypass_man/support/server_pool.rb +0 -46
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procon_bypass_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiikko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pbmenv
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: blue_green_process
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A programmable converter for Nintendo Switch Pro Controller
|
56
70
|
email:
|
57
71
|
- n905i.1214@gmail.com
|
@@ -76,6 +90,7 @@ files:
|
|
76
90
|
- Steepfile
|
77
91
|
- bin/console
|
78
92
|
- bin/dev_api_server.rb
|
93
|
+
- bin/generate_default_app
|
79
94
|
- bin/setup
|
80
95
|
- docs/getting_started.md
|
81
96
|
- docs/how_to_connect_procon.md
|
@@ -93,11 +108,10 @@ files:
|
|
93
108
|
- lib/procon_bypass_man.rb
|
94
109
|
- lib/procon_bypass_man/background.rb
|
95
110
|
- lib/procon_bypass_man/background/job_performer.rb
|
96
|
-
- lib/procon_bypass_man/background/
|
111
|
+
- lib/procon_bypass_man/background/job_queue.rb
|
97
112
|
- lib/procon_bypass_man/background/jobs/base_job.rb
|
98
113
|
- lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb
|
99
|
-
- lib/procon_bypass_man/background/jobs/concerns/
|
100
|
-
- lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb
|
114
|
+
- lib/procon_bypass_man/background/jobs/concerns/job_performable.rb
|
101
115
|
- lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb
|
102
116
|
- lib/procon_bypass_man/background/jobs/report_boot_job.rb
|
103
117
|
- lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb
|
@@ -105,7 +119,7 @@ files:
|
|
105
119
|
- lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb
|
106
120
|
- lib/procon_bypass_man/background/jobs/report_event_base_job.rb
|
107
121
|
- lib/procon_bypass_man/background/jobs/report_load_config_job.rb
|
108
|
-
- lib/procon_bypass_man/background/jobs/
|
122
|
+
- lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb
|
109
123
|
- lib/procon_bypass_man/background/jobs/report_reload_config_job.rb
|
110
124
|
- lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb
|
111
125
|
- lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb
|
@@ -124,7 +138,9 @@ files:
|
|
124
138
|
- lib/procon_bypass_man/buttons_setting_configuration/validator.rb
|
125
139
|
- lib/procon_bypass_man/bypass.rb
|
126
140
|
- lib/procon_bypass_man/bypass/bypass_command.rb
|
127
|
-
- lib/procon_bypass_man/bypass/
|
141
|
+
- lib/procon_bypass_man/bypass/bypass_value.rb
|
142
|
+
- lib/procon_bypass_man/bypass/procon_to_switch.rb
|
143
|
+
- lib/procon_bypass_man/bypass/switch_to_procon.rb
|
128
144
|
- lib/procon_bypass_man/commands.rb
|
129
145
|
- lib/procon_bypass_man/commands/print_boot_message_command.rb
|
130
146
|
- lib/procon_bypass_man/commands/print_message_command.rb
|
@@ -145,7 +161,6 @@ files:
|
|
145
161
|
- lib/procon_bypass_man/device_connection/spoofing_output_report_watcher.rb
|
146
162
|
- lib/procon_bypass_man/device_model.rb
|
147
163
|
- lib/procon_bypass_man/device_status.rb
|
148
|
-
- lib/procon_bypass_man/io_monitor.rb
|
149
164
|
- lib/procon_bypass_man/plugin/splatoon2/macro/charge_tansan_bomb.rb
|
150
165
|
- lib/procon_bypass_man/plugin/splatoon2/macro/dasei_cancel.rb
|
151
166
|
- lib/procon_bypass_man/plugin/splatoon2/macro/fast_return.rb
|
@@ -170,6 +185,14 @@ files:
|
|
170
185
|
- lib/procon_bypass_man/procon/macro_plugin_map.rb
|
171
186
|
- lib/procon_bypass_man/procon/macro_registry.rb
|
172
187
|
- lib/procon_bypass_man/procon/mode_registry.rb
|
188
|
+
- lib/procon_bypass_man/procon/performance_measurement.rb
|
189
|
+
- lib/procon_bypass_man/procon/performance_measurement/last_bypass_at.rb
|
190
|
+
- lib/procon_bypass_man/procon/performance_measurement/measurement_collection.rb
|
191
|
+
- lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb
|
192
|
+
- lib/procon_bypass_man/procon/performance_measurement/procon_performance_span_transfer_job.rb
|
193
|
+
- lib/procon_bypass_man/procon/performance_measurement/queue_over_process.rb
|
194
|
+
- lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
|
195
|
+
- lib/procon_bypass_man/procon/performance_measurement/span_transfer_buffer.rb
|
173
196
|
- lib/procon_bypass_man/procon/press_button_aware.rb
|
174
197
|
- lib/procon_bypass_man/procon/suppress_rumble.rb
|
175
198
|
- lib/procon_bypass_man/procon/user_operation.rb
|
@@ -185,6 +208,7 @@ files:
|
|
185
208
|
- lib/procon_bypass_man/procon/value_objects/procon_reader.rb
|
186
209
|
- lib/procon_bypass_man/procon/value_objects/rumble_binary.rb
|
187
210
|
- lib/procon_bypass_man/procon_display.rb
|
211
|
+
- lib/procon_bypass_man/procon_display/bypass_hook.rb
|
188
212
|
- lib/procon_bypass_man/procon_display/http_request.rb
|
189
213
|
- lib/procon_bypass_man/procon_display/http_response.rb
|
190
214
|
- lib/procon_bypass_man/procon_display/server.rb
|
@@ -210,18 +234,23 @@ files:
|
|
210
234
|
- lib/procon_bypass_man/scheduler.rb
|
211
235
|
- lib/procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler.rb
|
212
236
|
- lib/procon_bypass_man/support/callbacks.rb
|
237
|
+
- lib/procon_bypass_man/support/can_over_process.rb
|
213
238
|
- lib/procon_bypass_man/support/compress_array.rb
|
214
239
|
- lib/procon_bypass_man/support/cycle_sleep.rb
|
215
240
|
- lib/procon_bypass_man/support/device_mouse_finder.rb
|
216
241
|
- lib/procon_bypass_man/support/device_procon_finder.rb
|
242
|
+
- lib/procon_bypass_man/support/gc.rb
|
217
243
|
- lib/procon_bypass_man/support/http_client.rb
|
244
|
+
- lib/procon_bypass_man/support/load_agv.rb
|
218
245
|
- lib/procon_bypass_man/support/never_exit_accidentally.rb
|
219
246
|
- lib/procon_bypass_man/support/on_memory_cache.rb
|
247
|
+
- lib/procon_bypass_man/support/procon_performance_http_client.rb
|
220
248
|
- lib/procon_bypass_man/support/remote_macro_http_client.rb
|
249
|
+
- lib/procon_bypass_man/support/renice_command.rb
|
221
250
|
- lib/procon_bypass_man/support/report_http_client.rb
|
251
|
+
- lib/procon_bypass_man/support/retryable.rb
|
222
252
|
- lib/procon_bypass_man/support/safe_timeout.rb
|
223
253
|
- lib/procon_bypass_man/support/send_device_stats_http_client.rb
|
224
|
-
- lib/procon_bypass_man/support/server_pool.rb
|
225
254
|
- lib/procon_bypass_man/support/signal_handler.rb
|
226
255
|
- lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb
|
227
256
|
- lib/procon_bypass_man/support/uptime.rb
|
@@ -232,9 +261,12 @@ files:
|
|
232
261
|
- lib/procon_bypass_man/websocket/client.rb
|
233
262
|
- lib/procon_bypass_man/websocket/forever.rb
|
234
263
|
- lib/procon_bypass_man/websocket/watchdog.rb
|
264
|
+
- lib/procon_bypass_man/worker.rb
|
235
265
|
- procon_bypass_man.gemspec
|
236
266
|
- project_template/README.md
|
237
267
|
- project_template/app.rb
|
268
|
+
- project_template/app.rb.erb
|
269
|
+
- project_template/lib/app_generator.rb
|
238
270
|
- project_template/setting.yml
|
239
271
|
- project_template/systemd_units/pbm.service
|
240
272
|
- project_template/systemd_units/pbm_web.service
|
@@ -242,6 +274,7 @@ files:
|
|
242
274
|
- sig/README.md
|
243
275
|
- sig/main.rbs
|
244
276
|
- sig/on_memory_cache.rbs
|
277
|
+
- tmp/.keep
|
245
278
|
homepage: https://github.com/splaplapla/procon_bypass_man
|
246
279
|
licenses:
|
247
280
|
- MIT
|
@@ -257,7 +290,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
290
|
requirements:
|
258
291
|
- - ">="
|
259
292
|
- !ruby/object:Gem::Version
|
260
|
-
version:
|
293
|
+
version: 2.5.0
|
261
294
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
262
295
|
requirements:
|
263
296
|
- - ">="
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module ProconBypassMan
|
2
|
-
module Background
|
3
|
-
class JobRunner
|
4
|
-
MAX_QUEUE_SIZE = 100
|
5
|
-
|
6
|
-
def self.start!
|
7
|
-
new.start!
|
8
|
-
end
|
9
|
-
|
10
|
-
# for test
|
11
|
-
def stop!
|
12
|
-
return unless defined?(@thread)
|
13
|
-
@thread.kill
|
14
|
-
end
|
15
|
-
|
16
|
-
def start!
|
17
|
-
return if defined?(@thread)
|
18
|
-
@thread = Thread.new do
|
19
|
-
while(item = self.class.queue.pop)
|
20
|
-
begin
|
21
|
-
JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
|
22
|
-
sleep(1)
|
23
|
-
rescue => e
|
24
|
-
ProconBypassMan.logger.error(e)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.queue
|
32
|
-
@@queue ||= Queue.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.push(hash)
|
36
|
-
if queue.size > MAX_QUEUE_SIZE
|
37
|
-
ProconBypassMan.logger.error('Over queue size cap!!')
|
38
|
-
return
|
39
|
-
end
|
40
|
-
|
41
|
-
queue.push(hash)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module ProconBypassMan
|
2
|
-
module Background
|
3
|
-
module JobRunnable
|
4
|
-
def perform(*)
|
5
|
-
raise NotImplementedError, nil
|
6
|
-
end
|
7
|
-
|
8
|
-
def perform_async(*args)
|
9
|
-
ProconBypassMan::Background::JobRunner.push(
|
10
|
-
args: args,
|
11
|
-
reporter_class: self,
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class ProconBypassMan::ReportPressedButtonsJob < ProconBypassMan::BaseJob
|
2
|
-
extend ProconBypassMan::HasInternalApiSetting
|
3
|
-
|
4
|
-
# @param [String] body
|
5
|
-
def self.perform(body)
|
6
|
-
ProconBypassMan::ReportHttpClient.new(
|
7
|
-
path: path,
|
8
|
-
server_pool: server_pool,
|
9
|
-
).post(body: body, event_type: :internal)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.path
|
13
|
-
"/api/pressed_buttons"
|
14
|
-
end
|
15
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
class ProconBypassMan::Bypass
|
2
|
-
module UsbHidLogger
|
3
|
-
extend ProconBypassMan::Callbacks::ClassMethods
|
4
|
-
include ProconBypassMan::Callbacks
|
5
|
-
|
6
|
-
define_callbacks :send_gadget_to_procon
|
7
|
-
define_callbacks :send_procon_to_gadget
|
8
|
-
|
9
|
-
set_callback :send_gadget_to_procon, :after, :log_send_gadget_to_procon
|
10
|
-
set_callback :send_procon_to_gadget, :after, :log_procon_to_gadget
|
11
|
-
|
12
|
-
def log_send_gadget_to_procon
|
13
|
-
return unless bypass_value.to_text
|
14
|
-
|
15
|
-
if ProconBypassMan.config.verbose_bypass_log
|
16
|
-
ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
|
17
|
-
else
|
18
|
-
ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
|
19
|
-
ProconBypassMan.logger.debug { ">>> #{bypass_value.to_text}" }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def log_procon_to_gadget
|
25
|
-
return unless bypass_value.to_text
|
26
|
-
|
27
|
-
if ProconBypassMan.config.verbose_bypass_log
|
28
|
-
ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
|
29
|
-
else
|
30
|
-
ProconBypassMan.cache.fetch key: 'bypass_log', expires_in: 1 do
|
31
|
-
ProconBypassMan.logger.debug { "<<< #{bypass_value.to_text}" }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# TODO 別のコールバッククラスから実行したい
|
36
|
-
ProconBypassMan::ProconDisplay::Status.instance.current = bypass_value.binary.to_procon_reader.to_hash.dup
|
37
|
-
|
38
|
-
if ProconBypassMan.config.enable_reporting_pressed_buttons
|
39
|
-
ProconBypassMan.cache.fetch key: 'pressed_buttons_reporter', expires_in: 5 do
|
40
|
-
ProconBypassMan::ReportPressedButtonsJob.perform_async(
|
41
|
-
bypass_value.binary.to_procon_reader.to_hash
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module ProconBypassMan
|
2
|
-
class NullCounter
|
3
|
-
def initialize(label: )
|
4
|
-
end
|
5
|
-
|
6
|
-
def record(_)
|
7
|
-
end
|
8
|
-
|
9
|
-
def shutdown
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Counter
|
14
|
-
attr_accessor :label, :table, :previous_table, :active
|
15
|
-
|
16
|
-
def initialize(label: )
|
17
|
-
self.label = label
|
18
|
-
self.table = {}
|
19
|
-
self.previous_table = {}
|
20
|
-
self.active = true
|
21
|
-
end
|
22
|
-
|
23
|
-
# アクティブなバケットは1つだけ
|
24
|
-
def record(event_name)
|
25
|
-
key = Time.now.strftime("%S").to_i
|
26
|
-
if table[key].nil?
|
27
|
-
self.previous_table = table.values.first
|
28
|
-
self.table = {}
|
29
|
-
table[key] = {}
|
30
|
-
end
|
31
|
-
if table[key][event_name].nil?
|
32
|
-
table[key][event_name] = 1
|
33
|
-
else
|
34
|
-
table[key][event_name] += 1
|
35
|
-
end
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
def formatted_previous_table
|
40
|
-
t = previous_table.dup
|
41
|
-
start_function = t[:start_function] || 0
|
42
|
-
end_function = t[:end_function] || 0
|
43
|
-
eagain_wait_readable_on_read = t[:eagain_wait_readable_on_read] || 0
|
44
|
-
eagain_wait_readable_on_write = t[:eagain_wait_readable_on_write] || 0
|
45
|
-
"(#{(end_function / start_function.to_f * 100).floor(1)}%(#{end_function}/#{start_function}), loss: #{eagain_wait_readable_on_read}, #{eagain_wait_readable_on_write})"
|
46
|
-
end
|
47
|
-
|
48
|
-
def shutdown
|
49
|
-
self.active = false
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module IOMonitor
|
54
|
-
@@thread = nil
|
55
|
-
|
56
|
-
def self.new(label: )
|
57
|
-
return NullCounter.new(label: label) if not started?
|
58
|
-
|
59
|
-
counter = Counter.new(label: label)
|
60
|
-
@@list << counter
|
61
|
-
counter
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [Array<Counter>]
|
65
|
-
def self.targets
|
66
|
-
@@list
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.started?
|
70
|
-
!!@@thread
|
71
|
-
end
|
72
|
-
|
73
|
-
# ここで集計する
|
74
|
-
def self.start!
|
75
|
-
@@thread = Thread.start do
|
76
|
-
max_output_length = 0
|
77
|
-
loop do
|
78
|
-
list = @@list.select(&:active).dup
|
79
|
-
unless list.all? { |x| x&.previous_table.is_a?(Hash) }
|
80
|
-
sleep 0.5
|
81
|
-
next
|
82
|
-
end
|
83
|
-
|
84
|
-
line = list.map { |counter|
|
85
|
-
"#{counter.label}(#{counter.formatted_previous_table})"
|
86
|
-
}.join(", ")
|
87
|
-
max_output_length = line.length
|
88
|
-
sleep 0.7
|
89
|
-
|
90
|
-
if ENV["PBM_FOREGROUND"]
|
91
|
-
print "\r"
|
92
|
-
print " " * max_output_length
|
93
|
-
print "\r"
|
94
|
-
print line
|
95
|
-
end
|
96
|
-
ProconBypassMan.logger.debug { line }
|
97
|
-
break if $will_terminate_token
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.reset!
|
103
|
-
@@list = []
|
104
|
-
end
|
105
|
-
|
106
|
-
reset!
|
107
|
-
end
|
108
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module ProconBypassMan
|
2
|
-
class ServerPool
|
3
|
-
def initialize(servers: )
|
4
|
-
if servers.nil? || servers.empty?
|
5
|
-
return
|
6
|
-
end
|
7
|
-
|
8
|
-
@servers = servers
|
9
|
-
if @servers.size >= 1
|
10
|
-
@index = 0
|
11
|
-
else
|
12
|
-
@index = nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def pick
|
17
|
-
if @index.nil?
|
18
|
-
return @servers&.first
|
19
|
-
end
|
20
|
-
@servers[@index] or raise "bug!!!"
|
21
|
-
end
|
22
|
-
def server; pick; end
|
23
|
-
|
24
|
-
def next!
|
25
|
-
inc_index
|
26
|
-
if @servers[@index].nil?
|
27
|
-
reset
|
28
|
-
return
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def reset
|
35
|
-
@index = 0
|
36
|
-
end
|
37
|
-
|
38
|
-
def inc_index
|
39
|
-
@index = @index + 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
if $0 == __FILE__
|
45
|
-
ProconBypassMan::ServerPool.new(servers: ['http://example.com'])
|
46
|
-
end
|