Google App Engine Mini Profiler
gae_mini_profiler is a quick drop-in WSGI app that provides ubiquitous profiling of your existing GAE projects. It exposes both RPC statistics and standard profiling output for users of your choosing on your production site. Only requests coming from users of your choosing will be profiled, and others will not suffer any performance degradation. See screenshots and features below.
This project is heavily inspired by the impressive mvc-mini-profiler.
gae_mini_profiler is MIT licensed.
Demo
You can play around with one of GAE's sample applications with gae_mini_profiler enabled for all users via http://gae-mini-profiler.appspot.com.
Screenshots
All profiled pages have total milliseconds in corner, which can be expanded...
...to show more details...
...about remote procedure call performance...
...or standard profiler output.
Ajax requests are also profiled and details made available as they are received.
Getting Started
- Download this repository's source and copy the
gae_mini_profiler/
folder into your App Engine project's root directory. - Add the following two handler definitions to
app.yaml
:
handlers: – url: /gae_mini_profiler/static static_dir: gae_mini_profiler/static
– url: /gae_mini_profiler/.* script: gae_mini_profiler/main.py
- Modify the WSGI application you want to profile by wrapping it with the gae_mini_profiler WSGI application:
# Example of existing application application = webapp.WSGIApplication(...existing application...)
# Add the following from gae_mini_profiler import profiler application = profiler.ProfilerWSGIMiddleware(application)
- Insert the
profiler_includes
template tag below jQuery somewhere (preferably at the end of your template):
...your html... {% profiler_includes %} </body> </html>
- You're all set! Just choose the users for whom you'd like to enable profiling in
gae_mini_profiler/config.py
:
# If using the default should_profile implementation, the profiler # will only be enabled for requests made by the following GAE users. enabled_profiler_emails = [ "kamens@gmail.com", ]
Features
- Production profiling without impacting normal users
- Easily profile all requests, including ajax calls
- Summaries of RPC call types and their performance so you can quickly figure out whether datastore, memcache, or urlfetch is your bottleneck
- Share individual profile results with others by sending link
- Duplicate RPC calls are flagged for easy spotting in case you're repeating memcache or datastore queries.
- Quickly sort and examine profiler stats and call stacks
Bonus
gae_mini_profiler is currently in production use at Khan Academy (http://khanacademy.org). If you make find good use of it elsewhere, be sure to let me know.
FAQ
-
I had my appstats_RECORD_FRACTION variable set to 0.1, which means only 10% of my queries where getting profiles generated. This meant that most of the time gae_mini_profiler was failing with a javascript error, because the appstats variable was null.
If you are using appengine_config.py to customize Appstats behavior you should add this to the top of your "appstats_should_record" method.
def appstats_should_record(env): from gae_mini_profiler.config import should_profile if should_profile(env): return True