omarish / django-cprofile-middleware Goto Github PK
View Code? Open in Web Editor NEWHelpful django cprofiling middleware.
License: MIT License
Helpful django cprofiling middleware.
License: MIT License
More of a feature request -- It would be nice to have downloadable raw profile output that is readable by RunSnakeRun or CacheGrind.
def process_response(self, request, response):
if self.can(request):
self.profiler.create_stats()
May 4 16:48:52 localhost uwsgi: Traceback (most recent call last):
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
May 4 16:48:52 localhost uwsgi: self.load_middleware()
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 50, in load_middleware
May 4 16:48:52 localhost uwsgi: mw_class = import_string(middleware_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
May 4 16:48:52 localhost uwsgi: module = import_module(module_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
May 4 16:48:52 localhost uwsgi: return _bootstrap._gcd_import(name[level:], package, level)
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1129, in _exec
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1471, in exec_module
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django_cprofile_middleware/middleware.py", line 14, in <module>
May 4 16:48:52 localhost uwsgi: from django.utils.deprecation import MiddlewareMixin
May 4 16:48:52 localhost uwsgi: ImportError: cannot import name 'MiddlewareMixin'
May 4 16:48:52 localhost uwsgi: [pid: 6550|app: 0|req: 22/22] 172.16.6.20 () {44 vars in 837 bytes} [Fri May 4 16:48:52 2018] GET /xdashboard/home/?prof => generated 0 bytes in 9 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 42)
May 4 16:48:52 localhost uwsgi: Traceback (most recent call last):
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
May 4 16:48:52 localhost uwsgi: self.load_middleware()
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 50, in load_middleware
May 4 16:48:52 localhost uwsgi: mw_class = import_string(middleware_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
May 4 16:48:52 localhost uwsgi: module = import_module(module_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
May 4 16:48:52 localhost uwsgi: return _bootstrap._gcd_import(name[level:], package, level)
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1129, in _exec
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1471, in exec_module
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django_cprofile_middleware/middleware.py", line 14, in <module>
May 4 16:48:52 localhost uwsgi: from django.utils.deprecation import MiddlewareMixin
May 4 16:48:52 localhost uwsgi: ImportError: cannot import name 'MiddlewareMixin'
May 4 16:48:52 localhost uwsgi: [pid: 6550|app: 0|req: 23/23] 172.16.6.20 () {42 vars in 768 bytes} [Fri May 4 16:48:52 2018] GET /nginx-logo.png => generated 0 bytes in 5 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 46)
May 4 16:48:52 localhost uwsgi: Traceback (most recent call last):
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
May 4 16:48:52 localhost uwsgi: self.load_middleware()
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 50, in load_middleware
May 4 16:48:52 localhost uwsgi: mw_class = import_string(middleware_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
May 4 16:48:52 localhost uwsgi: module = import_module(module_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
May 4 16:48:52 localhost uwsgi: return _bootstrap._gcd_import(name[level:], package, level)
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1129, in _exec
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1471, in exec_module
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django_cprofile_middleware/middleware.py", line 14, in <module>
May 4 16:48:52 localhost uwsgi: from django.utils.deprecation import MiddlewareMixin
May 4 16:48:52 localhost uwsgi: ImportError: cannot import name 'MiddlewareMixin'
May 4 16:48:52 localhost uwsgi: [pid: 6550|app: 0|req: 24/24] 172.16.6.20 () {42 vars in 766 bytes} [Fri May 4 16:48:52 2018] GET /poweredby.png => generated 0 bytes in 5 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 11)
May 4 16:48:52 localhost uwsgi: Traceback (most recent call last):
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
May 4 16:48:52 localhost uwsgi: self.load_middleware()
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 50, in load_middleware
May 4 16:48:52 localhost uwsgi: mw_class = import_string(middleware_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
May 4 16:48:52 localhost uwsgi: module = import_module(module_path)
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
May 4 16:48:52 localhost uwsgi: return _bootstrap._gcd_import(name[level:], package, level)
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1129, in _exec
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 1471, in exec_module
May 4 16:48:52 localhost uwsgi: File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
May 4 16:48:52 localhost uwsgi: File "/root/.pyenv/versions/3.4.4/lib/python3.4/site-packages/django_cprofile_middleware/middleware.py", line 14, in <module>
May 4 16:48:52 localhost uwsgi: from django.utils.deprecation import MiddlewareMixin
May 4 16:48:52 localhost uwsgi: ImportError: cannot import name 'MiddlewareMixin'
May 4 16:48:52 localhost uwsgi: [pid: 6550|app: 0|req: 25/25] 172.16.6.20 () {46 vars in 815 bytes} [Fri May 4 16:48:52 2018] GET /favicon.ico => generated 0 bytes in 7 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 1)
The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.
due to it expecting unicode, here's the fix:
try:
from cStringIO import StringIO
except:
from io import StringIO
Currently the project don't support django 1.8. The project use MiddlewareMixin come with django 1.10. Django 1.8 is still used I would to know if you are ok to add the support of this django version.
in django 1.10.6, I got this error after inserting middleware at last index.
File "/t/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
We need some basic test coverage to make sure that the library functions as expected. Is anybody interested in helping out by creating some basic tests?
When I do pip install django-cprofile-middleware
, it installs v0.1. Looks like the newest version is missing from https://pypi.python.org/simple/django-cprofile-middleware/.
Hi,
I'm getting the following error with Django 1.5, any ideas what it can be ?
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'set_cookie'
Exception Location: /home/areski/.virtualenvs/cdrstats/local/lib/python2.7/site-packages/django/middleware/csrf.py in process_response, line 208
Full Paste
http://dpaste.com/1259400/
It would be nice to get a new release with the features added since 1.0.4
.
Thanks for your library!
Hi,
While I follow the steps necessary to install the module, and load the application, I get the following error message:
Error importing module: 'Module "api.cache.middleware" does not define a "ProfilerMiddleware" attribute/class'.
Django 1.10 / Python 3.6.
I think it can be interesting to add a settings to bypass the can method. I think on the development mode it's not necessary to be staff to show the result of profiling. Maybe it can be interesting to add a settings to bypass the current condition.
When I try and use it as described in the README., Ijust get:
"'WSGIRequest' object has no attribute 'user'" at middleware.py in can, line 30,
If i use a trailing / on the url, i get a different error:
"'Person' object has no attribute 'is_staff' middleware.py in can, line 30"
pip install django-cprofile-middleware
Collecting django-cprofile-middleware
Using cached https://files.pythonhosted.org/packages/3b/c2/0cb878b0018b54444849d4569c6b36e0688eb1316e363e356228bb5d1b0f/django-cprofile-middleware-1.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/c4/8qchc1vj479_9v7h_xm8ztw5hj2xk1/T/pip-install-UPHoZq/django-cprofile-middleware/setup.py", line 10, in
with open(path.join(project_path, 'README.md')) as f:
IOError: [Errno 2] No such file or directory: '/private/var/folders/c4/8qchc1vj479_9v7h_xm8ztw5hj2xk1/T/pip-install-UPHoZq/django-cprofile-middleware/README.md'
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.