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

It would be nice if snakeviz worked. #6817

Open
mforbes opened this issue Jul 5, 2023 · 5 comments
Open

It would be nice if snakeviz worked. #6817

mforbes opened this issue Jul 5, 2023 · 5 comments

Comments

@mforbes
Copy link

mforbes commented Jul 5, 2023

Not exactly sure where the problem lies, but it would be very nice if snakeviz could work with CoCalc notebooks.

It is not currently installed, so needs to be installed:

import sys
!{sys.executable} -m pip install --user snakeviz
# Might need a kernel restart to see this

Now it can be loaded as an extension...

%load_ext snakeviz

... then used as a cell magic:

%%snakeviz
x = 1+1

Currently this gives something like this:

*** Profile stats marshalled to file '/tmp/tmphifn32qq'.
Embedding SnakeViz in this document...
<function display at 0x7f2e4c74fdc0>

Instead, it should display an interface like this:

image

Running this through the Classic Notebook server also fails. The following error appears in the JS console in both cases:

Mixed Content: The page at 'https://cocalc.com/projects/d8321832-12e5-4c52-ac0b-46b5f29e9740/files/SnakeViz.ipynb' was loaded over HTTPS, but requested an insecure frame 'http://cocalc.com:8080/snakeviz/%2Ftmp%2Ftmphy03ii92'. This request has been blocked; the content must be served over HTTPS.

SnakeViz must be running a server and trying to place this in a frame. Any obvious way to make this work?

@mforbes
Copy link
Author

mforbes commented Jul 5, 2023

I can seem to run snakeviz from a terminal, but still have some issues:

# tst.py
def fib(n):
    if n <= 1:
        return 1
    return fib(n-1)+fib(n-2)
print(fib(10))
~$ python -m cProfile -o program.prof tst.py 
89
~$ snakeviz -s -H 0.0.0.0 -p 12345 program.prof 
snakeviz web server started on 0.0.0.0:12345; enter Ctrl-C to exit
http://0.0.0.0:12345/snakeviz/%2Fhome%2Fuser%2Fprogram.prof

I can open this on https://cocalc.com/<project id>/server/12345/snakeviz/%2Fhome%2Fuser%2Fprogram.prof, but run into jiffyclub/snakeviz#185.

Not sure if this has something to do with HTTP vs HTTPS. (Link above to a CoCalc project demonstrating the issue for developers.)

@williamstein
Copy link
Contributor

@williamstein
Copy link
Contributor

Their cli options are:

~$ snakeviz --help
usage: snakeviz [-h] [-v] [-H ADDR] [-p PORT] [-b BROWSER_PATH] [-s] filename

Start SnakeViz to view a Python profile.

positional arguments:
  filename              Python profile to view

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -H ADDR, --hostname ADDR
                        hostname to bind to (default: 127.0.0.1)
  -p PORT, --port PORT  port to bind to; if this port is already in use a free port will be selected automatically (default: 8080)
  -b BROWSER_PATH, --browser BROWSER_PATH
                        name of webbrowser to launch as described in the documentation of Python's webbrowser module: https://docs.python.org/3/library/webbrowser.html
  -s, --server          start SnakeViz in server-only mode--no attempt will be made to open a browser
~$ 

so I guess it doesn't support setting a custom base url, unless there is an environment variable that it uses for that.

@williamstein
Copy link
Contributor

My guess is that slightly changing this line

https://github.com/jiffyclub/snakeviz/blob/master/snakeviz/main.py#L67

would be how to add a base url. But there would also be several other places where they explicitly hardcode /snakeviz, rather than /user/configurable/path/to/snakeviz, many of which you can see listed here:

https://github.com/search?q=repo%3Ajiffyclub%2Fsnakeviz%20%2Fsnakeviz&type=code

e.g., in snakeviz/templates/dir.html

@mforbes
Copy link
Author

mforbes commented Jul 5, 2023

Thanks. I figured it was something like this. I will try patching SnakeViz and see if I can get this working. Once this is done, is there anything special that would be needed for getting it to working inline with CoCalc notebooks (i.e. along the lines of issues with ipywidgets etc.) or should that be straightforward and work too?

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

No branches or pull requests

2 participants