GithubHelp home page GithubHelp logo

chronial / python-flamegraph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evanhempel/python-flamegraph

0.0 3.0 0.0 198 KB

Statistical profiler which outputs in format suitable for FlameGraph (http://www.brendangregg.com/flamegraphs.html)

License: The Unlicense

Python 100.00%

python-flamegraph's Introduction

A simple statistical profiler which outputs in format suitable for FlameGraph.

INSTALL:

Simply run:

pip install git+https://github.com/evanhempel/python-flamegraph.git

USAGE:

Run your script under the profiler:

python -m flamegraph -o perf.log myscript.py --your-script args here

Or, run the profiler from your script:

flamegraph.start_profile_thread(fd=open("./perf.log", "w"))

Run Brendan Gregg's FlameGraph tool against the output:

flamegraph.pl --title "MyScript CPU" perf.log > perf.svg

Enjoy the output:

Attic create flame graph

Filtering

Sometimes you may want to exclude a method (for example in a server the method that waits for a new request) or you may want to profile only a subset of your code (a particular method and its children which are performance critical).

Filtering can be done by passing a python regular expression to the -f or --filter command line option which will restrict output to only those lines which match. Filtering is done against the entire line so you can filter by function name, thread name, both, or even by more complex filters such as function ABC calls DEF (ABC.*DEF).

Alternatively since the output is stackframes each on a line by itself, this can simply be done with a simple grep filter.:

Exclude:

  grep -v waiting_method perf.log > removed_waiting.log

Include:

  grep function_name perf.log > filtered.log

Then run the flamegraph.pl script against the filtered file.

yCanta webapp full profile of PDF export

Full profile output of yCanta webapp PDF export. Most time is spent in wait state and graph is not very helpful.

yCanta webapp filtered for PDF export format function.

Filtered profile output of yCanta webapp PDF export. Filtering was on the pdf format function so time spent in wait state has been excluded and the graph is now helpful.

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.