home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OVS_3031_NT.iso / win32 / tracesvr / otrcfunc.sql < prev    next >
Encoding:
Text File  |  1997-01-21  |  1.6 KB  |  42 lines

  1. -- OTRCFUNC.SQL
  2. --
  3. -- Defines the elapsed function for calculating elapsed time for Trace duration
  4. -- events.  Returns elapsed time in units of seconds.  It needs the collection 
  5. -- name to get the number of units in the nano fields.
  6. --
  7. -- Example:  select avg(elapsed('oracle7', 
  8. --                          x.timestamp_start, x.timestamp_nano_start,
  9. --                          x.timestamp_end, x.timestamp_nano_end))
  10. --           from v_192216243_f_5_e_9_7_3 x, epc_collection c
  11. --           where c.collection_name = 'oracle7' and
  12. --                 c.collection_id = x.collection_number;
  13.  
  14. CREATE OR REPLACE FUNCTION elapsed 
  15.                            (coll_name VARCHAR2, 
  16.                             start_time DATE,
  17.                             start_nanos NUMBER,
  18.                             end_time DATE,
  19.                             end_nanos NUMBER)
  20.    RETURN NUMBER 
  21. AS
  22.     ms_units NUMBER;                                -- # nanos per second
  23.     nanos NUMBER;
  24.     new_end_time DATE;
  25.     time NUMBER;
  26.     seconds NUMBER;
  27. BEGIN
  28.     SELECT ms_granularity INTO ms_units FROM epc_collection
  29.         WHERE collection_name = coll_name;
  30.     new_end_time := end_time;
  31.     nanos := end_nanos - start_nanos;
  32.     IF nanos < 0 THEN
  33.         new_end_time := end_time - (1/(60*60*24));  -- subtract 1 second
  34.         nanos := (ms_units + end_nanos) - start_nanos;
  35.     END IF;
  36.     time := new_end_time - start_time;              -- in units of days
  37.     seconds := time * (60*60*24);                   -- days * seconds/day
  38.     seconds := seconds + (nanos/ms_units);
  39.     RETURN(seconds);
  40. END;
  41. /
  42.