Skip to main content

Time utilities for Python code

Project description

Chronologger

Time utilities for Python1

Build Status Coverage Status

Requirements

Requirements: Python >= 3.6

Use the Makefile targets to access most of the functionality: make install-dev, make dbuild, make drun, make dstart...

Otherwise...

Install

pip install git+https://git@github.com/francisco-perez-sorrosal/chronologger.git

Run the Simple Example

Docker

Clone the project...

git clone git@github.com:francisco-perez-sorrosal/chronologger.git

and then...

cd chronologger
docker build -f Dockerfile.example -t chronologger-example .
docker run -itd --name chronologger-example chronologger-example:latest
docker exec -it chronologger-example python simple_example.py 

Local

After installing the package, just clone the project and execute example with:

git clone git@github.com:francisco-perez-sorrosal/chronologger.git ; cd chronologger
python examples/simple_example.py

or open your python environment/IDE and execute:

import time

from chronologger import Timer, TimeUnit, root_timer


# Example of decorator: This should report ~100ms each time that is called
@Timer(name="Foo method!", unit=TimeUnit.ms, simple_log=True)
def foo():
    time.sleep(0.1)


def main():
    # Example of explicit timer: This should report ~100ms
    timer = Timer("Individual Timer", unit=TimeUnit.ms).start()
    time.sleep(0.1)
    timer.stop()

    # Example of explicit context timer: This should report ~1s
    with Timer(name="Test Loop!", unit=TimeUnit.s, simple_log=True) as timer:
        for i in range(5):
            time.sleep(0.1)  # e.g. simulate IO
            foo()
            timer.mark("i_{}".format(i))


if __name__ == "__main__":
    root_timer.label("   STARTING!!!")
    main()
    root_timer.label("   PRINTING TIME")
    root_timer.print()

Development

Install:

make install-dev

Use other commands in the Makefile for extra functionality.

Docker

make dbuild
make drun
make dtests

Use other commands in the Makefile for extra functionality.

IDE (PyCharm) Docker Interpreter

Once you create the Docker image with make dbuild you can specify the chronologger-dev:latest image as a Ptyhon Docker interpreter in IntelliJ/PyCharm for example.


1: Inspired by the blog post Python Timer Functions: Three Ways to Monitor Your Code by Geir Arne Hjelle

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chronologger-0.0.0.dev23.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distribution

chronologger-0.0.0.dev23-py3-none-any.whl (13.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page