Class: Vernier::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/vernier/result.rb,
ext/vernier/vernier.cc

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



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

def end_time
  @end_time
end

#gc_markersObject (readonly)

Returns the value of attribute gc_markers.



10
11
12
# File 'lib/vernier/result.rb', line 10

def gc_markers
  @gc_markers
end

#hooksObject

Returns the value of attribute hooks.



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

def hooks
  @hooks
end

#metaObject (readonly)

Returns the value of attribute meta.



10
11
12
# File 'lib/vernier/result.rb', line 10

def meta
  @meta
end

#pidObject

Returns the value of attribute pid.



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

def pid
  @pid
end

#stack_tableObject Also known as: _stack_table

Returns the value of attribute stack_table.



5
6
7
# File 'lib/vernier/result.rb', line 5

def stack_table
  @stack_table
end

#threadsObject (readonly)

Returns the value of attribute threads.



10
11
12
# File 'lib/vernier/result.rb', line 10

def threads
  @threads
end

Instance Method Details

#each_sampleObject



60
61
62
63
64
65
66
67
# File 'lib/vernier/result.rb', line 60

def each_sample
  return enum_for(__method__) unless block_given?
  threads.values.each do |thread|
    thread[:samples].zip(thread[:weights]) do |stack_idx, weight|
      yield stack(stack_idx), weight
    end
  end
end

#elapsed_secondsObject



52
53
54
# File 'lib/vernier/result.rb', line 52

def elapsed_seconds
  (end_time - started_at) / 1_000_000_000.0
end

#inspectObject



56
57
58
# File 'lib/vernier/result.rb', line 56

def inspect
  "#<#{self.class} #{elapsed_seconds rescue "?"} seconds, #{threads.count} threads, #{total_samples} samples, #{total_unique_samples} unique>"
end

#main_threadObject



12
13
14
# File 'lib/vernier/result.rb', line 12

def main_thread
  threads.values.detect {|x| x[:is_main] }
end

#stack(idx) ⇒ Object



69
70
71
# File 'lib/vernier/result.rb', line 69

def stack(idx)
  stack_table.stack(idx)
end

#started_atObject

Realtime in nanoseconds since the unix epoch



17
18
19
20
21
22
# File 'lib/vernier/result.rb', line 17

def started_at
  started_at_mono_ns = meta[:started_at]
  current_time_mono_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
  current_time_real_ns = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
  (current_time_real_ns - current_time_mono_ns + started_at_mono_ns)
end

#to_cpuprofileObject



29
30
31
# File 'lib/vernier/result.rb', line 29

def to_cpuprofile
  Output::Cpuprofile.new(self).output
end

#to_firefox(gzip: false) ⇒ Object Also known as: to_gecko



24
25
26
# File 'lib/vernier/result.rb', line 24

def to_firefox(gzip: false)
  Output::Firefox.new(self).output(gzip:)
end

#total_bytesObject



77
78
79
80
81
82
83
# File 'lib/vernier/result.rb', line 77

def total_bytes
  unless meta[:mode] == :retained
    raise NotImplementedError, "total_bytes is only implemented for retained mode"
  end

  total_weights
end

#total_samplesObject



85
86
87
# File 'lib/vernier/result.rb', line 85

def total_samples
  threads.values.sum { _1[:samples].count }
end

#total_unique_samplesObject



89
90
91
# File 'lib/vernier/result.rb', line 89

def total_unique_samples
  threads.values.flat_map { _1[:samples] }.uniq.count
end

#total_weightsObject



73
74
75
# File 'lib/vernier/result.rb', line 73

def total_weights
  threads.values.sum { _1[:weights].sum }
end

#write(out:, format: "firefox") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vernier/result.rb', line 33

def write(out:, format: "firefox")
  case format
  when "cpuprofile"
    if out.respond_to?(:write)
      out.write(to_cpuprofile)
    else
      File.binwrite(out, to_cpuprofile)
    end
  when "firefox", nil
    if out.respond_to?(:write)
      out.write(to_firefox)
    else
      File.binwrite(out, to_firefox(gzip: out.end_with?(".gz")))
    end
  else
    raise ArgumentError, "unknown format: #{format}"
  end
end