bloomberg / memray

Memray is a memory profiler for Python
https://bloomberg.github.io/memray/
Apache License 2.0
13.17k stars 392 forks source link

CLI argument for memray run to also generate a flamegraph report if successful #649

Closed jcarnaxide closed 2 months ago

jcarnaxide commented 2 months ago

Is there an existing proposal for this?

Is your feature request related to a problem?

Currently one of my most common workflows with memray is to use memray run followed by memray flamegraph. This workflow requires two steps, one of which depends on the output from the other (the generated binary has a unique ID in the name and is needed for the second command)

This can become very tedious when I know I would like to generate a flamegraph from the very beginning.

Describe the solution you'd like

It would be great if memray run supported an additional CLI for generating a specified reporter directly as a result of the run, without needing to run an additional command.

I would imagine we could have this generate both the binary file and the specified reporter.

My first ask would be for flame graph support, but it would probably be wise to design this in a way to support other reporters too.

Alternatives you considered

This could be automated externally, but for those that would be interested in this feature, native support in Memray would be ideal.

godlygeek commented 2 months ago

This workflow requires two steps, one of which depends on the output from the other (the generated binary has a unique ID in the name and is needed for the second command)

The generated binary has a unique ID in it by default, but you can provide a filename explicitly instead. You can always do:

memray --output memray.out --force run foo.py; memray flamegraph --force memray.out

or with the short forms of those arguments:

memray -fo memray.out run foo.py; memray flamegraph -f memray.out
jcarnaxide commented 2 months ago

I like this alternative @godlygeek 👍