To time the execution of various stages of a long transaction, I’m using the following function:
CREATE OR REPLACE FUNCTION CVL_TimerLap() RETURNS double precision AS $$
import time
now = time.time()
if not SD.has_key('t_last'):
SD['t_last'] = now
elapsed = now - SD['t_last']
SD['t_last'] = now
return elapsed
$$ LANGUAGE plpythonu;
The “lap times” are returned using:
SELECT CVL_TimerLap();
This will return the number of seconds (wall-clock time) that have passed since the function was last invoked.
Leave a Reply
You must be logged in to post a comment.