Module: Vernier::Autorun

Defined in:
lib/vernier/autorun.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.collectorObject

Returns the value of attribute collector.



8
9
10
# File 'lib/vernier/autorun.rb', line 8

def collector
  @collector
end

.optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/vernier/autorun.rb', line 9

def options
  @options
end

Class Method Details

.at_exitObject



70
71
72
# File 'lib/vernier/autorun.rb', line 70

def self.at_exit
  stop if running?
end

.running?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/vernier/autorun.rb', line 66

def self.running?
  !!@collector
end

.startObject



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 = options.fetch(:interval, 500).to_i
  allocation_interval = options.fetch(:allocation_interval, 0).to_i
  hooks = options.fetch(:hooks, "").split(",")
   = if options[: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

.stopObject



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 = options[:output]
  unless output_path
    output_dir = options[:output_dir]
    unless output_dir
      if File.writable?(".")
        output_dir = "."
      else
        output_dir = Dir.tmpdir
      end
    end
    prefix = "profile-"
    timestamp = Time.now.strftime("%Y%m%d-%H%M%S")
    suffix = if options[:format] == "cpuprofile"
      ".vernier.cpuprofile"
    else
      ".vernier.json.gz"
    end

    output_path = File.expand_path("#{output_dir}/#{prefix}#{timestamp}-#{$$}#{suffix}")
  end

  result.write(out: output_path, format: options[:format] || "firefox")

  STDERR.puts(result.inspect)
  STDERR.puts("written to #{output_path}")
end

.toggleObject



74
75
76
# File 'lib/vernier/autorun.rb', line 74

def self.toggle
  running? ? stop : start
end