Search code examples
python-3.xodooprofilingodoo-14

Profiling in Odoo


I am new to odoo and code profiling. I am using py-spy to profile my odoo code, as I need a flame graph as the output of profiling. Everything is working fine with py-spy, but the issue is, the py-spy needs to be stopped by pressing ctrl + C on the terminal where it is running or shutting the odoo server down. I can't stop or reset the odoo server neither I can do ** Ctrl + C** on the server.

I had tried to create to do this To start py-spy

def start_pyflame(self):
    pyflame_started = self.return_py_spy_pid('py-spy')
    error = False
    if not pyflame_started:
        self.start_pyflame()
    else:
        error = 'PyFlame Graph process already created. Use Stop button if needed.'
        _logger.error(error)

which is working fine, the problem is with this one

def stop_pyflame_and_download_graph(self):
        pyflame_running = self.return_py_spy_pid('py-spy')
        if pyflame_running:
            subprocess.run(["sudo", "pkill", "py-spy"])

Now the issue is when I am killing the process with pkill or kill it kills the process but along with this, it also terminates the py-spy, because of which, the output file is not generated.

Is there any way to stop or soft kill py-spy so that the output file will be created.

Thanks in advance for help


Solution

  • After some research, I came to know that all these kill commands are just killing the process whereas in this case, we need to stop the process.

    This thing I have achieved by

    sudo kill -SIGINT <pid>
    

    As it is clear from the name, this command is not killing/terminating the process, it is simply asking the process to stop working by passing an interrupt signal.

    This worked for me.