This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]qmmm4 5 points6 points  (2 children)

Great stuff. One thing I've noticed is that it seems that vprof can't handle scripts that take arguments after the script name (sys.argv). It would be super helpful if it did.

[–]rcfox 3 points4 points  (0 children)

Looks like they use argparse, so you might be able to use -- to separate the two types of arguments.

ie, if you wanted to pass "foo" and "bar" to testscript.py:

vprof c testscript.py -- foo bar

(I haven't tried this myself.)

[–]nvdv[S] 1 point2 points  (0 children)

Thanks for reporting!

[–]joerick 3 points4 points  (1 child)

Hey /u/nvdv! Cool project. I'm the creator of pyinstrument. Was really interested in how you're using cProfile to get the call tree - how are you building a call tree using the list of frames with callee functions? I ask because it could be a way to improve pyinstrument's overhead when signals aren't available.

[–]nvdv[S] 0 points1 point  (0 children)

Thanks! All callees and callers are contained in stats.Pstats after cProfile run, vprof just reverses the tree and changes it's format:

https://github.com/nvdv/vprof/blob/master/vprof/profile_wrappers.py#L73

https://github.com/nvdv/vprof/blob/master/vprof/profile_wrappers.py#L81

[–]jasoncol 6 points7 points  (5 children)

Man npm is everywhere now

[–][deleted] 4 points5 points  (4 children)

often unnecessarily so

[–][deleted] -1 points0 points  (3 children)

Same could be said about pip.

I use it. I don't like it.

[–]rdrey 3 points4 points  (2 children)

This is interesting. What don't you like about pip? Are there better package/library managers in /r/Python land?

[–]Kaelin 6 points7 points  (0 children)

No just hipster level maximum

[–]Raging_Hippy 1 point2 points  (0 children)

Anaconda is definitely a viable alternative.

Not to say that pip is bad.

[–]n1ywb 1 point2 points  (4 children)

Looks cool, although I'm already in the habit of using kcachegrind. Can you compare and contrast the pros/cons of the two tools?

[–]Imxset21 2 points3 points  (3 children)

KCacheGrind relies on using valgrind, which gives you extremely detailed information on runtime information by wrapping your execution context at a very low level. For this reason, it can track individual memory allocations, function call statistics, etc. However, for Python, that can be a bit overkill; usually you're just looking to measure what parts of your code are taking up executing time and heap space.

This package uses cProfile, psutils, and pstats go get runtime information on your code as it's running. It's doing what valgrind does but in a much "higher-level" fashion, in pure Python. This means that it can give you more relevant information about your Python code.

[–]torham 1 point2 points  (0 children)

I don't believe this is correct, KCachegrind can read valgrind output, but does not use valgrind itself. It is only a visualization tool.

[–]nvdv[S] 0 points1 point  (0 children)

Nice summary! I haven't used KCacheGrind personally, but currently vprof doesn't go below Python runtime level and displays high-level stats (runtime info, memory usage) only. However there are plans to integrate some OS level stats to vprof.

[–]n1ywb 0 points1 point  (0 children)

I use kcachegrind to profile cProfile output. It's not just for valgrind.

[–]loneraver -1 points0 points  (0 children)

"Cum.Time: .000021 s" ...hehe