py-spy icon indicating copy to clipboard operation
py-spy copied to clipboard

Customisation of flame-graph parameters

Open 3tilley opened this issue 5 years ago • 5 comments

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:

  • Adjust the size of the output svg
  • Remove some layers of the call stack from the output (see the attached svg for pytest on a simple python test)
  • Use different colour schemes
  • List absolute time instead of number of samples

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

3tilley avatar Sep 23 '18 17:09 3tilley

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

DavidVentura avatar Sep 24 '18 08:09 DavidVentura

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

nziebart avatar Sep 25 '18 00:09 nziebart

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?

3tilley avatar Jul 17 '19 09:07 3tilley

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

benfred avatar Sep 23 '19 03:09 benfred

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.

Samreay avatar Mar 29 '21 09:03 Samreay