Advertisement
VoronVU

Untitled

Mar 31st, 2015
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE PACKAGE runstats_pkg
  2. AS
  3.     PROCEDURE rs_start;
  4.     PROCEDURE rs_middle;
  5.     PROCEDURE rs_stop( p_difference_threshold IN NUMBER DEFAULT 0 );
  6. END;
  7. /
  8.  
  9. CREATE OR REPLACE PACKAGE BODY runstats_pkg
  10. AS
  11.  
  12. g_start NUMBER;
  13. g_run1  NUMBER;
  14. g_run2  NUMBER;
  15.  
  16. PROCEDURE rs_start
  17. IS
  18. BEGIN
  19.     DELETE FROM run_stats;
  20.  
  21.     INSERT INTO run_stats
  22.     SELECT 'before', stats.* FROM stats;
  23.        
  24.     g_start := dbms_utility.get_cpu_time;
  25. END;
  26.  
  27. PROCEDURE rs_middle
  28. IS
  29. BEGIN
  30.     g_run1 := (dbms_utility.get_cpu_time-g_start);
  31.  
  32.     INSERT INTO run_stats
  33.     SELECT 'after 1', stats.* FROM stats;
  34.     g_start := dbms_utility.get_cpu_time;
  35.  
  36. END;
  37.  
  38. PROCEDURE rs_stop(p_difference_threshold IN NUMBER DEFAULT 0)
  39. IS
  40. BEGIN
  41.     g_run2 := (dbms_utility.get_cpu_time-g_start);
  42.  
  43.     dbms_output.put_line
  44.     ( 'Run1 ran in ' || g_run1 || ' cpu hsecs' );
  45.     dbms_output.put_line
  46.     ( 'Run2 ran in ' || g_run2 || ' cpu hsecs' );
  47.         IF ( g_run2 <> 0 )
  48.         THEN
  49.     dbms_output.put_line
  50.     ( 'run 1 ran in ' || ROUND(g_run1/g_run2*100,2) ||
  51.       '% of the time' );
  52.         END IF;
  53.     dbms_output.put_line( CHR(9) );
  54.  
  55.     INSERT INTO run_stats
  56.     SELECT 'after 2', stats.* FROM stats;
  57.  
  58.     dbms_output.put_line
  59.     ( RPAD( 'Name', 30 ) || LPAD( 'Run1', 12 ) ||
  60.       LPAD( 'Run2', 12 ) || LPAD( 'Diff', 12 ) );
  61.  
  62.     FOR x IN
  63.     ( SELECT RPAD( a.name, 30 ) ||
  64.              TO_CHAR( b.value-a.VALUE, '999,999,999' ) ||
  65.              TO_CHAR( c.value-b.VALUE, '999,999,999' ) ||
  66.              TO_CHAR( ( (c.value-b.VALUE)-(b.value-a.VALUE)), '999,999,999' ) data
  67.         FROM run_stats a, run_stats b, run_stats c
  68.        WHERE a.name = b.name
  69.          AND b.name = c.name
  70.          AND a.runid = 'before'
  71.          AND b.runid = 'after 1'
  72.          AND c.runid = 'after 2'
  73.          -- and (c.value-a.value) > 0
  74.          AND ABS( (c.value-b.VALUE) - (b.value-a.VALUE) )
  75.                > p_difference_threshold
  76.        ORDER BY ABS( (c.value-b.VALUE)-(b.value-a.VALUE))
  77.     ) LOOP
  78.         dbms_output.put_line( x.data );
  79.     END LOOP;
  80.  
  81.     dbms_output.put_line( CHR(9) );
  82.     dbms_output.put_line
  83.     ( 'Run1 latches total versus runs -- difference and pct' );
  84.     dbms_output.put_line
  85.     ( LPAD( 'Run1', 12 ) || LPAD( 'Run2', 12 ) ||
  86.       LPAD( 'Diff', 12 ) || LPAD( 'Pct', 10 ) );
  87.  
  88.     FOR x IN
  89.     ( SELECT TO_CHAR( run1, '999,999,999' ) ||
  90.              TO_CHAR( run2, '999,999,999' ) ||
  91.              TO_CHAR( diff, '999,999,999' ) ||
  92.              TO_CHAR( ROUND( run1/DECODE( run2, 0, TO_NUMBER(NULL), run2) *100,2 ), '99,999.99' ) || '%' data
  93.         FROM ( SELECT SUM(b.value-a.VALUE) run1, SUM(c.value-b.VALUE) run2,
  94.                       SUM( (c.value-b.VALUE)-(b.value-a.VALUE)) diff
  95.                  FROM run_stats a, run_stats b, run_stats c
  96.                 WHERE a.name = b.name
  97.                   AND b.name = c.name
  98.                   AND a.runid = 'before'
  99.                   AND b.runid = 'after 1'
  100.                   AND c.runid = 'after 2'
  101.                   AND a.name LIKE 'LATCH%'
  102.                 )
  103.     ) LOOP
  104.         dbms_output.put_line( x.data );
  105.     END LOOP;
  106. END;
  107.  
  108. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement