A library to measure your method, function execution time.
Project description
PY Profiler
A library to measure method, function or your restful api execution time.
Install
- Run
pip install py-profiler
orpip3 install py-profiler
to install this library
Usage
It comes with a really easy api to use, you can add profiler(name = None)
decorator to any method or function you want
to measure its execution time.
E.g:
from py_profiler import profiler, profiling_service
@profiler('hello')
def hello():
print('hello')
class Foo:
@profiler('Food.some_thing')
def some_thing(self):
print('some_thing')
# By default, profiler name is f'{class_name}.{method_name}'
@profiler()
def method_2(self):
print('method_2')
Access Profiler
There are 3 ways to access the profiler:
- View as a raw table in the console.
- View as a HTML page using a provided Flask blueprint.
- Integrate with your own RESTFul framework.
- Exec time is in milliseconds
- View as a table
from py_profiler import profiling_service
print(profiling_service.as_table())
No | Name | Total Req | Pending Req | Total Exec Time | Last Exec Time | Highest Exec Time | Request Rate (req/sec) | Avg Time/Request (millis/req) |
---|---|---|---|---|---|---|---|---|
1 | Foo.method_2 | 1 | 0 | 0.014 | 0.014 | 0.014 | 71428.571 | 0.014 |
2 | Food.some_thing | 1 | 0 | 0.011 | 0.011 | 0.011 | 90909.091 | 0.011 |
3 | hello | 1 | 0 | 0.031 | 0.031 | 0.031 | 32258.065 | 0.031 |
- Integrate with FastAPI
- If you are using FastAPI to implement your Restful API. You can add
profiler_router
to your FastAPI app.
E.g:
from fastapi import FastAPI
from py_profiler.fastapi_profiler_controller import profiler_router
app = FastAPI()
app.include_router(profiler_router)
Then you can access the profiler page at: http://127.0.0.1:8080/profiler
- Integrate with Flask
- If you are using Flask to implement your Restful API. You can add
profiler_blueprint
to your Flash app.
E.g:
from flask import Flask
from waitress import serve
from py_profiler.profiler_controller import profiler_blueprint
app = Flask(__name__)
app.register_blueprint(profiler_blueprint)
serve(
app,
host="0.0.0.0",
port=8080
)
Then you can access the profiler page at: http://127.0.0.1:8080/profiler
- Integrate with 3rd restful library.
You can build your custom profiler viewer by using as_html()
from py_profiler import profiling_service
html_page = profiling_service.as_html()
Then, you can implement a html page and return this html_page
to your client to see profiler viewer.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_profiler-0.2.7.tar.gz
.
File metadata
- Download URL: py_profiler-0.2.7.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d01da14421e32a934db2940de9de8db023c88d2ddb349328635a1f0b2d7a74 |
|
MD5 | dbc6e654b4b08d11923dd64f0bdfdcf9 |
|
BLAKE2b-256 | 82cd4d519d4538f6b29d0d9a51199018f2a1cc2f897692c6cfd8459614e36474 |
File details
Details for the file py_profiler-0.2.7-py3-none-any.whl
.
File metadata
- Download URL: py_profiler-0.2.7-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 251e84568fa2f249a5af1299e5f0cce783da3887e95014419563e041651fee8b |
|
MD5 | 15590d941eb42c9da8fc942e7b002013 |
|
BLAKE2b-256 | 1962bc80fa3587f0d28f155b9aa0d02dcda1c1763fe477b9c78172d705cb3b89 |