Git Product home page Git Product logo

django-snoopy's Introduction

Django Snoopy

Django Snoopy is a pluggable profiling tool for Django Apps.

Quick Start:

  1. Add snoopy.middleware.SnoopyProfilerMiddleware to MIDDLEWARE_CLASSES
  2. (Optional) Configure Output if you don't want to use the default log file output
  3. Profile your code!

Setting Custom Attributes:

In case you want to track something specific to your app, you can do this:

from snoopy.request import SnoopyRequest
SnoopyRequest.record_custom_attributes({
    'key': 'value'
})

Any value set twice will just be overridden.

IMPORTANT The data passed into this MUST be a JSON serializable dictionary.

Settings:

You can set these in your Django settings.py file to configure how Snoopy works

SNOOPY_COLLECT_SQL_QUERIES: True

  • Track all SQL queries done via the Django ORM

SNOOPY_OUTPUT_CLASS: 'snoopy.output.LogOutput'

  • Set the class that defines how the collected info is processed at the end of the request. The options available out of the box are:

    • snoopy.output.LogOutput: This will create a file for each request in the folder specified by SNOOPY_LOG_OUTPUT_DIR. Defaults to the root folder of the app
    • snoopy.output.HTTPOutput: This will make a JSON formatted HTTP POST with the data in SNOOPY_HTTP_OUTPUT_URL
  • You can write your own Output class. All you need to do is to extend snoopy.output.OutputBase and implement the save_request_data method.

SNOOPY_USE_CPROFILE: False

  • Set to True if you want profiling

SNOOPY_CPROFILE_SHOW_ALL_FUNCTIONS: True

  • If this option is set to False, django-snoopy will take the parent directory of the main django settings file as the project root and will only list items in the cProfile output that are files under this directory (your actual app code)

DEFAULT_USE_BUILTIN_PROFILER': False

  • Set to True if you want to use the built-in profiler/tracer

DEFAULT_BUILTIN_PROFILER_SHOW_ALL_FUNCTIONS': True

  • Like the cProfile option counterpart, allows you to specify if you want data about all or just your own code.

TODO:

  • Basic request profiling with pluggable outputs
  • SQL Query tracking
  • Custom attribute tracking
  • Make tracking configurable
  • Actual Python code profiling
  • Lightweight function tracing.
  • Analyzers / Visualizers
  • Tests!

Future Ideas:

django-snoopy's People

Contributors

pradeek avatar

Stargazers

Sergei Riazanov avatar Jonathan Barratt avatar Pritesh Jain avatar Sathya Narrayanan avatar

Watchers

James Cloos avatar Godwin Jebakumar avatar

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.