Code Monkey home page Code Monkey logo

nylas-perftools's Introduction

This is a collection of minimalist utilities for profiling Python programs. The motivation behind them is described in our blog post.

py2devtools

The profile visualizer that's built into the Chrome developer tools is pretty rad. py2devtools.py contains instrumentation to create a .cpuprofile file from a Python program that can be loaded into the developer tools. See the module docstring for details.

stacksampler

stacksampler.py contains a sampling profiler, along with a minimal embedded HTTP server to expose its data. It's built to work with gevented applications, but can be adapted to work without. Assuming gevent, drop

import stacksampler
gevent.spawn(stacksampler.run_profiler)

into your code, run your application, and then do

curl localhost:16384

to get profiling data. See the module docstring for more details.

The stackcollector agent

Screenshot

The stackcollector package adds basic support for automatically collecting and visualizing profiles from distributed processes. It has two parts: a long-running collector agent that periodically gets samples from processes, and a frontend that serves visualizations. Data is timestamped and persisted using gdbm, allowing for time-based querying.

Installation

# create a directory for data files
sudo mkdir -p /var/lib/stackcollector
sudo chmod a+rw /var/lib/stackcollector

virtualenv .
source bin/activate
python setup.py install

Running the collector

The collector assumes that processes expose profiles in the flamegraph line format over HTTP, as implemented by stacksampler.py.

# Every minute, gather stacks from a local process listening on port 16384.
python -m stackcollector.collector --host localhost --ports 16384 --interval 60

Running the visualizer

python -m stackcollector.visualizer --port 5555

Then visit e.g. http://localhost:5555?from=-15minutes to see data from the past 15 minutes.

Questions? Issues?

Don't hesitate to get in touch!

nylas-perftools's People

Contributors

akx avatar dannyroberts avatar emfree avatar grinich avatar mckelvin avatar mmaybeno avatar spang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nylas-perftools's Issues

[Question] Loading py2devtools.py json into chrome developer tools timeline

Hi,

Loading the JSON performance data produced by py2devtools.py into Chrome developer tools timeline isn't working for me.

Right click timeline, "Load Timeline data" and load JSON created by py2devtools.py results into nothing.

The error I'm getting:

[4763:4763:1230/195530:ERROR:CONSOLE(417)] "TracingStartedInPage event not found.", source: chrome-devtools://devtools/bundled/timeline_module.js (417)

Perhaps I'm overlooking something? Any ideas?

Does it work with the updated Chrome Dev Tools?

I'm not able to have the Chrome Dev Tools work a Profile file generated by py2devtools.py.

I quickly compared the format generated by py2devtools and the one generated by Chrome and they seem quite different. The former starts with an object, the latter with an array. Since it looks like the Chrome Dev Tools have been updated recently, I wonder if the format expected has changed.

Are you still able to get Chrome to load your profile files?

Thanks,
J

[Question] Sampling inside gunicorn gevent worker.

Hello,

Is this sampling strategy supposed to work in "gevent-driven" environment, like gunicorn gevent worker? I've tried it in our system, and looks like that after several minutes of sampling it just hangs somewhere in _sample, probably in while loop (other application code is working as expected).

Thanks.

[Question] Multiprocess application profiling

What I'm most interested in is that, you guys mentioned you've managed to "aggregate stacktraces from multiple processes". May I ask how is that achieved? Are you running a standalone stack sampler for each process?

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.