https://github.com/cafebazaar/profile_function
An easy profiling tool which collects elapsed time for functions and code blocks.
https://github.com/cafebazaar/profile_function
Last synced: about 1 year ago
JSON representation
An easy profiling tool which collects elapsed time for functions and code blocks.
- Host: GitHub
- URL: https://github.com/cafebazaar/profile_function
- Owner: cafebazaar
- Created: 2018-07-28T11:55:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T21:08:10.000Z (over 2 years ago)
- Last Synced: 2024-09-20T09:23:01.904Z (almost 2 years ago)
- Language: Python
- Size: 9.77 KB
- Stars: 5
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Project Description
A simple profiling tool which collects elapsed time for functions and code blocks.
## Usage
Using `statsd`:
```python
from profile_function import ProfileFunction, StatsdBackend
import statsd
statsd_client = statsd.StatsClient('localhost', 8125)
pf = ProfileFunction(StatsdBackend(statsd_client))
@pf.profile_function(group="rpc")
def f(x, y):
s = 0
with pf.profile_block("for-loop"):
for i in range(x):
s += i * x + y
return s
```
Using logger:
```python
from profile_function import ProfileFunction, LoggerBackend
import logging
logger = logging.getLogger(__name__)
pf = ProfileFunction(LoggerBackend(logger, log_level=logging.DEBUG))
@pf.profile_function(group="rpc")
def f(x, y):
s = 0
with pf.profile_block("for-loop"):
for i in range(x):
s += i * x + y
return s
```
## Install
You can install `profile_function` using pip:
```bash
$ pip install profile-function
```
If you are using `statsd` you need to install it first. This project does not mentioned `statsd` as it own dependency. This command may be useful then:
```bash
$ pip install statsd
```
## Development:
You can write your own collector if you need by implementing `CollectorBackend`.