TaggedTimeLine

Author: Jaesun Park (GitHub: @moran991231)
You can use and modify this for free.

Intro

This is a kind of a stopwatch which has string tags.
I made this for analyse the latencies step by step.

|--step1--|----step2----|-----step3-----|--step4--|--...
^         ^             ^               ^         ^
|         |             |               |         |
init    step1         step2           step3     step4  ...

=>
step1: (the time interval between init  and step1)
step2: (the time interval between step1 and step2)
step3: (the time interval between step2 and step3)
step4: (the time interval between step3 and step4)

Function & Usage

  • linear analysis (no loop) => see the ex_noloop() in the /example.py
    tag_time = tt.TaggedTimeLine()
    print("sleeping...");sleep(1);tag_time.check(tag ="1. sleep")
    print("having a lunch...");sleep(1.3);tag_time.check(tag = "2. have lunch")
    print("studying python...");sleep(1);tag_time.check(tag = "3. study python")
    print("attending a lecture...");sleep(2);tag_time.check(tag = "4. attend a lecture")
    print("having a dinner...");sleep(1);tag_time.check(tag = "5. have dinner")
    print("\n-- print all --")
    tag_time.print_all()

    output:
:::: Example Without Loop ::::
 My Daily Routine
sleeping...
having a lunch...
studying python...
attending a lecture...
having a dinner...

-- print all --
(1. sleep 1.0104 s) (2. have lunch 1.3005 s) (3. study python 1.0047 s) (4. attend a lecture 2.0022 s) (5. have dinner 1.0075 s) (total 6.3254 s)

-- print tag --
5. have dinner:1.0075s

-- print interval --
2. have lunch's end ~ 5. have dinner : 4.0144s
  • Iteration analysis (loop) => see the ex_loop() in the /example.py
    while True:
    tag_time.start() # !Impoortant! call start on the top of the loop
    print("\n! loop !")
    print("sleeping...");sleep(1);tag_time.check(tag ="1. sleep")
    print("having a lunch...");sleep(1.3);tag_time.check(tag ="2. have lunch")
    print("studying python...");sleep(1);tag_time.check(tag="3. study python")
    print("attending a lecture...");sleep(2);tag_time.check(tag ="4. attend a lecture")
    print("having a dinner...");sleep(1);tag_time.check(tag ="5. have dinner")
    isStopping = tag_time.accumulate(increment = 1) # !Important!
    print("-- print all --")
    tag_time.print_all()
    # you can add print_tag or print_interval here
    # print("\n-- print tag --")
    # tag_time.print_tag("5. have dinner")
    # print("\n-- print interval --")
    # tag_time.print_interval("2. have lunch","5. have dinner" )
    if(isStopping):
    break
    print("\n-- print avg --")
    tag_time.print_avg(delimiter = "\n ")
    output:
:::: Example With Loop ::::
 My Daily Routine

! loop !
sleeping...
having a lunch...
studying python...
attending a lecture...
having a dinner...
-- print all --
(1. sleep 1.0031 s) (2. have lunch 1.3004 s) (3. study python 1.0035 s) (4. attend a lecture 2.0137 s) (5. have dinner 1.0109 s) (total 6.3317 s)

! loop !
sleeping...
having a lunch...
studying python...
attending a lecture...
having a dinner...
-- print all --
(1. sleep 1.0088 s) (2. have lunch 1.3094 s) (3. study python 1.0052 s) (4. attend a lecture 2.0136 s) (5. have dinner 1.0044 s) (total 6.3414 s)

sleeping...
having a lunch...
studying python...
attending a lecture...
having a dinner...
-- print all --
(1. sleep 1.0077 s) (2. have lunch 1.3090 s) (3. study python 1.0089 s) (4. attend a lecture 2.0108 s) (5. have dinner 1.0032 s) (total 6.3395 s)

-- print avg --
The average of accumulated latency per loop:
 (1. sleep 1.0082 s)
 (2. have lunch 1.3092 s)
 (3. study python 1.0070 s)
 (4. attend a lecture 2.0122 s)
 (5. have dinner 1.0038 s)
 (total 6.3405 s)