Last active
December 23, 2015 06:19
-
-
Save jean/6592939 to your computer and use it in GitHub Desktop.
Plomino: profiling from the debug prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ How to do Plomino profiling from debug prompt | |
| """ | |
| from zope.component.hooks import setSite | |
| setSite(plone) | |
| from sys import stdin, stdout | |
| from ZPublisher.HTTPRequest import HTTPRequest | |
| from ZPublisher.HTTPResponse import HTTPResponse | |
| from ZPublisher.BaseRequest import RequestContainer | |
| def hacked_makerequest(stdout=None, environ={}): | |
| resp = HTTPResponse(stdout=stdout) | |
| environ.setdefault('SERVER_NAME', 'foo') | |
| environ.setdefault('SERVER_PORT', '80') | |
| environ.setdefault('REQUEST_METHOD', 'GET') | |
| req = HTTPRequest(stdin, environ, resp) | |
| req._steps = ['noobject'] # Fake a published object. | |
| req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4 | |
| req['status_criteria'] = 'Ongoing' | |
| req['cookies'] = {} | |
| from zope.publisher.browser import setDefaultSkin | |
| setDefaultSkin(req) | |
| requestcontainer = RequestContainer(REQUEST = req) | |
| return requestcontainer | |
| requestcontainer = hacked_makerequest() | |
| # I don't know why, but `plone.REQUEST = hacked_makerequest()` fails. | |
| plone.REQUEST = requestcontainer.REQUEST | |
| plone.REQUEST.set('level', 'form:fields:formulas') | |
| # This sets a cookie on the response, but it doesn't show up on the request: | |
| db.set_profiling_level(plone.REQUEST) | |
| # Fake a cookie on the request: | |
| plone.REQUEST.cookies = {'plomino_profiler': 'form:fields:formulas'} | |
| for d in db.getAllDocuments(): | |
| d.save() | |
| from pprint import pprint | |
| pprint(db.profiling_results()) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ebrehault nice to know it's possible ...