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

Uploaded Source

Built Distribution

zeitdieb-0.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zeitdieb-0.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a4fd576a9b857b2ce5f099c094b235eafad96b37a9b15e3b7cd27669949ebd01
MD5 0f59bb68e0045b3b245a2b6ad5d4b596
BLAKE2b-256 0745b09ca7d4757cd17ea5aaa9ae9d5e308057d5ae02f91bac72b306cfc0f044

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zeitdieb-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 163eb5374fc0c5aa95f977140af0fdd5e263dcf74cf58e430cafc0fbf23190a3
MD5 e146ba7b9085995c904100ebb7a8beb2
BLAKE2b-256 3032f16c36be47deb143c79fde87064333f29d48277cf15262ee5007fe08b6d7

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