Package: jort
jortTrack, 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.Installationpip install jortScript TimingUse theTrackerto create named blocks throughout your code. Blocks needstartandstopcalls, and
multiple iterations are combined to summarize how long it takes to complete each leg. Thereportfunction
prints the results from all blocks. Ifstopis 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 = 10Alternatively, you can use single line checkpoints withtr.checkpoint(), which create timing blocks that close at the start of the next checkpoint. Note that you must use anothertr.stop()call to end the final checkpoint block.Function Decoratorsjortsupports timing functions with decorators, viaTracker.track. As in the first example:@tr.track
def my_script():
    sleep(1)
    for _ in range(10):
        sleep_1s()NotificationsNotifications 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 commandjort config.SMS handling is done through Twilio, which offers afree trial tier. As of now,jorthandles notifications locally, so you need to add your own credentials for each service.Saving to Databasejortallows you to save details of finished jobs to a local database. To save all blocks to database, use theto_dbkeyword. You can also optionally group jobs under a common "session" by specifying thesession_namekeyword: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 TimingTo track a new command, you can run:jort track your_commandIf 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-eor-tflags, respectively. For a full list of options, use the-hflag.To save job details to database, add the-dflag. You can specify the session name with-s, and havejortskip jobs that both are already saved in the database under the same session and have completed successfully via the-uoption.You can also track an existing process using its integer process ID:jort track PIDSimilarly, add the-eor-tflags for either e-mail or SMS notification on completion, and-dand-sflags for saving info to database.Future DirectionsSave runtimes and other details in persistent formatPotential support for more complex profilingOffer a centralized option for notification handling