Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest-profiling not generating SVG file #93

Closed
williamjamir opened this issue Sep 5, 2018 · 5 comments · Fixed by #99
Closed

pytest-profiling not generating SVG file #93

williamjamir opened this issue Sep 5, 2018 · 5 comments · Fixed by #99

Comments

@williamjamir
Copy link

williamjamir commented Sep 5, 2018

OS version: Windows 10
Python Version: 3.6.5
pytest version: 3.7.3
pytest-profiling version: 1.3.0

Executing pytest --profile works fine for me, but when I use the pytest --profile-svg I have the following output

(py36) λ pytest --profile-svg
=== test session starts ===============================
platform win32 -- Python 3.6.5, pytest-3.7.3, py-1.5.3, pluggy-0.7.1
PyQt5 5.6 -- Qt runtime 5.6.2 -- Qt compiled 5.6.2
rootdir: W:\tmp2\profiling_test, inifile:
plugins: xdist-1.23.0, timeout-1.3.2, replay-0.2.2, regressions-1.0.1, qt-2.4.1, profiling-1.3.0, mock-1.10.0, localserver-0.4.1, lazy-fixture-0.3.0, forked-0.2, datadir-1.2.1, cpp-1.1.0, cov-2.5.1, pylama-7.4.3, hypothesis-3.11.0
collected 1 item

test_foo.py .                                                                                                    [100%]The syntax of the command is incorrect.

Profiling (from W:\tmp2\profiling_test\prof\combined.prof):
Wed Sep  5 11:09:28 2018    W:\tmp2\profiling_test\prof\combined.prof

         199 function calls (197 primitive calls) in 0.004 seconds

   Ordered by: cumulative time
   List reduced from 92 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.003    0.003 runner.py:107(pytest_runtest_call)
        1    0.000    0.000    0.003    0.003 python.py:1448(runtest)
        1    0.000    0.000    0.003    0.003 hooks.py:244(__call__)
        1    0.000    0.000    0.003    0.003 manager.py:64(_hookexec)
        1    0.000    0.000    0.003    0.003 manager.py:58(<lambda>)
        1    0.000    0.000    0.003    0.003 callers.py:151(_multicall)
        1    0.000    0.000    0.003    0.003 python.py:186(pytest_pyfunc_call)
        1    0.000    0.000    0.003    0.003 test_foo.py:1(testFoo)
        1    0.003    0.003    0.003    0.003 test_foo.py:2(<listcomp>)
      7/5    0.000    0.000    0.000    0.000 {built-in method builtins.next}
        2    0.000    0.000    0.000    0.000 capture.py:206(pytest_runtest_call)
        5    0.000    0.000    0.000    0.000 {method 'send' of 'generator' objects}
        2    0.000    0.000    0.000    0.000 capture.py:164(item_capture)
        1    0.000    0.000    0.000    0.000 contextlib.py:85(__exit__)
        1    0.000    0.000    0.000    0.000 capture.py:121(read_global_capture)
        1    0.000    0.000    0.000    0.000 capture.py:482(readouterr)
        2    0.000    0.000    0.000    0.000 capture.py:578(snap)
        2    0.000    0.000    0.000    0.000 capture.py:539(snap)
        2    0.000    0.000    0.000    0.000 {method 'read' of '_io.FileIO' objects}
        1    0.000    0.000    0.000    0.000 runner.py:129(_update_current_test_var)


SVG profile in W:\tmp2\profiling_test\prof\combined.svg.

And the combined.svg file is not generated.

@smarie
Copy link
Contributor

smarie commented Oct 25, 2018

I have exactly the same issue "The syntax of the command is incorrect." on Windows 7 with graphviz properly installed (since the commandlines below work).

Here is the workaround that I currently use.

I assume that you have installed graphviz and added its bin folder to the path (a simple way is to use conda install graphviz if you use anaconda or miniconda).

gprof2dot -f pstats prof/combined.prof > prof/tmp
dot -Tsvg -o prof/combined.svg prof/tmp

That generates the svg file.

It would however be great if this could be done automatically, I'll have a look and propose a PR

@smarie
Copy link
Contributor

smarie commented Oct 25, 2018

Diagnosis attempt: current version uses pipes.Template to perform the transform.

This ends up building the following command:

"IN='C:\\...\\tests\\servicetests\\prof\\combined.prof'; gprof2dot -f pstats $IN |\n{ OUT='C:\\...\\tests\\servicetests\\prof\\combined.svg'; dot -Tsvg -o $OUT; }"

This is therefore not valid on windows targets.

Suggested remedy: use subprocess.Popen instead .

smarie added a commit to smarie/pytest-plugins that referenced this issue Oct 25, 2018
…e of pipes and using a temporary file instead. Also improved the terminal message at the end depending on the result of this operation. Fixes man-group#93.
eeaston added a commit that referenced this issue Dec 8, 2019
Fixed SVG file generation on windows (#93)
@isaacnorman82
Copy link

I still see this issue, did the fix make it into 1.7.0?

@smarie
Copy link
Contributor

smarie commented Nov 12, 2020

I don't think so, see #162

@rpbc86
Copy link

rpbc86 commented Feb 22, 2024

I have exactly the same issue "The syntax of the command is incorrect." on Windows 7 with graphviz properly installed (since the commandlines below work).

Here is the workaround that I currently use.

I assume that you have installed graphviz and added its bin folder to the path (a simple way is to use conda install graphviz if you use anaconda or miniconda).

gprof2dot -f pstats prof/combined.prof > prof/tmp
dot -Tsvg -o prof/combined.svg prof/tmp

That generates the svg file.

It would however be great if this could be done automatically, I'll have a look and propose a PR

solution worked
thanks for inputs :)

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

Successfully merging a pull request may close this issue.

4 participants