Runstats

整理一下tom大师的runstats检查工具包的脚本和使用示例,便于日后查看。运行runstats测试工具必须有访问V$STATNAME,V$MYSTAT,V$LATCH的权限,还必须有对SYS.V_$STATNAME,SYS.V_$MYSTAT,SYS.V_$LATCH的直接权限(不是通过角色授权)。

1.授权:

SQL> grant select on sys.v_$timer to jhondom;

Grant succeeded.

SQL> grant select on v_$mystat to jhondom;

Grant succeeded.

SQL> grant select on sys.v_$statname to jhondom;

Grant succeeded.

SQL> grant select on sys.v_$latch to jhondom;

Grant succeeded.

SQL> grant create view to jhondom;

Grant succeeded.

2.安装runstats包:

以jhondom用户登录执行以下操作:

(1)创建stats视图

SQL> create or replace view stats
  2  as
  3  select 'STAT..' || a.name name, b.value
  4  from v$statname a, v$mystat b
  5  where a.statistic# = b.statistic#
  6  union all
  7  select 'LATCH.' || name, gets
  8  from v$latch;

View created.

(2)创建run_stats临时表

SQL> create global temporary table run_stats
  2  ( runid varchar2(15),
  3  name varchar2(80),
  4  value int
  5  )on commit preserve rows;

Table created.

(3)创建runstats包头

SQL> create or replace package runstats
  2  as
  3  procedure rs_start;
  4  procedure rs_middle;
  5  procedure rs_stop( p_difference_threshold in number default 0);
  6  end;
  7  /

Package created.

p_difference_threshold参数的含义是:前后两个相同的项的统计结果相差的数目的绝对值大于等于该参数设定的值,该统计项才会被显示。默认值是0表示所有的结果都显示。

(4)创建runstats包体

SQL> create or replace package body runstats
  2  as
  3  g_start number;
  4  g_run1 number;
  5  g_run2 number;
  6  procedure rs_start
  7  is
  8  begin
  9  delete from run_stats;
 10  insert into run_stats
 11  select 'before', stats.* from stats;
 12  g_start := dbms_utility.get_time;
 13  end;
 14  procedure rs_middle
 15  is
 16  begin
 17  g_run1 := (dbms_utility.get_time-g_start);
 18  insert into run_stats
 19  select 'after 1', stats.* from stats;
 20  g_start := dbms_utility.get_time;
 21  end;
 22  procedure rs_stop(p_difference_threshold in number default 0)
 23  is
 24  begin
 25  g_run2 := (dbms_utility.get_time-g_start);
 26  --add a line here to avoid ora-20000
 27  dbms_output.enable(480000);
 28  dbms_output.put_line
 29  ( 'Run1 ran in ' || g_run1 || ' hsecs' );
 30  dbms_output.put_line
 31  ( 'Run2 ran in ' || g_run2 || ' hsecs' );
 32  dbms_output.put_line
 33  ( 'run 1 ran in ' || round(g_run1/g_run2*100,2) ||
 34  '% of the time' );
 35  dbms_output.put_line( chr(9) );
 36  insert into run_stats
 37  select 'after 2', stats.* from stats;
 38  dbms_output.put_line
 39  ( rpad( 'Name', 30 ) || lpad( 'Run1', 12 ) ||
 40  lpad( 'Run2', 12 ) || lpad( 'Diff', 12 ) );
 41  for x in
 42  ( select rpad( a.name, 30 ) ||
 43  to_char( b.value-a.value, '999,999,999' ) ||
 44  to_char( c.value-b.value, '999,999,999' ) ||
 45  to_char( ( (c.value-b.value)-(b.value-a.value)), '999,999,999' ) data
 46  from run_stats a, run_stats b, run_stats c
 47  where a.name = b.name
 48  and b.name = c.name
 49  and a.runid = 'before'
 50  and b.runid = 'after 1'
 51  and c.runid = 'after 2'
 52  -- and (c.value-a.value) > 0
 53  and abs( (c.value-b.value) - (b.value-a.value) )
 54  > p_difference_threshold
 55  order by abs( (c.value-b.value)-(b.value-a.value))
 56  ) loop
 57  dbms_output.put_line( x.data );
 58  end loop;
 59  dbms_output.put_line( chr(9) );
 60  dbms_output.put_line
 61  ( 'Run1 latches total versus runs -- difference and pct' );
 62  dbms_output.put_line
 63  ( lpad( 'Run1', 12 ) || lpad( 'Run2', 12 ) ||
 64  lpad( 'Diff', 12 ) || lpad( 'Pct', 10 ) );
 65  for x in
 66  ( select to_char( run1, '999,999,999' ) ||
 67  to_char( run2, '999,999,999' ) ||
 68  to_char( diff, '999,999,999' ) ||
 69  to_char( round( run1/run2*100,2 ), '99,999.99' ) || '%' data
 70  from ( select sum(b.value-a.value) run1, sum(c.value-b.value) run2,
 71  sum( (c.value-b.value)-(b.value-a.value)) diff
 72  from run_stats a, run_stats b, run_stats c
 73  where a.name = b.name
 74  and b.name = c.name
 75  and a.runid = 'before'
 76  and b.runid = 'after 1'
 77  and c.runid = 'after 2'
 78  and a.name like 'LATCH%'
 79  )
 80  ) loop
 81  dbms_output.put_line( x.data );
 82  end loop;
 83  end;
 84  end;
 85  /

