部署Thomas Kyte 的 runstats 工具

runstats是由Thomas Kyte开发的脚本,该脚本能对做同一件事的两个不同方法进行比较,得出孰优孰劣的结果。

1.授权

SQL> grant select on v_$statname to livan;

Grant succeeded.

SQL> grant select on v_$mystat to livan;

Grant succeeded.

SQL> grant select on v_$timer to livan;

Grant succeeded.

SQL> grant select on v_$latch to livan;

Grant succeeded.

2.创建视图

SQL> conn livan/livan
Connected.
SQL> create or replace view stats
  2  as select ‘STAT...‘ || a.name name,b.value
  3  from v$statname a, v$mystat b
  4  where a.statistic# = b.statistic#
  5  union all
  6  select ‘LATCH.‘ || name,gets
  7  from v$latch
  8  union all
  9  select ‘STAT...Elapsed Time‘,hsecs from v$timer;

View created.

3.创建统计结果临时表

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.

4.创建runstats包

--runstats开始调用rs_start
--rs_middle在中间调用
--完成时调用rs_stop,并打印报告

--创建包头

SQL> 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  /

Package created.

--创建包体

[[email protected] ~]$ vi body_runstats_pkg.sql

    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,‘9,999,999‘)||
       to_char(run2,‘9,999,999‘)||
       to_char(diff,‘9,999,999‘)||
       to_char(round(run1/decode(run2,0,to_number(0),run2*100,2)),‘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;

"body_runstats_pkg.sql" [New] 95L, 2589C written

SQL> @body_runstats_pkg.sql
 96  /

Package body created.

5.测验

SQL> execute runstats_pkg.rs_start;

PL/SQL procedure successfully completed.

SQL> insert into t1 select * from dba_objects;

72898 rows created.

SQL> commit;

Commit complete.

SQL> execute runstats_pkg.rs_middle;

PL/SQL procedure successfully completed.

SQL> begin
  2  for x in (select * from dba_objects)
  3  loop
  4  insert into t2 values x;
  5  end loop;
  6  commit;
  7  end;
  8  /

PL/SQL procedure successfully completed.

SQL> execute runstats_pkg.rs_stop(10000000);

PL/SQL procedure successfully completed.

SQL> set serveroutput on
SQL> execute runstats_pkg.rs_stop(10000000);
Run1 ran in60cpu hsecs
Run2 ran in425cpu hsecs
run 1 ran in14.12% of the time

Name                                  Run1        Run2        Diff
STAT...redo size                 8,577,680  29,178,972  20,601,292
STAT...redo size                 8,577,680  29,183,900  20,606,220

Run1 latches total versus runs -- difference and pct
Run1        Run2        Diff       Pct
146,010 1,069,172   923,162%

PL/SQL procedure successfully completed.

show_space过程参考博主:

http://blog.csdn.net/huang_xw/article/details/7015349

时间: 2024-10-29 19:05:31

部署Thomas Kyte 的 runstats 工具的相关文章

【CentOS】部署开源企业级Linux备份工具—BackupPC

BackupPC安装所需的主要的安装包下载地址:http://pan.baidu.com/s/1bnCGCY7 (BackupPC的版本为3.2.1) (该版本的BackupPC是支持中文的,BackupPC配置好后,可以在其Web页面设置其显示语言即可) 1.添加backuppc组及用户 groupadd   backuppc useradd   -g   backuppc   backuppc 2.安装httpd.mod_perl及BackupPC yum   install   httpd

一键快速部署CodeBlocks的EGE图形库工具

大一下学期,学完了c语言的基本内容, 也就开始开发项目了,此时一个图形界面就比较重要了,c语言中不提供图形界面,一般这些是用的其它开发的图形库,如 Easyx .ege等. 本文就提供 Codeblocks 快速部署ege图形库的小工具,其实就是方便些,原理是一样的复制对应的文件到相应的文件夹中,只是使用了bat命令来批量快速地复制罢了. 工具下载链接 链接:https://pan.baidu.com/s/1pFUBcjmE0dNketwIc6AQrA Password:jb8s 下载解压后,双

分布式系统部署和编译相关的工具和文章链接

最近在关注 分布式部署相关的工具和方法,下面是一些有趣的链接: Linux PXE + Kickstart 自动装机 https://www.cnblogs.com/llife/p/11632933.html 本文章作用,主要是用来进行索引文档链接信息,保持更新,更多内容请关注 cnblogs.com/xuyaowen 原文地址:https://www.cnblogs.com/xuyaowen/p/Distributed-deployment.html

部署系统漏洞的检测工具总结

系统上线后,对于系统的安全如何评测,此处说明几个开源的工具,一些渗透测试工具,可以检测系统,WEB站点等. 使用这些工具检查并修复,都一般的小站点的安全性提高不少 系统漏洞扫描OpenVAS http://www.openvas.org/ 可以直接下载虚拟机版本 http://www.openvas.org/vm.html 默认用户   linux系统 root/openvas, WEB系统 https://###  admin/admin g 通过这个工具可以扫描到很多的系统漏洞并根据报告的建

部署安装snort--入侵检测工具

1:部署安装snort yum -y install wget 2: 基本依赖环境 yum -y install gcc flex bison zlib zlib-devel libpcap libpcap-devel pcre pcre-devel libdnet libdnet-devel tcpdump yum -y install epel-release nghttp2 yum -y install glibc-headers gcc-c++ 下载软件 wget https://www

我和Thomas Kyte

系统自动化安装部署工具&mdash;&mdash;cobbler

本节我们来讲一讲系统自动化安装工具,大家应该还记得我在在前面的内容中曾经有讲过一个跟这个类似的PXE安装环境,而本节我们要讲的这个cobbler其实就是PEX的加强版,那么下面我们就来学习下如何部署安装吧. cobbler的介绍 cobbler是一个部署和创建系统的工具,他的主要功能就是通过一些自动化的操作来简化系统管理员的操作,他也可以使虚拟化操作变的简化:其组成部分主要包括cobbler和cobbler_web两部分. cobbler所依赖的服务 想要组件一个cobbler环境,还得有以下几

超级简便的容器化部署工具(使用 ASP.NET Core 演示)

Docker 改变了我们部署网站的方式,从原先的手动编译打包上传,到现在的构建镜像然后推送部署,让我们在配置环境上所花费的时间大大减少了.不仅如此,通过一系列相关的工具配合,可以很轻松的实现 CI.CD.本文即将介绍的就是这么一款非常简便的工具--captainduckduck,使用 captainduckduck 只需要很少的 Docker 知识. 简介 原先,我们的部署流程可能是这样的: 拉取代码 -> 构建镜像 -> 启动容器 除此之外,还需要配置 HTTPS,配置反向代理,如果要更新应

持续集成工具jenkins部署发布JAVA项目(二)

一.部署环境系统 Centos7和上期的jenkins在一台主机,jenkins服务使用的tomcat是8080端口,本次JAVA项目部署使用的tomcat是8090端口 二.部署流程和所需工具 所需工具: maven.tomcat 三.部署过程1.修改部署JAVA项目的tomcat端口为8090将解压的tomcat包放到/opt下修改端口为8090vim conf/server.xml将所有端口号都加10 ,防止与主服务冲突 2.在jenkins上创建testDeploy任务 设置jenkin