项目作者: akx

项目描述 :
Python statistical profiler
高级语言: Python
项目地址: git://github.com/akx/abyss.git
创建时间: 2015-12-15T13:37:32Z
项目社区:https://github.com/akx/abyss

开源协议:

下载


abyss

… is a statistical profiler and Chrome tracing file generator for Python.

  • Status: WIP but works for me!
  • Compatibility: Python 3.6+

Installation

  • Clone Abyss somewhere, say, ~/abyss
  • In your “client project”, i.e. whatever you’re profiling, pip install -e ~/abyss

Usage - Python

  1. from abyss.simple import profiling
  2. with profiling():
  3. my_slow_code()

Abyss will generate a tracing file you can load in chrome://tracing

Usage - Django middleware

Add abyss.django.AbyssMiddleware to your MIDDLEWARE.

By default, the middleware will generate a tracing file for every request that
either has any truthy value in a header or a query parameter named abyss.

The generated files will be saved to the configured django media storage
backend, with a prefix of abyss-django/.

You can customize the behavior easily by subclassing the middleware and
modifying a few variables or functions, for example:

  1. from abyss.django import AbyssMiddleware
  2. from django.http import HttpRequest
  3. class CustomAbyssMiddleware(AbyssMiddleware):
  4. STORAGE_CLASS = "storages.backends.s3boto3.S3Boto3Storage"
  5. FILENAME_PREFIX = "traces/"
  6. def should_profile_request(self, request: HttpRequest) -> bool:
  7. return super().should_profile_request(request) and request.user.is_superuser

How to analyze tracing files

  • ui.perfetto.dev is pretty snazzy in general.
  • The Chrome browser also has a built-in tool for analyzing these files: chrome://tracing.