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)
- #to_markdown(top_n: 20, lines_per_file: 5) ⇒ Object
- #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 @meta 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
70 71 72 73 74 75 76 77 |
# File 'lib/vernier/result.rb', line 70 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
62 63 64 |
# File 'lib/vernier/result.rb', line 62 def elapsed_seconds (end_time - started_at) / 1_000_000_000.0 end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/vernier/result.rb', line 66 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
79 80 81 |
# File 'lib/vernier/result.rb', line 79 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 |
#to_markdown(top_n: 20, lines_per_file: 5) ⇒ Object
33 34 35 |
# File 'lib/vernier/result.rb', line 33 def to_markdown(top_n: 20, lines_per_file: 5) Output::Markdown.new(self, top_n: top_n, lines_per_file: lines_per_file).output end |
#total_bytes ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/vernier/result.rb', line 87 def total_bytes unless [:mode] == :retained raise NotImplementedError, "total_bytes is only implemented for retained mode" end total_weights end |
#total_samples ⇒ Object
95 96 97 |
# File 'lib/vernier/result.rb', line 95 def total_samples threads.values.sum { _1[:samples].count } end |
#total_unique_samples ⇒ Object
99 100 101 |
# File 'lib/vernier/result.rb', line 99 def total_unique_samples threads.values.flat_map { _1[:samples] }.uniq.count end |
#total_weights ⇒ Object
83 84 85 |
# File 'lib/vernier/result.rb', line 83 def total_weights threads.values.sum { _1[:weights].sum } end |
#write(out:, format: "firefox") ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vernier/result.rb', line 37 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 "markdown", "md" if out.respond_to?(:write) out.write(to_markdown) else File.binwrite(out, to_markdown) 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 |