Oracle PL/SQL编程之如何实现程序来统计另一个程序的性能(接上一篇 优化后)
2013-03-12 15:15
791 查看
不多说,直接上代码
/*******创建表ct用于保存第一次运行程序采集到的信息和优化后采集到的信息*******/
--drop table ct;
--create table ct(name varchar2(50),firstvalue number(8));
/*******创建表isFirst用于标识要测试的程序是第一次运行还是优化后运行*******/
--drop table isFirst;
--create table isFirst(first number(1));
--insert into isFirst values(0);
/************
设计思路:
oracle中创建以上两张表,当第一次运行被测试程序是,本程序采集被测试程序运行信息并存储到表ct中firstvalue列中,
同时修改isFirst表中first的值为1,表示被测试程序已经运行第一次。同时输出采集到的信息。当被测试程序优化后再次
运行,本程序采集被测试程序的运行信息插入到表ct中secondvalue中,同时修改isFirst表中first的值为0,将表中firstvalue
和secondvalue字段比较得出差值输出给用户即可。同时删除表ct中的行,节省空间。
************/
declare
b_isfirst number(1);
i_sid binary_integer :=0;
begin
select sid into i_sid from v$mystat where rownum = 1;
select first into b_isfirst from isFirst; --判断是否为第一次运行程序
declare
begin
if b_isfirst = 0 then
insert into ct select stat_name, value from V$SESS_TIME_MODEL where sid=i_sid and stat_name in('DB time','DB CPU');
insert into ct
select name,value
from v$sesstat a,v$statname b
where a.STATISTIC#=b.STATISTIC# and
sid=i_sid and
name in ('session logical reads',
'physical read IO requests',
'physical write IO requests');
commit;
dbms_output.put_line('**************采集******************');
for cur1 in (select name,firstvalue from ct) loop
dbms_output.put_line(cur1.name||':'||cur1.firstvalue);
end loop;
dbms_output.put_line('**************采集完毕**************');
update isFirst set first=1;
commit;
else
dbms_output.put_line('**************比较******************');
for cur1 in (select stat_name, value from V$SESS_TIME_MODEL where sid=i_sid and stat_name in('DB time','DB CPU')) loop
for cur2 in (select * from ct where name=cur1.stat_name ) loop
dbms_output.put_line(cur1.stat_name||' increase:'||(cur1.value-cur2.firstvalue));
end loop;
end
4000
loop;
for cur1 in (select name,value from v$sesstat a,v$statname b
where a.STATISTIC#=b.STATISTIC# and sid=i_sid and name in
('session logical reads','physical read IO requests',
'physical write IO requests') ) loop
for cur2 in (select * from ct where name=cur1.name ) loop
dbms_output.put_line(cur1.name||' increase:'||(cur1.value-cur2.firstvalue));
end loop;
end loop;
dbms_output.put_line('**************比较完毕**************');
update isFirst set first=0;
commit;
delete from ct;
commit;
end if;
end;
end;
/*******创建表ct用于保存第一次运行程序采集到的信息和优化后采集到的信息*******/
--drop table ct;
--create table ct(name varchar2(50),firstvalue number(8));
/*******创建表isFirst用于标识要测试的程序是第一次运行还是优化后运行*******/
--drop table isFirst;
--create table isFirst(first number(1));
--insert into isFirst values(0);
/************
设计思路:
oracle中创建以上两张表,当第一次运行被测试程序是,本程序采集被测试程序运行信息并存储到表ct中firstvalue列中,
同时修改isFirst表中first的值为1,表示被测试程序已经运行第一次。同时输出采集到的信息。当被测试程序优化后再次
运行,本程序采集被测试程序的运行信息插入到表ct中secondvalue中,同时修改isFirst表中first的值为0,将表中firstvalue
和secondvalue字段比较得出差值输出给用户即可。同时删除表ct中的行,节省空间。
************/
declare
b_isfirst number(1);
i_sid binary_integer :=0;
begin
select sid into i_sid from v$mystat where rownum = 1;
select first into b_isfirst from isFirst; --判断是否为第一次运行程序
declare
begin
if b_isfirst = 0 then
insert into ct select stat_name, value from V$SESS_TIME_MODEL where sid=i_sid and stat_name in('DB time','DB CPU');
insert into ct
select name,value
from v$sesstat a,v$statname b
where a.STATISTIC#=b.STATISTIC# and
sid=i_sid and
name in ('session logical reads',
'physical read IO requests',
'physical write IO requests');
commit;
dbms_output.put_line('**************采集******************');
for cur1 in (select name,firstvalue from ct) loop
dbms_output.put_line(cur1.name||':'||cur1.firstvalue);
end loop;
dbms_output.put_line('**************采集完毕**************');
update isFirst set first=1;
commit;
else
dbms_output.put_line('**************比较******************');
for cur1 in (select stat_name, value from V$SESS_TIME_MODEL where sid=i_sid and stat_name in('DB time','DB CPU')) loop
for cur2 in (select * from ct where name=cur1.stat_name ) loop
dbms_output.put_line(cur1.stat_name||' increase:'||(cur1.value-cur2.firstvalue));
end loop;
end
4000
loop;
for cur1 in (select name,value from v$sesstat a,v$statname b
where a.STATISTIC#=b.STATISTIC# and sid=i_sid and name in
('session logical reads','physical read IO requests',
'physical write IO requests') ) loop
for cur2 in (select * from ct where name=cur1.name ) loop
dbms_output.put_line(cur1.name||' increase:'||(cur1.value-cur2.firstvalue));
end loop;
end loop;
dbms_output.put_line('**************比较完毕**************');
update isFirst set first=0;
commit;
delete from ct;
commit;
end if;
end;
end;
相关文章推荐
- Oracle PL/SQL编程之如何实现程序来统计另一个程序的性能
- oracle柱状分析,实现sql性能优化
- Oracle Pl/Sql 性能优化
- Oracle Pl/Sql 性能优化
- Oracle PL/SQL编程-存储过程优缺点及实现过程【1】
- 用Oracle PL/SQL 编程实现小数转分数的方法
- SQL编程性能优化--ORACLE
- 转- oracle10g-如何提高pl/sql程序的性能
- 如何使用Oracle中autotrace来实现性能优化
- [转载]Oracle8 PL/SQL编程风格与系统性能的提高
- 用PL/SQL语言编写一程序,实现按部门分段统计各个工资段的职工人数、以及各部门的工资总额
- 用Oracle PL/SQL 编程实现小数转分数的方法
- PL/SQL编程实现Oracle分页 java调用
- 数组比特【编程珠玑】如何优化程序打印出小于100000的素数
- matlab程序性能优化与混合编程技术介绍
- 如何在不安装Oracle Client的情况下使用PL/SQL Developer
- Oracle PL/SQL编程详解之七:程序包的创建与应用
- Oracle SQL性能优化
- Oracle(26)pl/sql编程 例外处理
- oracle pl/sql 无监听程序