Skip to main content

No project description provided

Project description

Zeitdieb

Zeitdieb allows you to profile the time each line of your code takes.

Screenshot of the output of zeitdieb

pip install zeitdieb

Manual usage

with StopWatch(additional, callables) as sw:
    your()
    code()
print(sw)

Alternatively, without using the context manager:

sw = StopWatch(additional, callables)
sw.start()
your()
code()
sw.finish()
print(sw)

Formatting

While you can just print the StopWatch object, you can also customize the output by using f-strings:

print(f"{sw:3b:0.3,0.1}")

The format spec looks like this: [width][flags]:[threshold][,threshold].

  • width specifies the width of the time column (e.g. 4 for an output like 2.01)
  • flags are single-letter flags influencing the output:
    • b enables barplot mode: Instead of a numeric time output, a vertical barplot will be printed
  • thresholds specify where to start marking times as critical/warnings (red/yellow). The thresholds must be ordered (highest to lowest).

Integrations

Zeitdieb can optionally be intregrated with Pyramid, Flask, or FastAPI. After you've done so, you can trigger tracing with the special header X-Zeitdieb.

Pyramid

Put this somewhere in your Pyramid settings:

zeitdieb.format = 20b

pyramid.tweens =
    ...
    zeitdieb.pyramid

Flask

For Flask or flask-based frameworks, adjust your create_app() function:

def create_app():
    ...
    my_flask_app.config["ZEITDIEB_FORMAT"] = "7b:0.5"
    zeitdieb.flask(my_flask_app)

FastAPI

FastAPI can be configured by calling zeitdieb.fastapi() inside of create_app():

class Settings(...):
    ...
    zeitdieb_format: Optional[str] = "6b"

def create_app(...):
    ...
    zeitdieb.fastapi(app, settings)

Settings client headers

To trigger the tracing of functions, you need to set an X-Zeitdieb header:

curl

$ curl https://.../ -H 'X-Zeitdieb: path.to.module:callable,path.to.othermodule:callable`

jsonrpclib

jsonrpclib.ServerProxy(host, headers={"X-Zeitdieb": "path.to.module:callable,path.to.othermodule:callable"})

Acknowledgements

This project was created as a result of a learning day @ solute.

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

zeitdieb-0.2.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

zeitdieb-0.2.0-py3-none-any.whl (5.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