Skip to content

Repository files navigation

Profyle

Development tool for analysing and managing python traces

TestsPackage versionSupported Python versions

Why do you need Profyle?

Bottlenecks

With Profyle you can easily detect where in your code you have a bottleneck, simply analyze the trace and see what function or operation is taking most of the execution time of the request

Enhance performace

Analyze the traces and decide which parts of your code should be improved

Installation

$ pip install profyle---> 100%

Example

1. Implement

In order to track all your API requests you must implement the ProfyleMiddleware

ProfyleMiddleware

AttributeRequiredDefaultDescriptionENV Variable
enabledNoTrueEnable or disable ProfylePROFYLE_ENABLED
patternNoNone0nly trace those paths that match with patternPROFYLE_PATTERN
max_stack_depthNo-1Limit maximum stack trace depthPROFYLE_MAX_STACK_DEPTH
min_durationNo0 (milisecons)Only record traces with a greather duration than the limit.PROFYLE_MIN_DURATION
FastAPI
fromfastapiimportFastAPIfromprofyle.fastapiimportProfyleMiddlewareapp=FastAPI()
# Trace all requestsapp.add_middleware(ProfyleMiddleware)
@app.get("/")asyncdefroot():
return {"hello": "world"}
fromfastapiimportFastAPIfromprofyle.fastapiimportProfyleMiddlewareapp=FastAPI()
# Trace all requests that match that start with /users # with a minimum duration of 100ms and a maximum stack depth of 20app.add_middleware(
ProfyleMiddleware,
pattern="/users*",
max_stack_depth=20,
min_duration=100
)
@app.get("/users/{user_id}")asyncdefget_user(user_id: int):
return {"hello": "user"}
Flask
fromflaskimportFlaskfromprofyle.flaskimportProfyleMiddlewareapp=Flask(__name__)
app.wsgi_app=ProfyleMiddleware(app.wsgi_app, pattern="*/api/products*")
@app.route("/")defroot():
return"<p>Hello, World!</p>"
Django
# settings.pyMIDDLEWARE= [
...
"profyle.django.ProfyleMiddleware",
...
]

2. Run

  • Run the web server:
$ profyle startINFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)INFO: Started reloader process [28720]INFO: Started server process [28722]INFO: Waiting for application startup.INFO: Application startup complete.

3. List

  • List all requests tracing:

Alt text

4. Analyze

  • Profyle stands on the shoulder of giants: Viztracer and Perfetto
  • Detailed function entry/exit information on timeline with source code
  • Super easy to use, no source code change for most features, no package dependency
  • Supports threading, multiprocessing, subprocess and async
  • Powerful front-end, able to render GB-level trace smoothly
  • Works on Linux/MacOS/Window

Alt text

Alt text

CLI Commands

start

  • Start the web server and view profile traces
OptionsTypeDefaultDescription
--portINTEGER0web server port
--hostTEXT127.0.0.1web server host
$ profyle start --port 5432INFO: Uvicorn running on http://127.0.0.1:5432 (Press CTRL+C to quit)INFO: Started reloader process [28720]INFO: Started server process [28722]INFO: Waiting for application startup.INFO: Application startup complete.

clean

  • Delete all profile traces
$ profyle clean10 traces removed 

check

  • Check traces DB size
$ profyle checkDB size: 30MB

About

Development tool for analysing and managing python traces

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages