Skip to content

Instantly share code, notes, and snippets.

@jean
Last active December 23, 2015 06:19
Show Gist options
  • Select an option

  • Save jean/6592939 to your computer and use it in GitHub Desktop.

Select an option

Save jean/6592939 to your computer and use it in GitHub Desktop.
Plomino: profiling from the debug prompt
""" 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())
@jean
Copy link
Author

jean commented Sep 17, 2013

@ebrehault nice to know it's possible ...

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