Coder Social home page Coder Social logo

flamegraph's Introduction

Flamegraph

Flamegraph support for arbitrary Ruby apps.

Note, flamegraph support is built in to rack-mini-profiler, just require this gem and you should be good to go. Type ?pp=flamegraph to create one for the current page.

Installation

Add this line to your application's Gemfile:

gem 'flamegraph'

And then execute:

$ bundle

Or install it yourself as:

$ gem install flamegraph

NOTE: For ruby 2.1+ you'll need to install a stackprof gem:

$ gem install stackprof

Usage

Note: Only supported on Ruby 2.0. Gathering stack traces is too slow on earlier versions of Ruby or JRuby

require 'flamegraph'
html = Flamegraph.generate do
  # your work here
end

# or


Flamegraph.generate(filename) do
  # your work here
end

Demo

Demo of: https://github.com/SamSaffron/flamegraph/blob/master/demo/demo.rb

http://samsaffron.github.io/flamegraph/demo.html

Demo of Discourse startup using: https://github.com/SamSaffron/flamegraph/blob/master/demo/rails_startup.rb

WARNING VERY SLOW, MAY CRASH BROWSER TAB http://samsaffron.github.io/flamegraph/rails-startup.html

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

flamegraph's People

Contributors

adammeghji avatar bquorning avatar cjstadler avatar edbond avatar felixbuenemann avatar kapcod avatar mahemoff avatar nilbus avatar samsaffron avatar tmm1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flamegraph's Issues

Faster loading and zoom

Hi @SamSaffron

I've made a few changes (demo in video link: https://drive.google.com/open?id=0B-8YziZr08bQaEF3VmNIQURFMWM ):

  1. Added the ability to color by gem or method via radio buttons, without having to refresh the page.
  2. Filter by width of frame (to get quick visibility on slower calls).
  3. Ability to see callee in addition of the backtrace in the modal.
  4. Zoom via click, instead of having to click and drag.

Would love your thoughts.

Additionally I'm working on getting filtering via method/gem, as well.

Doesn't work on windows

While trying to install it I get:

Building native extensions.  This could take a while...
ERROR:  Error installing flamegraph:
ERROR: Failed to build gem native extension.

C:/Ruby200/bin/ruby.exe extconf.rb
creating Makefile
make
generating fast_stack-i386-mingw32.def
compiling fast_stack.c
In file included from c:/Ruby200/include/ruby-2.0.0/ruby/defines.h:153:0,
             from c:/Ruby200/include/ruby-2.0.0/ruby/ruby.h:70,
             from c:/Ruby200/include/ruby-2.0.0/ruby.h:33,
             from fast_stack.c:3:
c:/Ruby200/include/ruby-2.0.0/ruby/win32.h:276:12: error: conflicting types for 'gettimeofday'
In file included from fast_stack.c:2:0:
c:\ruby200\devkit\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/include/sys/time.h:42:13: note: previous declaration of 'gettimeofday' was here
fast_stack.c: In function 'rb_profile_start':
.
.
.

stackprof dependency required for ruby 2.1

I don't know anything about gemspecs, but I assume that since stackprof is only needed for ruby 2.1 that you can't add it as a dependency? If so, this should probably be documented in the README.

For others having this problem:
LoadError: cannot load such file -- stackprof,
add gem 'stackprof', '~> 0.2.7' to your Gemfile.

thanks for this! I like the changes but the UI needs to be a bit more

thanks for this! I like the changes but the UI needs to be a bit more
polished, maybe have it default off for now just to get it merged in and
then we can polish up the UI a bit.

On Sun, Apr 23, 2017 at 3:46 PM, Adnan Ali [email protected] wrote:

Hi @SamSaffron https://github.com/SamSaffron

I've made a few changes (demo in video link:
https://drive.google.com/open?id=0B-8YziZr08bQaEF3VmNIQURFMWM ):

  1. Added the ability to color by gem or method via radio buttons,
    without having to refresh the page.
  2. Filter by width of frame (to get quick visibility on slower calls).
  3. Ability to see callee in addition of the backtrace in the modal.
  4. Zoom via click, instead of having to click and drag.

Would love your thoughts.

Additionally I'm working on getting filtering via method/gem, as well.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#23, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAUXXnYxibABWlxD5vFc8eDw2tT9zDOks5ry9TfgaJpZM4NFkFs
.

Originally posted by @SamSaffron in #23 (comment)

Application with flamegraph installed fails to load (missing deps)

So flamegraph will attempt to require either stackprof or fast_stack

if RUBY_VERSION >= "2.1.0".freeze
  begin
    require "stackprof"
  rescue LoadError
    STDERR.puts "Please require the stackprof gem falling back to fast_stack"
    require "fast_stack"
  end

When the later fails Rails Server / Console will fail to initialize and exit. Should one of these be added to the dependency list, or otherwise the a rescue added for require "fast_stack" ?

JRuby support?

JRuby can't compile the C extension in the fast_stack dependency. Your README seems to imply that recent versions of JRuby in 2.0 mode might work with flamegraph. Have you indeed ever had this working under JRuby?

 $ ruby -v
jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-20 d537cab OpenJDK 64-Bit Server VM 24.75-b04 on 1.7.0_75-b13 +jit [linux-amd64]

 $ gem install fast_stack
Fetching: rake-compiler-0.9.5.gem (100%)
Successfully installed rake-compiler-0.9.5
Fetching: fast_stack-0.1.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing fast_stack:
        ERROR: Failed to build gem native extension.

    /home/nilbus/.rvm/rubies/jruby-9.0.0.0.pre1/bin/jruby -r ./siteconf20150408-110294-zavcjx.rb extconf.rb
NotImplementedError: C extensions are not supported
      (root) at /home/nilbus/.rvm/rubies/jruby-9.0.0.0.pre1/lib/ruby/stdlib/mkmf.rb:1
     require at org/jruby/RubyKernel.java:954
      (root) at /home/nilbus/.rvm/rubies/jruby-9.0.0.0.pre1/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
  __script__ at extconf.rb:1

extconf failed, exit code 1

Gem files will remain installed in /home/nilbus/.rvm/gems/jruby-9.0.0.0.pre1/gems/fast_stack-0.1.0 for inspection.
Results logged to /home/nilbus/.rvm/gems/jruby-9.0.0.0.pre1/extensions/universal-java-1.7/2.2/fast_stack-0.1.0/gem_make.out
nilbus (CE-976-profile)

 $ rvm use jruby-1.7.6
Using /home/nilbus/.rvm/gems/jruby-1.7.6

 $ jruby --2.0 -v
jruby 1.7.6 (2.0.0p195) 2013-10-22 6004147 on OpenJDK 64-Bit Server VM 1.7.0_75-b13 [linux-amd64]
 $ rvm use jruby-1.7.19
Using /home/nilbus/.rvm/gems/jruby-1.7.19
nilbus (CE-976-profile)

 $ jruby --2.0 -v
jruby 1.7.19 (2.0.0p598) 2015-01-29 20786bd on OpenJDK 64-Bit Server VM 1.7.0_75-b13 +jit [linux-amd64]
nilbus (CE-976-profile)

 $ jruby --2.0 -S gem install fast_stack
Building native extensions.  This could take a while...
ERROR:  Error installing fast_stack:
        ERROR: Failed to build gem native extension.

    /home/nilbus/.rvm/rubies/jruby-1.7.19/bin/jruby -r ./siteconf20150408-112721-ejau45.rb extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /home/nilbus/.rvm/rubies/jruby-1.7.19/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1071
   (root) at /home/nilbus/.rvm/rubies/jruby-1.7.19/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
   (root) at extconf.rb:1

extconf failed, uncaught signal 1

Gem files will remain installed in /home/nilbus/.rvm/gems/jruby-1.7.19/gems/fast_stack-0.1.0 for inspection.
Results logged to /home/nilbus/.rvm/gems/jruby-1.7.19/extensions/universal-java-1.7/1.9/fast_stack-0.1.0/gem_make.out

Ability to hide and unhide some gems

The overall problem I'm facing is having information overload associated with flamegraphs: http://stackoverflow.com/questions/35855922/dealing-with-information-overload-for-rack-mini-profiler-flamegraph

One approach for dealing with this (not mentioned in the SO question) may be to have the ability to click on a gem to hide (or unhide) gems. For example, I'd click on the "journey-1.0.4" gem and then the nodes for that would disappear. It'd probably be something like #7 (interactive legend) except with a different trigger and a different effect, and possibly something for hiding or unhiding all third party gems.

Color functions not gems

Hey, I want to profile my own methods not gems, but flamegraph colors all of my project code with same color, can this be changed? E.g. color by methods and not gems.

I forked the repo and added filtering options, but can't find where coloring decision happens.

Request: ESC to close Frame Info

Nice tool here. Can you please make it possible to close with a keyboard shortcut as moving the mouse outside the window can make it difficult to jump around and drill into different sections.

fast_stack not compiling

Hi,

first of all thanks for this gem. I tried to include it together with mini-profiler. This is a

  • MAC OS X 10.11
  • Rails 4.2.4
  • Ruby 2.2.3
  • bundler 1.10.6
  • rubygems 2.4.5.1

setup. I get the following error when trying to run bundle and also when trying to install fast_stack standalone via gem install flamegraph:

Building native extensions.  This could take a while...
ERROR:  Error installing fast_stack:
    ERROR: Failed to build gem native extension.

    /Users/andwen/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151009-33231-16ysef.rb extconf.rb
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling fast_stack.c
linking shared-object fast_stack/fast_stack.bundle
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [fast_stack.bundle] Error 1

make failed, exit code 2

Is this a compiler issue? I have Apple LLVM version 7.0.0 (clang-700.0.72) installed (gcc -v)

Thanks for any help.

Cheers

Andy

Performance issues for large graphs

Profiling an ActiveRecord query generates a flamegraph that is borderline unusable. Zooming in to the graph such that labels show slows down the page to 300ms per frame, 3FPS. The majority of time is spent in d3.js restyling and rendering.

Can zoom be implemented in a way that doesn't require expensive re-calculations whenever we want to move around the graph?

Screen Shot 2019-05-28 at 10 55 35 AM

Screen Shot 2019-05-28 at 10 55 51 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.