Skip to main content

Script profiler with checkpoints

Project description

jort

PyPI version Documentation Status

  • Track, profile, and notify at custom blocks in your coding scripts.
  • Time new and existing shell commands with a convenient command line tool.
  • Save and view details of finished jobs with a local database. jort help message

Installation

pip install jort

Script Timing

Use the Tracker to create named blocks throughout your code. Blocks need start and stop calls, and multiple iterations are combined to summarize how long it takes to complete each leg. The report function prints the results from all blocks. If stop is not supplied a block name, the tracker will close and calculate elapsed time from the last open block (i.e. last in, first out).

import jort
from time import sleep

tr = jort.Tracker()

tr.start('my_script')
sleep(1)
for _ in range(10):
    tr.start('sleep_1s')
    sleep(1)
    tr.stop('sleep_1s')
tr.stop('my_script')
    
tr.report()

The printed report appears as:

my_script | 11.0 s ± 0.0 s per iteration, n = 1
sleep_1s | 1.0 s ± 0.0 s per iteration, n = 10

Alternatively, you can use single line checkpoints with tr.checkpoint(), which create timing blocks that close at the start of the next checkpoint. Note that you must use another tr.stop() call to end the final checkpoint block.

Function Decorators

jort supports timing functions with decorators, via Tracker.track. As in the first example:

@tr.track
def my_script():
    sleep(1)
    for _ in range(10):
        sleep_1s()

Notifications

Notifications are handled by callbacks to timing functions. As of now, there are three main callbacks:

jort.PrintReport()
jort.EmailNotification()
jort.TextNotification()

To use notifications, add callbacks to tracking functions:

# linear script
tr.stop('my_script', callbacks=[jort.PrintReport(), jort.TextNotification()])

# function decorator
@tr.track(callbacks=[jort.EmailNotification()])
def my_script():
    [...]

For SMS text and e-mail notifications, you can enter credentials with the command jort config.

SMS handling is done through Twilio, which offers a free trial tier. As of now, jort handles notifications locally, so you need to add your own credentials for each service.

Saving to Database

jort allows you to save details of finished jobs to a local database. To save all blocks to database, use the to_db keyword. You can also optionally group jobs under a common "session" by specifying the session_name keyword:

tr = jort.Tracker(to_db=True, session_name="my_session")

If you do not want every block to be saved, you can specify manually:

tr.stop('my_script', to_db=True)

@tr.track(to_db=True)
def my_script():
    [...]

Command Line Timing

jort track help

To track a new command, you can run:

jort track your_command

If the target command uses its own options, place quotes around the full command.

jort track "your_command -a -b -c"

To send notifications on completion via e-mail or text, add the -e or -t flags, respectively. For a full list of options, use the -h flag.

To save job details to database, add the -d flag. You can specify the session name with -s, and have jort skip jobs that both are already saved in the database under the same session and have completed successfully via the -u option.

You can also track an existing process using its integer process ID:

jort track PID

Similarly, add the -e or -t flags for either e-mail or SMS notification on completion, and -d and -s flags for saving info to database.

Future Directions

  • Save runtimes and other details in persistent format
  • Potential support for more complex profiling
  • Offer a centralized option for notification handling

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

jort-1.5.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

jort-1.5.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file jort-1.5.0.tar.gz.

File metadata

  • Download URL: jort-1.5.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for jort-1.5.0.tar.gz
Algorithm Hash digest
SHA256 c6e8a5f27f719098d619b688380f3fe3f657751faefb323b0a2170ceb964ae2a
MD5 d350072b308f0db2af1d36e483141fff
BLAKE2b-256 5ffdd634df9ff77cd6d02b473ca9834a7a33f3acc34ca15e721315642801b062

See more details on using hashes here.

File details

Details for the file jort-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: jort-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for jort-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a12ae4fdba3e604dba6378cd70605827582b83be3857d8090e0f036d767abfb4
MD5 d032ce81973e2b7dfa3390f33c160363
BLAKE2b-256 47d059468bcc626ccc04112bf8e4ecf7f51558d2185ff32211979bfd9409892b

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