Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vernier #29

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Add general profile method
technicalpickles committed May 8, 2024
commit f63fae136e98900690e09b5fd4294e6d5702861d
30 changes: 22 additions & 8 deletions lib/singed.rb
Original file line number Diff line number Diff line change
@@ -51,22 +51,36 @@ def filter_line(line)
line
end

def stackprof(label = "stackprof", open: true, announce_io: $stdout, **stackprof_options, &)
fg = Singed::Flamegraph::Stackprof.new(label: label, **stackprof_options)
def profiler_klass(profiler)
case profiler
when :stackprof, nil then Singed::Flamegraph::Stackprof
when :vernier then Singed::Flamegraph::Vernier
else
raise ArgumentError, "Unknown profiler: #{profiler}"
end
end

def profile(label = "flamegraph", profiler: nil, open: true, io: $stdout, **profiler_options, &)
profiler_klass = profiler_klass(profiler)
fg = profiler_klass.new(
label: label,
announce_io: io,
**profiler_options
)

result = fg.record(&)
fg.save
fg.open if open

result
end

def vernier(label = "vernier", open: true, announce_io: $stdout, **vernier_options, &)
fg = Singed::Flamegraph::Vernier.new(label: label, announce_io: announce_io, **vernier_options)
result = fg.record(&)
fg.save
fg.open if open
def stackprof(label = "stackprof", open: true, announce_io: $stdout, **stackprof_options, &)
profile(label, profiler: :stackprof, open: open, announce_io: announce_io, **stackprof_options, &)
end

result
def vernier(label = "vernier", open: true, announce_io: $stdout, **vernier_options, &)
profile(label, profiler: :vernier, open: open, announce_io: announce_io, **vernier_options, &)
end

autoload :Flamegraph, "singed/flamegraph"
13 changes: 2 additions & 11 deletions lib/singed/kernel_ext.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
module Kernel
def flamegraph(label = nil, open: true, io: $stdout, **stackprof_kwargs, &)
fg = Singed::Flamegraph::Stackprof.new(
label: label,
announce_io: io,
**stackprof_kwargs
)
result = fg.record(&)
fg.save
fg.open if open

result
def flamegraph(label = nil, profiler: nil, open: true, io: $stdout, **profiler_options, &)
Singed.profile(label, profiler: profiler, open: open, io: io, **profiler_options, &)
end
end

Unchanged files with check annotations Beta

class Stackprof < Flamegraph
DEFAULT_OPTIONS = {
mode: :wall,
raw: true,

Check failure on line 51 in lib/singed/flamegraph.rb

GitHub Actions / StandardRB

lib/singed/flamegraph.rb#L51

Avoid comma after the last item of a hash.
}.freeze
def initialize(label: nil, announce_io: $stdout, **stackprof_options)