Class: Ritsudo::Benchmark
- Inherits:
-
Object
- Object
- Ritsudo::Benchmark
- Defined in:
- lib/ritsudo/benchmark.rb
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
Instance Method Summary collapse
- #collect(url, wait:, sub_process_timeout:, driver_options:) ⇒ Object
- #collect_requests_wait_finish(driver, sub_process_timeout:) ⇒ Object
- #do(url, count: 5, wait: 1, sub_process_timeout: 3, driver_options: {}) ⇒ Object
- #drive(driver_options) {|driver| ... } ⇒ Object
-
#initialize(collector: Ritsudo::Collector.new) ⇒ Benchmark
constructor
A new instance of Benchmark.
Constructor Details
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
3 4 5 |
# File 'lib/ritsudo/benchmark.rb', line 3 def collector @collector end |
Instance Method Details
#collect(url, wait:, sub_process_timeout:, driver_options:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ritsudo/benchmark.rb', line 47 def collect(url, wait:, sub_process_timeout:, driver_options:) drive() do |driver| driver.get(url) sleep(wait) sleep(1) until driver.driver.execute_script("return window.performance.timing.loadEventEnd") requests = collect_requests_wait_finish(driver, sub_process_timeout: sub_process_timeout) @collector.add(requests) dom_content_loaded_script = "return window.performance.timing.domContentLoadedEventEnd - window.performance.timing.requestStart" dom_content_loaded = driver.driver.execute_script(dom_content_loaded_script) @collector.add_misc("Misc", "DomContentLoaded", dom_content_loaded) loaded_script = "return window.performance.timing.loadEventEnd - window.performance.timing.requestStart" loaded = driver.driver.execute_script(loaded_script) @collector.add_misc("Misc", "Loaded", loaded) end end |
#collect_requests_wait_finish(driver, sub_process_timeout:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ritsudo/benchmark.rb', line 26 def collect_requests_wait_finish(driver, sub_process_timeout:) = driver.manage.logs.get('performance') requests = Ritsudo::Request.grouping() Timeout.timeout(sub_process_timeout) do while requests.find(&:processing?) sleep(0.5) = driver.manage.logs.get('performance') + requests = Ritsudo::Request.grouping() end end requests rescue Timeout::Error requests end |
#do(url, count: 5, wait: 1, sub_process_timeout: 3, driver_options: {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ritsudo/benchmark.rb', line 8 def do(url, count: 5, wait: 1, sub_process_timeout: 3, driver_options: {}) if [:cookies] puts <<-EOS WARNING: headless chrome can not set cookie before access. Ritsudo accesses root path before requested path for set cookies. EOS end = { timeout: 5, wait_time: 1 } puts "Ritsudo requests #{count} times: #{url}" count.times do print(".") collect(url, wait: wait, sub_process_timeout: sub_process_timeout, driver_options: .merge()) end puts "" end |