No project description provided
Project description
Zeitdieb
Zeitdieb allows you to profile the time each line of your code takes.
pip install zeitdieb
Manual usage
sw = StopWatch.install(additional, callables)
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 like2.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
threshold
s 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
:
$ curl https://.../ -H 'X-Zeitdieb: path.to.module:callable,path.to.othermodule:callable`
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)
Project details
Release history Release notifications | RSS feed
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.1.0.tar.gz
(4.5 kB
view hashes)