Time utilities Isis software documentation

Time utilities

This document explains the various utilities for dealing with time in Isis, including timer objects, synchronizing networked computers, and putting the process to sleep.


(sleep seconds) # sleep for a number of seconds (microsleep microseconds) # sleep for a number of microseconds sleep and microsleep puts the process to sleep for the specified number of seconds or microseconds, which may be an integer or real number with a fractional part. They returns True after the interval has expired, or False if an error occurred.


An Isis timer is an object that keeps track of elapsed time. When you create a timer, it begins counting immediately from zero. At any time later, you can query the timer for the current elapsed time, or reset the timer to zero. (new-timer) # create a new timer object new-timer creates and returns a new timer object. This object is a procedure that you can call with different arguments to operate on the timer in different ways. (timer) # get elapsed time (timer 'r') # reset elapsed time to 0.0 Calling a timer with no arguments returns the current elapsed time, as a real number. Calling the timer with a single argument 'r' (for "reset") resets the timer to zero. (timer 'z') # get the "zero" system time of the timer (timer 'z' system-time) # set the "zero" system time of the timer (new-timer system-time) # sets "zero" system time on creation Calling a timer with a single argument 'z' returns the internal "zero" system time that the timer uses as a reference to determine the elapsed time, and by passing one additional argument, you can modify the zero system time. You can also pass a zero system time as an argument when you create the timer. You will only need to query and modify the zero system time of the timer if you are attempting to synchronize two or more timers in different processes or on different machines. See the section below for more information on system time. (print-frames-per-second timer framecount) # prints a nice fps message This utility routine accepts a timer and the number of "frames" or other items that have been processed since the zero time of that timer, and it prints a convenient "frames per second" message.

Below is an example that creates a timer, and prints out the elapsed time approximately every 2 seconds, and resets the timer every 30 seconds.

(set timer (new-timer)) # create a timer (while True # loop forever (begin (sleep 2) # sleep a couple seconds (set curtime (timer)) # get current time (print curtime "seconds have elapsed." newline) # print a message (if (> curtime 30.0) (timer 'r')))) # reset every 30 seconds

System time

(get-time) # get current system time [secs microsecs] (master-sync port reps) # synchronize system time on 2 machines (slave-sync port reps) # returns offset to ADD to master times

get-time retrieves the current system time, which serves as the base for all timing and synchronization in Isis. System times are represented as a list of two integers: the number of seconds and microseconds since January 1, 1970.

-> (get-time) [ 860617823 584033 ] -> (get-time) [ 860617831 514603 ]
master-sync and slave-sync provide a means of synchronizing system times on two machines. First, establish a connection between two machines. Then, on the master machine, call the master-sync function with the port used to communicate to the slave. On the slave machine, call slave-sync with the port used to communicate with the master. reps specifies the number of trials to perform and average over to find the result and must be the same on both machines. slave-sync will return a system time offset that should be added to master times in order to synchronize. See the example below.

On the "master" machine:

-> (set serv (tcp-listen 1234)) 3 -> (set port (tcp-accept serv)) 4 -> (master-sync port 20) 20 -> (master-sync port 20) 20 -> (master-sync port 20) 20 -> (slave-sync port 20) [ 0 -7988 ] -> (slave-sync port 20) [ 0 -7894 ] -> (slave-sync port 20) [ 0 -7530 ]
On the "slave" machine:
-> (set port (tcp-open "alphaville" 1234)) 3 -> (slave-sync port 20) [ 0 7693 ] -> (slave-sync port 20) [ 0 7274 ] -> (slave-sync port 20) [ 0 7324 ] -> (master-sync port 20) 20 -> (master-sync port 20) 20 -> (master-sync port 20) 20