Package body created.

至此runstats包安装完毕。

3.使用runstats包进行测试:

(1)创建测试表:

SQL> create table t(id number);

Table created.

(2)记录开始状态:
SQL> exec runstats.rs_start;

PL/SQL procedure successfully completed.

(3)执行第一段sql语句:

SQL> begin
  2  for i in 1..1000
  3  loop
  4  insert into t values(i);
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

(4)记录执行完第一段sql后的状态:

SQL> exec runstats.rs_middle;

PL/SQL procedure successfully completed.

(5)执行第二段sql语句:

SQL> begin
  2  for i in 1..1000
  3  loop
  4  execute immediate 'insert into t values('||i||')';
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

(5)记录执行完第二段sql后的状态并显示所有执行结果

SQL> exec runstats.rs_stop;
Run1 ran in 22702 hsecs
Run2 ran in 27107 hsecs
run 1 ran in 83.75% of the time

Name                                  Run1        Run2        Diff
STAT..redo synch writes                  1           0          -1
STAT..redo synch time                    1           0          -1
STAT..rows fetched via callbac           1           0          -1
STAT..Heap Segment Array Updat           1           0          -1
STAT..session cursor cache cou           1           0          -1
LATCH.post/wait queue                    4           5           1
LATCH.queued dump request                1           0          -1
LATCH.MinActiveScn Latch                 1           0          -1
LATCH.KTF sga latch                      2           1          -1
LATCH.ktm global data                    2           1          -1
LATCH.Shared B-Tree                      9          10           1
LATCH.SQL memory manager latch           8           9           1
LATCH.kwqbsn:qsga                        8           9           1
STAT..non-idle wait time                 2           0          -2
STAT..switch current to new bu           2           0          -2
STAT..shared hash latch upgrad           2           0          -2
LATCH.call allocation                   54          56           2
LATCH.kss move lock                      5           3          -2
LATCH.channel handle pool latc          20          22           2
LATCH.archive control                    3           5           2
LATCH.FAL Queue                          6           8           2
LATCH.managed standby latch              6           8           2
LATCH.dml lock allocation                6           4          -2
LATCH.lob segment hash table l           3           1          -2
LATCH.space background state o           2           0          -2
LATCH.resmgr:actses change gro           6           8           2
LATCH.Real-time plan statistic           3           5           2
LATCH.JS mem alloc latch                 2           0          -2
LATCH.JS queue access latch              3           1          -2
STAT..user I/O wait time                 3           0          -3
STAT..messages sent                      3           0          -3
LATCH.process group creation            18          21           3
LATCH.ksuosstats global area            15          18           3
LATCH.object stats modificatio           7           4          -3
LATCH.OS process: request allo          18          21           3
LATCH.ksz_so allocation latch           18          21           3
LATCH.sort extent pool                   5           8           3
LATCH.job workq parent latch             4           7           3
LATCH.hash table modification            3           0          -3
STAT..active txn count during            1           5           4
STAT..cleanout - number of ktu           1           5           4
STAT..HSC Heap Segment Block C       1,018       1,014          -4
LATCH.ksv class latch                    9           5          -4
LATCH.ksv allocation latch              12           8          -4
LATCH.Event Group Locks                  9          13           4
LATCH.qmn task queue latch              32          36           4
STAT..immediate (CURRENT) bloc           5           0          -5
STAT..workarea executions - op           7           2          -5
LATCH.session switching                 55          50          -5
LATCH.list of block allocation           7          12           5
STAT..physical read total IO r           6           0          -6
STAT..physical reads                     6           0          -6
STAT..physical reads cache               6           0          -6
STAT..physical read IO request           6           0          -6
STAT..deferred (CURRENT) block           6           0          -6
LATCH.archive process latch             18          24           6
LATCH.job_queue_processes free           6          12           6
LATCH.process allocation                26          33           7
LATCH.compile environment latc          11          18           7
STAT..hot buffers moved to hea          10           2          -8
STAT..calls to kcmgas                   11           3          -8
LATCH.Consistent RBA                    18          26           8
LATCH.parameter list                    14          22           8
LATCH.parallel query alloc buf          29          37           8
LATCH.kokc descriptor allocati           4          12           8
LATCH.parameter table manageme          24          33           9
LATCH.resmgr:free threads list          24          33           9
LATCH.dummy allocation                  25          34           9
LATCH.sequence cache                     9          18           9
LATCH.resmgr:active threads             24          33           9
STAT..non-idle wait count               14           4         -10
LATCH.FOB s.o list latch                14          24          10
STAT..commit cleanouts                  11           0         -11
STAT..commit cleanouts success          11           0         -11
LATCH.DML lock allocation               48          59          11
LATCH.session state list latch          29          40          11
LATCH.session allocation                91         103          12
LATCH.job_queue_processes para          52          64          12
LATCH.resmgr group change latc          18          32          14
LATCH.KMG MMAN ready and start          76          90          14
LATCH.threshold alerts latch             3          18          15
LATCH.Change Notification Hash          75          91          16
LATCH.PL/SQL warning settings           45          28         -17
LATCH.session timer                     78          96          18
STAT..consistent changes                60          40         -20
LATCH.lgwr LWN SCN                      83         104          21
LATCH.mostly latch-free SCN             83         104          21
LATCH.OS process                        79         100          21
LATCH.file cache latch                   1          23          22
STAT..bytes received via SQL*N       1,238       1,262          24
STAT..free buffer requested             38          14         -24
LATCH.session idle bit                  96         121          25
STAT..parse time cpu                     2          27          25
STAT..DB time                           20          45          25
LATCH.space background task la         173         198          25
STAT..workarea memory allocate           6          33          27
STAT..cluster key scans                 28           0         -28
LATCH.ASM db client latch              152         180          28
STAT..sorts (memory)                    29           0         -29
STAT..parse time elapsed                 1          32          31
LATCH.OS process allocation            126         157          31
STAT..recursive cpu usage                7          38          31
LATCH.undo global data                 103         135          32
LATCH.simulator lru latch               17          51          34
STAT..cluster key scan block g          34           0         -34
STAT..CPU used when call start           9          45          36
STAT..CPU used by this session           9          45          36
STAT..index fetch by key                37           0         -37
STAT..table fetch by rowid              47           8         -39
STAT..redo entries                   1,062       1,020         -42
LATCH.shared pool sim alloc              1          45          44
STAT..index scans kdiixs1               46           0         -46
LATCH.client/application info           78         132          54
LATCH.object queue header heap          99         154          55
LATCH.cache buffers lru chain           74         129          55
LATCH.active checkpoint queue           96         153          57
LATCH.simulator hash latch             473         407         -66
STAT..free buffer inspected             68           0         -68
STAT..execute count                  1,089       1,009         -80
STAT..opened cursors cumulativ       1,090       1,009         -81
LATCH.redo allocation                  214         297          83
STAT..db block changes               2,153       2,069         -84
STAT..calls to get snapshot sc          91           5         -86
LATCH.In memory undo latch             149         238          89
LATCH.redo writing                     310         420         110
LATCH.active service list              492         602         110
STAT..consistent gets - examin         120           5        -115
STAT..no work - consistent rea         131           8        -123
LATCH.object queue header oper         272         440         168
STAT..buffer is not pinned cou         216          16        -200
LATCH.channel operations paren       1,109       1,324         215
LATCH.JS queue state obj latch       1,620       1,944         324
STAT..sorts (rows)                     368           0        -368
LATCH.messages                       2,036       2,514         478
LATCH.checkpoint queue latch         1,615       2,110         495
STAT..consistent gets                  265       1,021         756
STAT..consistent gets from cac         265       1,021         756
STAT..consistent gets from cac         138       1,016         878
LATCH.SQL memory manager worka       5,111       6,057         946
STAT..enqueue requests                  43       1,004         961
STAT..enqueue releases                  41       1,004         963
STAT..parse count (total)               37       1,009         972
STAT..parse count (hard)                16       1,003         987
STAT..calls to kcmgcs                   30       1,024         994
STAT..session cursor cache hit       1,061           4      -1,057
LATCH.JS slv state obj latch          -366         695       1,061
STAT..recursive calls                2,245       4,034       1,789
STAT..db block gets from cache       1,156       3,062       1,906
STAT..db block gets                  1,156       3,062       1,906
STAT..db block gets from cache          27       2,000       1,973
LATCH.kks stats                         25       2,031       2,006
STAT..undo change vector size       73,392      71,192      -2,200
LATCH.shared pool simulator             36       2,631       2,595
STAT..session logical reads          1,421       4,083       2,662
LATCH.enqueues                       3,729       6,526       2,797
LATCH.enqueue hash chains            3,883       6,691       2,808
LATCH.cache buffers chains          11,584      16,207       4,623
STAT..redo size                    257,384     249,260      -8,124
STAT..session uga memory max       123,452     138,596      15,144
LATCH.row cache objects              2,272      21,232      18,960
STAT..file io wait time             25,934           0     -25,934
LATCH.shared pool                    2,388      42,276      39,888
STAT..physical read total byte      49,152           0     -49,152
STAT..physical read bytes           49,152           0     -49,152
STAT..cell physical IO interco      49,152           0     -49,152
STAT..session pga memory max             0      65,536      65,536
STAT..session uga memory            65,512     196,536     131,024
STAT..session pga memory            65,536     196,608     131,072

Run1 latches total versus runs -- difference and pct
Run1        Run2        Diff       Pct
39,482     117,930      78,448     33.48%

PL/SQL procedure successfully completed.

从以上可以看出,不使用绑定变量的执行效率明显低于使用绑定变量。

另:如果想统计同一项的统计值前后差异超过N的项,则执行:

SQL> exec runstats.rs_stop(N);




 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20523441/viewspace-760055/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20523441/viewspace-760055/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值