benfred / py-spy

Sampling profiler for Python programs
MIT License
12.8k stars 430 forks source link

Customisation of flame-graph parameters #45

Open 3tilley opened 6 years ago

3tilley commented 6 years ago

The default setting to make the flame-graph are pretty good, but it would be nice to be able to flex them. Things I'd like to be able to do:

I can think of three ways to do this:

  1. Expose the output of the profiler before it goes into flame, a custom call to the flame-script could then be executed by the user
  2. Allow a dictionary of command line arguments to be given to py-spy and passed on
  3. Pass a command-line config file

I have not used Rust before, but I could perhaps implement this change given some direction. FWIW I think the second is probably the best option, even if it is a little hacky.

pytest_flame

DavidVentura commented 6 years ago

A nice feature would be to be able to include/exclude filenames, for example only render files whose path starts with MYPACKAGENAME/* and then you wouldn't see the stack inside of libraries; I don't really care about what is taking time inside of redis' HGET or json internals (see screenshot)

2018-09-24-104432_1158x172_scrot

edit: or just limit whatever is not included to 1 as maximum depth; in my example you'd only see hget but not execute_command or anything below it

nziebart commented 6 years ago

+1 for approach #1 (exposing intermediate output). I think this is an important primitive

3tilley commented 5 years ago

What do you think is the easiest way to expose the options dict in inferno::flamegraph? That would give a lot of bang for buck: svg size, reverse stack order etc. Command line args? Env vars?

benfred commented 5 years ago

There is an option to output raw data in v0.2.0 now - you can use this to generate intermediate output to pass to flamegraph.pl with custom options now

Samreay commented 3 years ago

I love all the suggestions made so far, especially excluding specific packages, svg size and the colour scheme. Whilst theres now the raw data available, it would be good at a minimum for the main documentation to perhaps include some examples showing how you can achieve any of those customisations if they arent available within pyspy itself. Though having the ability to pass args from py-spy to flamegraph.pl would be fantastic. @benfred - thoughts on this? py-spy is my favourite profiler because of how simple it is it get high quality and useful output, and I'm leery of trying to complicate that ease-of-use too much by adding extra steps for users fi they want to tweak things.