Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Gathered data is lost if process terminates before Pyflame #25

Closed
jdgillespie91 opened this issue Oct 5, 2016 · 2 comments
Closed

Gathered data is lost if process terminates before Pyflame #25

jdgillespie91 opened this issue Oct 5, 2016 · 2 comments

Comments

@jdgillespie91
Copy link

Currently, if the process being profiled terminates before Pyflame has finished, the Pyflame process errors rather than printing what has been profiled up until that point.

Ideally, if the process being profiled terminates before Pyflame has finished, the Pyflame process would exit cleanly and the output be as normal.

I'm not sure of the feasibility of this request so feel free to close the issue if appropriate.


Reproducible example

Running the following will demonstrate the error:

$ python -c "from time import sleep; sleep(1)" & sudo pyflame "$!" -s 5
[1] 11075
Failed to attach to PID 11075: No such process

Use case

I'm trying to profile a set of tests that are invoked with py.test ....

Currently, I start this process in the background with py.test ... &. I determine the PID of the process (by writing and reading from a file) and then call Pyflame on this PID. Given that I want to profile the whole test suite, I have to match the time that Pyflame is called for with the time the test suite should take to run (which is naturally variable).

It would be especially convenient to call Pyflame for longer than necessary to ensure the whole test suite is profiled.

@eklitzke
Copy link
Collaborator

eklitzke commented Oct 5, 2016

So I fixed this in the sense that if the process exits early pyflame will just print the results it has so far. However, there's something even better that can be done for your use case. Ptrace has a special "trace me" mode for observing the entire lifetime of a process. This is how the strace command works, e.g. when you do strace ls it will watch the ls process from the moment it starts until it ends. The use case you have here (profiling a test suite) is pretty interesting and I think it should be supported with the trace mode.

@jdgillespie91
Copy link
Author

Thanks @eklitzke for the rapid work. I'm still seeing the same issue though (after pulling from master):

$ python -c "from time import sleep; sleep(1)" & sudo pyflame "$!" -s 5
[1] 19824
Failed to attach to PID 19824: No such process
[1]+  Done                    python -c "from time import sleep; sleep(1)"

Regarding the trace mode, that sounds like a great idea! I'll take a look to see if I can assist but this might be beyond me...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants