The aim: profiling a Python script with Pyflame in another Python script.
The details: code is run on a virtual machine with Ubuntu 14.04 LTS.
1) To run the profiled script I'm using:
process = subprocess.Popen(["python", "python_script.py"])
2) Then I'm trying to attach Pyflame to the process (treat this line as a smoke test):
subprocess.Popen(["sudo pyflame -s 60 -r 0.0001 " + str(process.pid)],
shell=True)
The problem: Without sudo
in the above statement I'm getting a Failed to attach to PID ...: Operation not permitted
error.
With sudo
I'm getting Failed to locate libpython named libpython2.7.so
.
I would be grateful for any ideas regarding how to make statement 2) work, with or without sudo
!
Apparently, Pyflame will return the second error that you got if these conditions are met:
Take a look at the source code of Pyflame here and here . When you run Pyflame, it looks into the memory space of your interpreter and it tries to find libpython2.7.so . For a Python 3.X interpreter, the library is not there.
So I suggest that you try the following:
cat /proc/{YOUR_PID}/maps | grep libpython2.7
To target Python 3.X when compiling Pyflame, refer to the documentation. Hint: you'll need to change the call to ./configure as follows:
./configure --with-python=python3
Besides, if you have trouble making python3 recognized as a library in your environment, you'll need to symlink to the Python 3.X interpreter's executable. This is a bit out of scope, so you can check out my personal blog for more details (see the post "Using Uber's Pyflame and Logs to Tackle Scaling Issues"). Disclaimer: I'm the author of that post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.