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.3.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zeitdieb-0.3.1.tar.gz
Algorithm Hash digest
SHA256 359ec82a0c76b10227ef361872aa4c992e06f9a4dca9e5071be62bd4ebd95392
MD5 bbdc0550dc25edda2de561dfa6a7f7f7
BLAKE2b-256 4a2a391f0ad8442ec6c46f09704cf1e8ca112d374340f063ff95f629c8caca90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zeitdieb-0.3.1-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.5.0

File hashes

Hashes for zeitdieb-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db96a4392814a566eb861a0a07242e5d12414182cab580d1d98ac3f2c6918860
MD5 908c64055d2d1a96ae4e3663955abc83
BLAKE2b-256 d0d14299cb5e956a37362fc89abc807a09d0d098f1dafb50deade34b8d35be2f

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