Class: Ferrum::Page::Tracing
- Inherits:
-
Object
- Object
- Ferrum::Page::Tracing
- Defined in:
- lib/ferrum/page/tracing.rb
Overview
Records a Chrome performance trace for the page via the CDP Tracing domain, optionally including screenshots, and streams the resulting trace data to disk or memory once recording stops.
Constant Summary collapse
- EXCLUDED_CATEGORIES =
%w[*].freeze
- SCREENSHOT_CATEGORIES =
%w[disabled-by-default-devtools.screenshot].freeze
- INCLUDED_CATEGORIES =
%w[devtools.timeline v8.execute disabled-by-default-devtools.timeline disabled-by-default-devtools.timeline.frame toplevel blink.console blink.user_timing latencyInfo disabled-by-default-devtools.timeline.stack disabled-by-default-v8.cpu_profiler disabled-by-default-v8.cpu_profiler.hires].freeze
- DEFAULT_TRACE_CONFIG =
{ includedCategories: INCLUDED_CATEGORIES, excludedCategories: EXCLUDED_CATEGORIES }.freeze
Instance Method Summary collapse
-
#initialize(page) ⇒ Tracing
constructor
A new instance of Tracing.
-
#record(path: nil, encoding: :binary, timeout: nil, trace_config: nil, screenshots: false) ⇒ String, true
Accepts block, records trace and by default returns trace data from
Tracing.tracingCompleteevent as output.
Constructor Details
#initialize(page) ⇒ Tracing
Returns a new instance of Tracing.
23 24 25 26 |
# File 'lib/ferrum/page/tracing.rb', line 23 def initialize(page) @page = page @subscribed_tracing_complete = false end |
Instance Method Details
#record(path: nil, encoding: :binary, timeout: nil, trace_config: nil, screenshots: false) ⇒ String, true
Accepts block, records trace and by default returns trace data from Tracing.tracingComplete event as output.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ferrum/page/tracing.rb', line 54 def record(path: nil, encoding: :binary, timeout: nil, trace_config: nil, screenshots: false) @path = path @encoding = encoding @pending = Concurrent::IVar.new trace_config ||= DEFAULT_TRACE_CONFIG.dup if screenshots included = trace_config.fetch(:includedCategories, []) trace_config.merge!(includedCategories: included | SCREENSHOT_CATEGORIES) end subscribe_tracing_complete start(trace_config) yield stop @pending.value!(timeout || @page.timeout) end |