Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PACKAGE runstats_pkg
- AS
- PROCEDURE rs_start;
- PROCEDURE rs_middle;
- PROCEDURE rs_stop( p_difference_threshold IN NUMBER DEFAULT 0 );
- END;
- /
- CREATE OR REPLACE PACKAGE BODY runstats_pkg
- AS
- g_start NUMBER;
- g_run1 NUMBER;
- g_run2 NUMBER;
- PROCEDURE rs_start
- IS
- BEGIN
- DELETE FROM run_stats;
- INSERT INTO run_stats
- SELECT 'before', stats.* FROM stats;
- g_start := dbms_utility.get_cpu_time;
- END;
- PROCEDURE rs_middle
- IS
- BEGIN
- g_run1 := (dbms_utility.get_cpu_time-g_start);
- INSERT INTO run_stats
- SELECT 'after 1', stats.* FROM stats;
- g_start := dbms_utility.get_cpu_time;
- END;
- PROCEDURE rs_stop(p_difference_threshold IN NUMBER DEFAULT 0)
- IS
- BEGIN
- g_run2 := (dbms_utility.get_cpu_time-g_start);
- dbms_output.put_line
- ( 'Run1 ran in ' || g_run1 || ' cpu hsecs' );
- dbms_output.put_line
- ( 'Run2 ran in ' || g_run2 || ' cpu hsecs' );
- IF ( g_run2 <> 0 )
- THEN
- dbms_output.put_line
- ( 'run 1 ran in ' || ROUND(g_run1/g_run2*100,2) ||
- '% of the time' );
- END IF;
- dbms_output.put_line( CHR(9) );
- INSERT INTO run_stats
- SELECT 'after 2', stats.* FROM stats;
- dbms_output.put_line
- ( RPAD( 'Name', 30 ) || LPAD( 'Run1', 12 ) ||
- LPAD( 'Run2', 12 ) || LPAD( 'Diff', 12 ) );
- FOR x IN
- ( SELECT RPAD( a.name, 30 ) ||
- TO_CHAR( b.value-a.VALUE, '999,999,999' ) ||
- TO_CHAR( c.value-b.VALUE, '999,999,999' ) ||
- TO_CHAR( ( (c.value-b.VALUE)-(b.value-a.VALUE)), '999,999,999' ) data
- FROM run_stats a, run_stats b, run_stats c
- WHERE a.name = b.name
- AND b.name = c.name
- AND a.runid = 'before'
- AND b.runid = 'after 1'
- AND c.runid = 'after 2'
- -- and (c.value-a.value) > 0
- AND ABS( (c.value-b.VALUE) - (b.value-a.VALUE) )
- > p_difference_threshold
- ORDER BY ABS( (c.value-b.VALUE)-(b.value-a.VALUE))
- ) LOOP
- dbms_output.put_line( x.data );
- END LOOP;
- dbms_output.put_line( CHR(9) );
- dbms_output.put_line
- ( 'Run1 latches total versus runs -- difference and pct' );
- dbms_output.put_line
- ( LPAD( 'Run1', 12 ) || LPAD( 'Run2', 12 ) ||
- LPAD( 'Diff', 12 ) || LPAD( 'Pct', 10 ) );
- FOR x IN
- ( SELECT TO_CHAR( run1, '999,999,999' ) ||
- TO_CHAR( run2, '999,999,999' ) ||
- TO_CHAR( diff, '999,999,999' ) ||
- TO_CHAR( ROUND( run1/DECODE( run2, 0, TO_NUMBER(NULL), run2) *100,2 ), '99,999.99' ) || '%' data
- FROM ( SELECT SUM(b.value-a.VALUE) run1, SUM(c.value-b.VALUE) run2,
- SUM( (c.value-b.VALUE)-(b.value-a.VALUE)) diff
- FROM run_stats a, run_stats b, run_stats c
- WHERE a.name = b.name
- AND b.name = c.name
- AND a.runid = 'before'
- AND b.runid = 'after 1'
- AND c.runid = 'after 2'
- AND a.name LIKE 'LATCH%'
- )
- ) LOOP
- dbms_output.put_line( x.data );
- END LOOP;
- END;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement