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 details)

Uploaded Source

Built Distribution

zeitdieb-0.2.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file zeitdieb-0.2.0.tar.gz.

File metadata

  • Download URL: zeitdieb-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Darwin/23.1.0

File hashes

Hashes for zeitdieb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2b998a637d8bb3e652e59b57374af23fbb83fe801b54f7bd460ce387bf7fd0dd
MD5 e9f8e827cb30cb816926748b23a43295
BLAKE2b-256 04be5882e64cb468927fc04ae065121ab52071a25938bfc7c6194e482b712fa8

See more details on using hashes here.

File details

Details for the file zeitdieb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: zeitdieb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Darwin/23.1.0

File hashes

Hashes for zeitdieb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b1da9197f4a3a7d8b241a18c2585eb055fb0d5fe179bee8ce9e6ce3b710c677
MD5 916f77b9e4b1782a518bf472f4b5c875
BLAKE2b-256 609b727c70ec6045a31aeec3cf55c0f5b7e6f63eb89194f9077cd6eb0e5e4adc

See more details on using hashes here.

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