Module: Vernier::Autorun
- Defined in:
- lib/vernier/autorun.rb
Class Attribute Summary collapse
-
.collector ⇒ Object
Returns the value of attribute collector.
-
.options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Class Attribute Details
.collector ⇒ Object
Returns the value of attribute collector.
8 9 10 |
# File 'lib/vernier/autorun.rb', line 8 def collector @collector end |
.options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/vernier/autorun.rb', line 9 def @options end |
Class Method Details
.at_exit ⇒ Object
70 71 72 |
# File 'lib/vernier/autorun.rb', line 70 def self.at_exit stop if running? end |
.running? ⇒ Boolean
66 67 68 |
# File 'lib/vernier/autorun.rb', line 66 def self.running? !!@collector end |
.start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vernier/autorun.rb', line 19 def self.start interval = .fetch(:interval, 500).to_i allocation_interval = .fetch(:allocation_interval, 0).to_i hooks = .fetch(:hooks, "").split(",") = if [:metadata] JSON.parse(@options[:metadata].unpack1("m")).to_h { |k, v| [k.to_sym, v] } else {} end STDERR.puts("starting profiler with interval #{interval} and allocation interval #{allocation_interval}") @collector = Vernier::Collector.new(:wall, interval:, allocation_interval:, hooks:, metadata:) @collector.start end |
.stop ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vernier/autorun.rb', line 35 def self.stop result = @collector.stop @collector = nil output_path = [:output] unless output_path output_dir = [:output_dir] unless output_dir if File.writable?(".") output_dir = "." else output_dir = Dir.tmpdir end end prefix = "profile-" = Time.now.strftime("%Y%m%d-%H%M%S") suffix = if [:format] == "cpuprofile" ".vernier.cpuprofile" else ".vernier.json.gz" end output_path = File.("#{output_dir}/#{prefix}#{}-#{$$}#{suffix}") end result.write(out: output_path, format: [:format] || "firefox") STDERR.puts(result.inspect) STDERR.puts("written to #{output_path}") end |
.toggle ⇒ Object
74 75 76 |
# File 'lib/vernier/autorun.rb', line 74 def self.toggle running? ? stop : start end |