=================
Project description
This package is an often used part of our debug environment at Publons. It helps benchmark and explain inefficiencies in pieces of code as well as our dependencies on different service response times.
There are four kinds of Context managers we support with this package
FileFlame
InlineFlame
DjangoFileFlame
DjangoInlineFlame
They all serve the same use case outputting a Flame graph to your machine for you to dive into and debug your code. FileFlame/DjangoFileFlame save the graph to an SVG for you to share, while InlineFlame/DjangoInlineFlame will render it in your IPython browser.
Examples
Saving a Flame graph to an SVG can be done with the following benchmarking code:
from flame_analyzer import FileFlame with FileFlame('./file_flame_test.svg'): # Some expensive piece of code. [len(u.email) for u in User.objects.all()]
Or directly to the IPython notebook:
from flame_analyzer import InlineFlame with InlineFlame(): # Some expensive piece of code. [len(u.email) for u in User.objects.all()]
You can also optionally configure the width by adding the width kwarg:
with FileFlame( './file_flame_test.svg', flame_width=1200, options={'title': 'This is my test title'} ): # some expensive piece of code [len(u.email) for u in User.objects.all()]
Extensions
By default both IPython and Django are optional imports meaning you can install this library and use it in the terminal to debug your app code without them installed. Support can be added for other Database frameworks or if your wanting to hook into the context enter/exit methods by creating your own hooks and adding to the output flame type your wanting for example::
from flame_analyzer import InlineFlame class CustomHook: """ Append the time taken to execute to the flame graphs title. """ def before(self): self.called_before = '< Called before code execution >' def after(self): self.called_after = '< Called after code execution >' def modify_flame_options(self, flame_options): title = flame_options.get('title', '') flame_options['title'] = self.called_before + ' --- ' + self.called_after return flame_options class CustomInlineFlame(InlineFlame): hook_classes = (CustomHook,) with CustomInlineFlame(flame_width=500): total_email_length = 0 for u in User.objects.all(): total_email_length += len(u.email) print(total_email_length)
Outputs the IPython viewed Graph:
- Credits to the following projects:
Home-page: https://github.com/publons/flame-analyzer Author: Matthew Betts, Aidan Houlihan Author-email: aidan@publons.com License: MIT License Description: UNKNOWN Platform: UNKNOWN Classifier: Environment :: Web Environment Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3.0 Classifier: Programming Language :: Python :: 3.6 Classifier: Topic :: Internet :: WWW/HTTP Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for flame_analyzer-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cf3370ba10ce5fc57dbf55dd83610b977e1e66f655aa877d66fc78293ab7f57 |
|
MD5 | fed1cac6e13840b2715d19b1c72efad5 |
|
BLAKE2b-256 | de38e7666e108cd930f9538789c70efe61798d3df1fbc289fcb9941b10413328 |