ymichael / cprofilev Goto Github PK
View Code? Open in Web Editor NEW:fire: An easier way to use cProfile
Home Page: https://pypi.python.org/pypi/CProfileV
License: MIT License
:fire: An easier way to use cProfile
Home Page: https://pypi.python.org/pypi/CProfileV
License: MIT License
I'm fine reloading the page every once in a while, but for longer running things, it'd be pretty awesome to either autoreload or, better yet, update the results with an ajax request to the bottle server. I have a profiling job that might take upwards of an hour where I check back from time to time and that'd be pretty nice. If we do something like #19, this should be pretty straightforward to implement. Thoughts?
Remove the need to an output file
This should return a friendly error message indicating that their scriptfile
passed in is indeed not a python script.
I have a patch that catches the possible TypeError
and SyntaxError
which outputs a friendly error before printing the rest of the scripts help documentation.
[cProfileV]: there was a problem compiling your scriptfile.
@ymichael please let me know if you are interested in this patch.
It might be nice to use something like DataTables to make it easier to read the output and filter for particular rows in the table. Do you have any opposition to a contribution along these lines?
On Python 2.7.2, a KeyError
is raised when you attempt to sort by ncalls, tottime, cumtime, or filename. pstats
is the module that actually raises the exception, but it is initiated by cprofilev.py on line #136:
self.obj.sort_stats(sort)
If you modify the URI to, for example be ?sort=calls
instead of ?sort=ncalls
(which according to the pstats docs, is the correct key supported by 2.7, the sort succeeds, the server no longer 500's, and no key error is raised.
It seems that the keys that cprofilev uses only became available in Python >= 3.2, but I realize that some of these sort keys (like provide a distinct advantage over the ones available in Python < 3.2. Would it be possible to version sniff when setting the nfl
)SORT_ARGS
dict, so that cprofilev works on Python < 3.2?
I can submit a PR, but I wanted to make sure that this was acceptable for you.
I have profiled some code using the command
$ python -m cProfile -o report.prof script.py
I then launch cprofilev like so
$ cprofilev -f report.prof
When I go to the URL localhost I see a 500 error:
Error: 500 Internal Server Error
Sorry, the requested URL 'http://127.0.0.1:4000/' caused an error:
Internal Server Error
When I look at the console where the cprofilev was launched I see this:
Traceback (most recent call last):
File "/home/james/miniconda3/envs/climate_profile/bin/bottle.py", line 862, in _handle
return route.call(**args)
File "/home/james/miniconda3/envs/climate_profile/bin/bottle.py", line 1740, in wrapper
rv = callback(*a, **ka)
File "/home/james/miniconda3/envs/climate_profile/lib/python3.6/site-packages/cprofilev.py", line 154, in route_handler
self.stats = Stats(self.profile)
File "/home/james/miniconda3/envs/climate_profile/lib/python3.6/site-packages/cprofilev.py", line 75, in __init__
self.stats = pstats.Stats(self.profile, stream=self.stream)
File "/home/james/miniconda3/envs/climate_profile/lib/python3.6/pstats.py", line 72, in __init__
self.init(arg)
File "/home/james/miniconda3/envs/climate_profile/lib/python3.6/pstats.py", line 86, in init
self.load_stats(arg)
File "/home/james/miniconda3/envs/climate_profile/lib/python3.6/pstats.py", line 100, in load_stats
self.stats = marshal.load(f)
ValueError: bad marshal data (unknown type code)
The cprofilev package was installed into an Anaconda environment running Python 3.6.3 using pip install
.
Can anyone advise as to how I can get past this issue? Thanks in advance for any assistance.
Is there a way to run cprofilev for a module?
Im trying like that:
python3 -m cprofilev "-m myprogram myargs"
also
python3 -m cprofilev -m myprogram my args
When I install your cprofilev with:
pip install cprofilev
I get the following exception:
File "/.../env/build/cprofilev/setup.py", line 3, in <module>
import cprofilev
File "cprofilev.py", line 3, in <module>
from bottle import Bottle, template, request
ImportError: No module named bottle
What you could do about it is to add bottle to the setup.py file:
requires = [
'bottle',
]
P.S. Great tool!
Tried to use your package and it didn't work, so I gave up and used pstats instead
$ python -m cprofilev profile_output
[cProfileV]: cProfile output available at http://127.0.0.1:4000
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/cprofilev.py", line 238, in
main()
File "/usr/local/lib/python2.7/dist-packages/cprofilev.py", line 221, in main
code = compile(fp.read(), progname, 'exec')
TypeError: compile() expected string without null bytes
Hi! I'm trying to use cprofilev. I'm not a python geek. So maybe you can help me the error I'm facing.
When I launch: python -m cprofilev -p 11100 /path/to/x.py
(I used another port because 4000 was already use)
My program starts.. but if I connect to localhost:11100 during the execution I see a server error page.
My port scan see this port open.
My program lasts about 5 minutes and has a lot of print logs.
When the program has finished I see this error as well on the terminal:
Traceback (most recent call last):
File "/Users/andreapigatto/anaconda/lib/python2.7/site-packages/bottle.py", line 862, in _handle
return route.call(*_args)
File "/Users/andreapigatto/anaconda/lib/python2.7/site-packages/bottle.py", line 1732, in wrapper
rv = callback(_a, **ka)
File "/Users/andreapigatto/anaconda/lib/python2.7/site-packages/cprofilev.py", line 164, in route_handler
'stats': self.stats.sort(sort).show(func_name).read(),
File "/Users/andreapigatto/anaconda/lib/python2.7/site-packages/cprofilev.py", line 125, in show
self.stats.print_stats(restriction)
File "/Users/andreapigatto/anaconda/lib/python2.7/pstats.py", line 351, in print_stats
print >> self.stream, indent, self.total_calls, "function calls",
TypeError: unicode argument expected, got 'str'
Can you give me some tips about how to solve and what can be?
Many thanks
Andrea
love the tool and all, but I'd like to be able to output cprofilev output to a file for html viewing, rather than have cprofilev serve as the file viewer itself.
I have hundreds of benchmarks I need to go through, so I'd like to pass it to a script to generate the html, then view via a regular web browser.
I'll modify it inline to do that, but I'd definitely rather have it exported to me via pip.
thanks much,
Hi and thanks for this lovely project.
I have a small webserver using aiohttp (which in turn, wraps asyncio).
When running it like so: python -m cprofilev main.py
I get the following error:
[cProfileV]: cProfile output available at http://127.0.0.1:4000
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.8/cProfile.py", line 100, in runctx
exec(cmd, globals, locals)
File "main.py", line 255, in <module>
main()
File "main.py", line 239, in main
web.run_app(app, port=WEBSERVER_PORT)
File "/home/hemulin/workspace/venv/lib/python3.8/site-packages/aiohttp/web.py", line 409, in run_app
loop = asyncio.get_event_loop()
File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1'.
Any idea how to use this profiler with asyncio?
Rather than the web server assuming a single profile output, the webserver could serve from a directory of profile outputs that can be viewed.
Hi, I'm running windows server 2008 with python 2.7.5 and I have created an virtual env. I then pip installed cprofilev and invoke it via the command below. You can see the stacktrace below. I've tried with an admin terminal with no change in output. Do you have any suggestions on how to get past this socket issue?
λ cprofilev C:\Users\agrc-arcgis\Envs\runsnake\Scripts\seed.profile
cprofilev server listening on port 4000
Traceback (most recent call last):
File "C:\Users\agrc-arcgis\Envs\runsnake\Scripts\cprofilev-script.py", line 9, in <module>
load_entry_point('CProfileV==0.1.3', 'console_scripts', 'cprofilev')()
File "C:\Users\agrc-arcgis\Envs\runsnake\lib\site-packages\cprofilev.py", line 199, in main
CProfileV(cprofile_output, address, port, quiet).start()
File "C:\Users\agrc-arcgis\Envs\runsnake\lib\site-packages\cprofilev.py", line 175, in start
self.app.run(host=self.address, port=self.port, quiet=self.quiet)
File "C:\Users\agrc-arcgis\Envs\runsnake\Scripts\bottle.py", line 755, in run
run(self, **kwargs)
File "C:\Users\agrc-arcgis\Envs\runsnake\Scripts\bottle.py", line 3114, in run
server.run(app)
File "C:\Users\agrc-arcgis\Envs\runsnake\Scripts\bottle.py", line 2768, in run
srv = make_server(self.host, self.port, app, server_cls, handler_cls)
File "C:\Python27\ArcGISx6410.2\Lib\wsgiref\simple_server.py", line 144, in make_server
server = server_class((host, port), handler_class)
File "C:\Python27\ArcGISx6410.2\Lib\SocketServer.py", line 419, in __init__
self.server_bind()
File "C:\Python27\ArcGISx6410.2\Lib\wsgiref\simple_server.py", line 48, in server_bind
HTTPServer.server_bind(self)
File "C:\Python27\ArcGISx6410.2\Lib\BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "C:\Python27\ArcGISx6410.2\Lib\SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "C:\Python27\ArcGISx6410.2\Lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
I'm running Python 3.4 on Windows 7. I created a profile file using CProfile file that can be visualised using pstats. However, when I attempt to use your module raises a TypeError
[cProfileV]: cProfile output available at http://127.0.0.1:4000
Traceback (most recent call last):
File "C:\Python34\Scripts\cprofilev-script.py", line 9, in
load_entry_point('CProfileV==1.0.6', 'console_scripts', 'cprofilev')()
File "C:\Python34\lib\site-packages\cprofilev.py", line 217, in main
code = compile(fp.read(), progname, 'exec')
TypeError: source code string cannot contain null bytes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.