memray icon indicating copy to clipboard operation
memray copied to clipboard

Ability to write to a pipe from `memray.Tracker`

Open jhance opened this issue 1 year ago • 1 comments

Is there an existing proposal for this?

  • [X] I have searched the existing proposals

Is your feature request related to a problem?

I want to write to a fifo instead of a file but memray complains if the file I point it to already exists. The end problem I am trying to solve is that I want to stream the result to a distributed file system instead of place it on the disk.

Describe the solution you'd like

I'd like to write to a pre-existing fifo pipe.

Alternatives you considered

If memray could just give me the bytes in an iterator that would be fine too.

jhance avatar Mar 28 '24 23:03 jhance

As things stand today, this isn't simple. Memray expects to be able to mmap the output file, and pipes cannot be mmapped.

We do support binding to a TCP port, waiting for a client to connect, and then writing the captured data over that socket - https://bloomberg.github.io/memray/api.html#memray.SocketDestination

That's intended for use by the memray live TUI, but you might be able to use that for your needs by spawning a thread or process that connects to that TCP port and writes everything it receives to your FIFO.

godlygeek avatar Mar 29 '24 03:03 godlygeek

After talking about it a bit, we decided we would address this in two separate ways:

  1. Add documentation for writing a wrapper script that smuggles the capture file out: #598
  2. Add a way for the Tracker API to take a callback for user post-processing: #599

Closing this in favor of the other two.

sarahmonod avatar May 20 '24 02:05 sarahmonod