Class: Vernier::Result
- Inherits:
-
Object
- Object
- Vernier::Result
- Defined in:
- lib/vernier/result.rb,
ext/vernier/vernier.cc
Instance Attribute Summary collapse
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#gc_markers ⇒ Object
readonly
Returns the value of attribute gc_markers.
-
#hooks ⇒ Object
Returns the value of attribute hooks.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#stack_table ⇒ Object
(also: #_stack_table)
Returns the value of attribute stack_table.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #each_sample ⇒ Object
- #elapsed_seconds ⇒ Object
- #inspect ⇒ Object
- #main_thread ⇒ Object
- #stack(idx) ⇒ Object
-
#started_at ⇒ Object
Realtime in nanoseconds since the unix epoch.
- #to_cpuprofile ⇒ Object
- #to_firefox(gzip: false) ⇒ Object (also: #to_gecko)
- #total_bytes ⇒ Object
- #total_samples ⇒ Object
- #total_unique_samples ⇒ Object
- #total_weights ⇒ Object
- #write(out:, format: "firefox") ⇒ Object
Instance Attribute Details
#end_time ⇒ Object
Returns the value of attribute end_time.
8 9 10 |
# File 'lib/vernier/result.rb', line 8 def end_time @end_time end |
#gc_markers ⇒ Object (readonly)
Returns the value of attribute gc_markers.
10 11 12 |
# File 'lib/vernier/result.rb', line 10 def gc_markers @gc_markers end |
#hooks ⇒ Object
Returns the value of attribute hooks.
8 9 10 |
# File 'lib/vernier/result.rb', line 8 def hooks @hooks end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
10 11 12 |
# File 'lib/vernier/result.rb', line 10 def end |
#pid ⇒ Object
Returns the value of attribute pid.
8 9 10 |
# File 'lib/vernier/result.rb', line 8 def pid @pid end |
#stack_table ⇒ Object 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 |
#threads ⇒ Object (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_sample ⇒ Object
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_seconds ⇒ Object
52 53 54 |
# File 'lib/vernier/result.rb', line 52 def elapsed_seconds (end_time - started_at) / 1_000_000_000.0 end |
#inspect ⇒ Object
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_thread ⇒ Object
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_at ⇒ Object
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 = [: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_cpuprofile ⇒ Object
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_bytes ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/vernier/result.rb', line 77 def total_bytes unless [:mode] == :retained raise NotImplementedError, "total_bytes is only implemented for retained mode" end total_weights end |
#total_samples ⇒ Object
85 86 87 |
# File 'lib/vernier/result.rb', line 85 def total_samples threads.values.sum { _1[:samples].count } end |
#total_unique_samples ⇒ Object
89 90 91 |
# File 'lib/vernier/result.rb', line 89 def total_unique_samples threads.values.flat_map { _1[:samples] }.uniq.count end |
#total_weights ⇒ Object
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 |