diff --git a/README.md b/README.md index 9b0129f..0e4a480 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,23 @@ end ``` +You can also pass some options: + +```ruby + +# will hide bottom x lines of the graph +Flamegraph.generate(filename, hide_x_bottom_lines: 20) do + # your work here +end + +# will order stacktraces alphabetically, like the original Flamegraph (https://github.com/brendangregg/FlameGraph) does +Flamegraph.generate(filename, sort_alphabetically: true) do # TODO: consider https://gist.github.com/BrVer/9854d6fb5b9546987c49e0dcf8ead380 instead + # your work here +end + +``` + + ## Demo Demo of: https://github.com/SamSaffron/flamegraph/blob/master/demo/demo.rb diff --git a/lib/flamegraph.rb b/lib/flamegraph.rb index 6cfb441..30c6af5 100644 --- a/lib/flamegraph.rb +++ b/lib/flamegraph.rb @@ -44,6 +44,12 @@ def self.generate(filename=nil, opts = {}) yield end end + if opts[:hide_x_bottom_lines] + backtraces.map! { |b| b[0..-(opts[:hide_x_bottom_lines].to_i + 1)] }.reject(&:empty?) + end + if opts[:sort_alphabetically] + backtraces.sort_by! {|b| b.reverse.join('---')} + end embed_resources = (filename && !opts.key?(:embed_resources)) || opts[:embed_resources]