以前写过用external table来加载trace文件,详情参考下面链接.

http://www.cnblogs.com/princessd8251/p/3779145.html

今天要做到是用UTL_FILE包来读取一个directory下面的文件,比如我们的trace文件.

先定义get_trace_file 函数.

-- create directory and varchar2 array
col value new_value user_dump_directory;
select value from v$parameter where name = 'user_dump_dest';
create or replace directory user_dump_dir as '&user_dump_directory';
create or replace type varchar2_array as table of varchar2(4000);
/ -- create get_trace_file1 function
create or replace function get_trace_file1(s_id number default userenv('sid'))
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_filename varchar2(2000);
v_line varchar2(4000);
begin
-- get exact file_name
-- below code can be repaced by a query against v$diag_info if you are on Oracle 11G.
select i.value||'_ora_'||p.spid||decode(t.value,null,'','_'||t.value)||'.trc' into v_filename
from v$process p, v$session s,
(select value from v$parameter where name = 'instance_name') i,
(select value from v$parameter where name = 'tracefile_identifier') t
where p.addr = s.paddr and s.sid = s_id;
v_handle := utl_file.fopen('USER_DUMP_DIR', v_filename, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/ -- create get_trace_file2 function
create or replace function get_trace_file2(file_name in varchar2)
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_line varchar2(20000);
begin
v_handle := utl_file.fopen('USER_DUMP_DIR', file_name, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception
when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/ -- create get_trace_file3 function
create or replace function get_trace_file3(dir_name in varchar2, file_name in varchar2)
return varchar2_array
pipelined
as
v_handle utl_file.file_type;
v_line varchar2(20000);
begin
v_handle := utl_file.fopen(dir_name, file_name, 'R', 32767);
loop
begin
utl_file.get_line(v_handle, v_line);
exception
when no_data_found then
exit;
end;
pipe row(v_line);
end loop;
utl_file.fclose(v_handle);
return;
end;
/
然后开启10046,并执行一个查询.

alter session set events '10046 trace name context forever, level 8';
select count(*) from t1;
alter session set events '10046 trace name context off';

用函数get_trace_file1去查看内容.
select * from table(get_trace_file1); Dump file c:\oracle\admin\ukja10\udump\ukja10_ora_2820.trc
Thu Mar 19 15:10:10 2009
ORACLE V10.2.0.1.0 - Production vsnsta=0
vsnsql=14 vsnxtr=3
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Windows XP Version V5.1 Service Pack 2
CPU : 2 - type 586
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:1481M/3070M, Ph+PgF:3140M/4960M, VA:1359M/2047M
Instance name: ukja10 Redo thread mounted by this instance: 1 Oracle process number: 16 Windows thread id: 2820, image: ORACLE.EXE (SHAD) *** ACTION NAME:() 2009-03-19 15:10:10.109
*** MODULE NAME:(SQL*Plus) 2009-03-19 15:10:10.109
*** SERVICE NAME:(UKJA10) 2009-03-19 15:10:10.109
*** SESSION ID:(157.1205) 2009-03-19 15:10:10.109
=====================
PARSING IN CURSOR #1 len=68 dep=0 uid=61 oct=42 lid=61 tim=172367882897 hv=740818757 ad='27e12b14'
alter session set events '10046 trace name context forever, level 8'
END OF STMT
...

Now I sort the buffer busy waits event by class# like this.

col class# format a10
col elapsed format 99.99 with t as (
select /*+ materialize */
column_value as line,
instr(column_value, 'ela=') ei,
instr(column_value, 'file#=') fi,
instr(column_value, 'block#=') bi,
instr(column_value, 'class#=') ci,
instr(column_value, 'obj#=') oi,
instr(column_value, 'tim=') ti
from table(get_trace_file2('trc_1.trc'))
--from table(get_trace_file2('trc_2.trc'))
where
instr(column_value, 'WAIT #2: nam=''buffer busy waits''') > 0
--instr(column_value, 'WAIT #11: nam=''buffer busy waits''') > 0
)
select
class#
, count(1) as cnt
, sum(elapsed)/1000000 as elapsed
from
(
select
substr(line, ei+4, fi-ei-4) as elapsed,
substr(line, fi+6, bi-fi-6) as file#,
substr(line, bi+7, ci-bi-7) as block#,
substr(line, ci+7, oi-ci-7) as class#,
substr(line, oi+5, ti-oi-5) as obj#,
substr(line, ti+4) as tim
from
t
) x
group by
class#
order by
2 desc, 3 desc;

What I’m actually doing is:

  1. trc_1.trc file contains the 10046 trace result with 40K extent size in ASSM.
  2. trc_2.trc file contains the 10046 trace result with 10M extent size in ASSM.
  3. 10 concurrent sessions insert into the table with 10046 trace enabled.
  4. I’d like to analyze how extent size affects the pattern of buffer contention.

Here is the result.

--when extent size is 40K
CLASS# CNT ELAPSED
---------- ---------- -------
8 285 1.40
1 215 4.64
4 42 .01
9 2 .00
19 1 .00
33 1 .00 -- when extent size is 10M
CLASS# CNT ELAPSED
---------- ---------- -------
8 1456 3.01
1 420 1.54
4 5 .00
35 2 .00
77 1 .00

See the diffference. With big extent size, we have major buffer contention on 1st level bitmap block(8). With (too) smaller extent size, the major contention is on data block(1).

 

利用utl_file来读取文件.的更多相关文章

  1. html5中利用FileReader来读取文件。

    利用FileReader来读取文件的能够来实现即时预览的效果,这个也是在html5中才有的功能. <!DOCTYPE html> <html lang="en"& ...

  2. Mysql 漏洞利用(越权读取文件,实战怎么从低权限拿到root密码)[转]

    cnrstar (Be My Personal Best!) | 2014-05-20 21:58 众所周知,Mysql的用户在没有File权限情况下是无法通过Load_file读文件或者通过into ...

  3. oracle读写文件--利用utl_file包对磁盘文件的读写操作

    oracle读写文件--利用utl_file包对磁盘文件的读写操作 摘要: 用户提出一个需求,即ORACLE中的一个表存储了照片信息,字段类型为BLOB,要求能导出成文件形式. 本想写个C#程序来做, ...

  4. Java利用内存映射文件实现按行读取文件

    我们知道内存映射文件读取是各种读取方式中速度最快的,但是内存映射文件读取的API里没有提供按行读取的方法,需要自己实现.下面就是我利用内存映射文件实现按行读取文件的方法,如有错误之处请指出,或者有更好 ...

  5. .net上传文件,利用npoi读取文件信息到datatable里

    整理代码,.net上传文件,利用npoi读取文件到datatable里,使用了FileUpload控件,代码如下: protected void Button1_Click(object sender ...

  6. Java读取文件加锁代码Demo(利用Java的NIO)

    本博文部分转载于:http://blog.csdn.net/wangbaochu/article/details/48546717 Java 提供了文件锁FileLock类,利用这个类可以控制不同程序 ...

  7. 利用PushbackReader读取文件中某个字符串之前的内容

    package File; import java.io.FileReader; import java.io.IOException; import java.io.PushbackReader; ...

  8. C++ 利用 libxl 将 Excel 文件转化为 Xml 文件

    在游戏开发工作中,策划和运营一般会用Excel来编写配置文件,但是程序读取配置,最方便的还是xml文件.所以最好约定一个格式,然后在二者之间做一个转化. 本文利用libxl来读取Excel文件,利用 ...

  9. Android从assets目录下读取文件相关

    有一个需求是app的帮助文档是word格式,ios可以直接用webview加载word显示,Android不行.而美工不配合转换成图片,前端没时间把word写成html 没办法,自己搞. 步骤: 1. ...

随机推荐

  1. JS来操作hover

    hover我们可以用css的方式写,当然,也可以用js的方式写 <html> <head> <title>js的下拉菜单效果</title> <s ...

  2. SpringMVC+Spring+MyBatis整合完整版Web实例(附数据)

    最近段时间正在学习Spring MVC和MyBatis的一些知识.自己也在网络上面找了一些例子来练习.但是都不是很完整.所以,今天,自己也抽空写了个完成的关于Spring MVC + Spring + ...

  3. 【C语言】05-printf和scanf函数

    一.printf函数 这是在stdio.h中声明的一个函数,因此使用前必须加入#include <stdio.h>,使用它可以向标准输出设备(比如屏幕)输出数据 1.用法 1> pr ...

  4. easyui datagrid 增删改查示例

    查询JSP页面 <!doctype html> <%@include file="/internet/common.jsp"%> <!-- 新样式右侧 ...

  5. 《GK101任意波发生器》升级固件发布(版本:1.0.2build198)

    一.固件说明: 硬件版本:0,logic.3 固件版本:1.0.2.build198 编译日期:2014-09-17 ====================================== 二. ...

  6. MySql之触发器【过度变量 new old】

    trigger是由事件触发某个操作.这些事件包括insert语句.update语句和delete语句.当数据库执行这些事件时,就会激活触发器执行相应的操作. [1]只有一个执行语句 create tr ...

  7. 【转】区别和认识.Net四个判等函数

    原文地址:不详 .Net有四个判等函数?不少人看到这个标题,会对此感到怀疑.事实上确是如此,.Net提供了ReferenceEquals.静态Equals,具体类型的Equals以及==操作符这四个判 ...

  8. A trip through the Graphics Pipeline 2011_04

    Welcome back. Last part was about vertex shaders, with some coverage of GPU shader units in general. ...

  9. 获取checkbox复选框的值

    <title>CheckBox</title> <script type = "text/javascript"> doGetVal: func ...

  10. TeamViewer“试用期已到期”解决方法

    今天打开TeamViewer,显示试用期已到期,不能远程至其它电脑上.软件重装也没用,因为它与你的机器及网卡做了绑定. 查看网上资料,发现需要删除注册信息等操作才能继续使用,步骤如下: 说明:操作前, ...