Coder Social home page Coder Social logo

blackfireio / python-continuous-profiling Goto Github PK

View Code? Open in Web Editor NEW
0.0 9.0 0.0 59 KB

Python Continuous Profiling support

Home Page: https://blackfire.io

Makefile 9.74% Python 80.45% Dockerfile 2.56% Shell 7.25%
blackfire performance python

python-continuous-profiling's Introduction

Blackfire Continuous Profiler for Python

Blackfire Continuous Profiler continuously collects and uploads profiling data to the Blackfire servers. Once enabled, the profiler collects the relevant profiling information in configurable intervals and periodically uploads it to the Blackfire Agent. Blackfire Agent then forwards this information to the backend.

How to use

Prerequisites

  • Python >= 3.7.0
  • Blackfire Agent >= 2.13.0

Installation

pip install blackfire_conprof

Example

An example using the whole API interface:

  1. Install dependencies
pip install blackfire_conprof
  1. Create example.py with the following code
from blackfire_conprof.profiler import Profiler

def foo():
    import time
    time.sleep(1.0)

profiler = Profiler(application_name="my-python-app", agent_socket="tcp://127.0.0.1:8307", labels={'my-extra-label': 'data'})
profiler.start()
foo()
profiler.stop()
  1. Run Blackfire Agent (version 2.13.0 and up)
BLACKFIRE_SOCKET="tcp://127.0.0.1:8307" blackfire agent --log-level=4
  1. Run the example application. (python example.py)
  2. Profiler will send data to the Agent, and Agent will forward it to the Blackfire backend. Data then can be visualized at https://blackfire.io

Enabling the profiler

There are two ways to enable the profiler:

  • via Code,
  • via Command Line.

Code

from blackfire_conprof.profiler import Profiler

profiler = Profiler()
profiler.start()

Please note that the above needs to be done as early as possible in your application. Example: for gevent applications to work correctly, this needs to be imported before gevent.monkey.patch_all().

Command line

Run your Python application as following:

blackfire-conprof python app.py

This will automatically enable the profiler just before your application runs.

Contributing

Use make help to display an overview of useful commands for your dev environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.