Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/flamegraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down