Skip to main content

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

https://user-images.githubusercontent.com/6813352/68050764-c1107800-fd4a-11e9-94a2-8ab0bc564617.png
Credits to the following projects:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flame-analyzer-0.1.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flame_analyzer-0.1.4-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file flame-analyzer-0.1.4.tar.gz.

File metadata

  • Download URL: flame-analyzer-0.1.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8

File hashes

Hashes for flame-analyzer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a5707b124cd6ecc05f2a898feb655405e86bd0e535b14c0ed5dd45fe7cbbdb4
MD5 9f4e5ca44a978bd370a2ba5c7b69ab68
BLAKE2b-256 9a380d5fa14d43a2b3684b2c4f7542c7d2066a22fe83eee23f4e25ea25763377

See more details on using hashes here.

File details

Details for the file flame_analyzer-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: flame_analyzer-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8

File hashes

Hashes for flame_analyzer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 24a826e401ac54d6cc0472b474a96da043cab5de1ec1232136fc6c1f5ee776a8
MD5 f95679a2e043c620c1727e1701a8f2f6
BLAKE2b-256 65864717982e35027364ed14799186ac451b4f54b5dd67c54a19fcb9b78af95f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page