Skip to content

An easy profiling tool which collects elapsed time for functions and code blocks.

Notifications You must be signed in to change notification settings

cafebazaar/profile_function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Project Description

A simple profiling tool which collects elapsed time for functions and code blocks.

Usage

Using statsd:

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:

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:

$ 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:

$ pip install statsd

Development:

You can write your own collector if you need by implementing CollectorBackend.

About

An easy profiling tool which collects elapsed time for functions and code blocks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages