P403n1x87 / austin-vscode

Austin extension for Visual Studio Code
MIT License
21 stars 4 forks source link

Trying to run pytest using Austin in VS code. #24

Closed hrshdhgd closed 2 years ago

hrshdhgd commented 2 years ago

This may be similar to https://github.com/P403n1x87/austin-vscode/issues/21 but I'm not sure. I read the documentation at the VS code marketplace here

Here's my situation: I have python project that I'm trying to profile using Austin within VS code. I'm using a MacBook (macOS Big Sur). Here's my tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "austin",
            "label": "Profile tests",
            "args": [
                "python",
                "-m",
                "pytest",
            ],
            "problemMatcher": []
        }
    ]
}

I'm just trying to run pytest over the project. I'm also running this within a conda virtual environment. I get the following error:

> Executing task: Profile tests <

Starting Profiler in xxx/yyy/zzz/project-name.
Running 'austin' with args '-i 100 --pipe  python -m pytest'.
austin process exited with code 127
The terminal process failed to launch (exit code: 127).

Terminal will be reused by tasks, press any key to close it.

Any guidance/suggestion would be great appreciated.

P403n1x87 commented 2 years ago

I think this might be due to the fact that austin is running without sudo. On MacOS the use of sudo is unfortunately mandatory (unless you have SIP disabled). One possible solution is to allow austin to run without password, by adding a rule in the sudoers file, and then actually running sudo, e.g.

        {
            "type": "austin",
            "label": "Profile tests",
            "command": ["sudo"],
            "args": [
                "python",
                "-m",
                "pytest",
            ]
        },
hrshdhgd commented 2 years ago

Hey @P403n1x87 , thank you so much for the suggestion. I sudo vi sudo and added the line:

myUsername ALL=(ALL) NOPASSWD: ALL

and ran the task again after changing the task to what you suggested above. I get a different error (exit code 1) instead of the previous exit code 127..

Running 'sudo' with args 'austin -i 100 --pipe  python -m pytest'.
austin process exited with code 1
The terminal process failed to launch (exit code: 1).

Terminal will be reused by tasks, press any key to close it.
P403n1x87 commented 2 years ago

@hrshdhgd thanks for trying that. I think this is now the same as #23, which I haven't been able to figure out yet šŸ™ .

P403n1x87 commented 2 years ago

I sudo vi sudo and added the line:

myUsername ALL=(ALL) NOPASSWD: ALL

Just as an aside, I'd use something like

myUsername ALL = (root) NOPASSWD: /usr/local/bin/austin

instead.

hrshdhgd commented 2 years ago

Not a problem , please let me know when you figure it out. In the meanwhile, would you know which Austin VSCode extension version and Austin version combination has proven to work in unison in the past?

hrshdhgd commented 2 years ago

I sudo vi sudo and added the line: myUsername ALL=(ALL) NOPASSWD: ALL

Just as an aside, I'd use something like

myUsername ALL = (root) NOPASSWD: /usr/local/bin/austin

instead.

Aah ... I'll try that.

hrshdhgd commented 2 years ago

same error.

P403n1x87 commented 2 years ago

Not a problem , please let me know when you figure it out. In the meanwhile, would you know which Austin VSCode extension version and Austin version combination has proven to work in unison in the past?

I'm afraid Austin latest and Austin VS Code latest have the best chances šŸ™ . What I would recommend in the meantime is to invoke austin manually from the command line and open the collected samples with the extension afterwards. I think I can safely say this proves to be the most reliable way of using the extension when everything else fails.

hrshdhgd commented 2 years ago

Could you direct me to an example please?

P403n1x87 commented 2 years ago

Could you direct me to an example please?

You can run the same command that VS Code is trying to run from a terminal, e.g.

sudo austin -i 100 -o /path/to/austin/output.austin python -m pytest

and then open the /path/to/austin/output.austin from VS Code by clicking the OPEN button in the Flame Graph panel (or using the Cmd + Shift + A shortcut). This is equivalent to running the task.

hrshdhgd commented 2 years ago

Thank you so much @P403n1x87 ! That works as expected!