oracle function dtrace
https://andreynikolaev.wordpress.com/2010/10/28/appetizer-for-dtrace/
Appetizer for DTrace
To discover how the Oracle latch works, we need the tool. Oracle Wait Interface allows us to explore the waits only. Oracle X$/V$ tables instrument the latch acquisition and give us performance counters. To see how latch works through time and to observe short duration events, we need something like stroboscope in physics. Likely such tool exists in Oracle Solaris. The DTrace, Solaris 10 Dynamic Tracing framework!
Here I would like to give brief, Oracle DBA inclined into to some of DTrace topics. Tanel Poder, James Morle, Dough Burnswere used the DTrace for performance diagnostics for years. But it is still not popular as should be in our DBA community. One of the problems is another “language”. The best DTrace presentations talk about “probes”, “actions”, unfamiliar Solaris kernel structures, etc… Begging pardon to the DTrace inventors, I will use more database-like terminology here.
I will not even try to touch the most popular DTrace usage. Anyone who’s interested in this revolutionary technology, should read DTrace introduction, DTrace user guide,the upcoming DTrace book and DTrace communitymaterials.
DTrace is event-driven instrumentation of Solaris kernel and user applications. This is the key point. No application change is needed to use DTrace. This is very similar to triggers in Oracle database. You define the probe (trigger ) to fire on event, and write the action (body) to execute. I will use this analogy in this post.
A probe is a point of instrumentation made available by a provider. A provider has analogy in Oracle trigger type (system/user triggers, DML, DDL, etc…). Officially, the provider represents a methodology for instrumenting the system.
Popular Solaris providers are pid,syscall, sysinfo, … As of now (11.2.0.2), we are still waiting for Oracle specific providers to integrate Oracle Server and Oracle DTrace. But we can do a lot with a generic pid provider, which allows to set triggers on any function call in user application. My goal is to see the latch operations on-the-fly.
The DTrace describes the triggering probe in a four field format: provider:module:function:name. If one need to set trigger inside the oracle process with Solaris spid 16444, to fire on entry to function kslgetl (get exclusive latch), the probe description will be pid16444:oracle:kslgetl:entry
Surprisingly this is enough to start use the DTrace with Oracle. Suppose, I would like to see latch acquisitions by MMON process . In my database the MMON process currently has spid 16444. Ask your Solaris SysAdmin for dtrace_userprivilege and type:
$/usr/sbin/dtrace -n 'pid16444:oracle:kslgetl:entry'
dtrace: description 'pid16444:oracle:kslgetl:entry' matched 1 probe
CPU ID FUNCTION:NAME
1 67480 kslgetl:entry
1 67480 kslgetl:entry
0 67480 kslgetl:entry
…
<ctrl-C>
This simple DTrace one-liner traces calls of kslgetl() function and shows how the process migrates between CPUs.
How it works? Unlike standard tracing tools, DTrace works in Solaris kernel. When I activated this probe, dtrace set trigger at the entry to kslgetl function. When oracle process entered this function, the execution went to Solaris kernel and the DTrace filled buffers with the data. The dtrace program printed out these buffers.
Let us compare the DTrace and obsoleted Oracle Trace. Both were event driven. Otrace tried to catch all the evens in instance, the DTrace catch only what you asked for. Otrace allowed to set filters, in the DTrace you write the program. Otrace was fully userland, DTrace works in the OS kernel.
Kernel based tracing is much more stable and have less overhead then userland. DTrace sees all the system activity and can take into account the ‘unaccounted for’ time associated with kernel calls, scheduling, etc.
Actions (trigger bodies!) are what happen when a probe is hit. Actions are fully programmable using D language, which will be familiar to anybody who ever used C and awk. Action code enclosed in curly brackets {} and could use arguments of function call as arg0, arg1, etc….
Naturally, the next step in our DTrace latch tracing is to see the latch function arguments. It is easy to write such a script (ksl_args.d). Remember that Oracle acquires exclusive latches using kslgetl(laddr, wait, why, where), and shared latches using kslgetsl(laddr, wait, why, where, rs) (ksl_get_shared_latch() in 11g):
#!/usr/sbin/dtrace -Zs #pragma D option quiet pid$target::kslgetl:entry { printf("%s(0x%X,wait=%d,why=0x%X,whr=%d)\n",probefunc,arg0,arg1,arg2,arg3); } pid$target::kslgetsl:entry, pid$target::ksl_get_shared_latch:entry { printf("%s(0x%X,wait=%d,why=0x%X,whr=%d,rs=%d)\n",probefunc,arg0, arg1,arg2,arg3,arg4); } pid$target::kslfre:entry { printf(" %s(0x%X)\n",probefunc,arg0); } |
The script probes (triggers) will fire on each entry to latch acquisition functions. Printf()’s inside the trigger bodies (actions) will print out arguments of these functions to the dtrace kernel buffers. $target macro will be replaced at runtime by spid number from -p script oprion. And this is the output:
$ ./ksl_args.d -p 16444
kslgetl(0x38000CC98,wait=1,why=0x0,whr=175)
kslfre(0x38000CC98)
ksl_get_shared_latch(0x38DE6DD00,wait=1,why=0x38DE6DCB8,whr=290,rs=16)
kslfre(0x38DE6DD00)
kslgetl(0x38BE4C328,wait=1,why=0x0,whr=3487)
kslfre(0x38BE4C328)
kslgetl(0x38BE4C328,wait=1,why=0x0,whr=3510)
...
One can focus on the particular latch using predicate (WHEN clause !). Predicate takes the form of / … / just before action code. The probe will fire only when the predicate evaluates to true.
Look at my test Oracle instance suffered from “transaction allocation” latch contention.
select addr,latch#,name,gets,misses,sleeps,spin_gets,wait_time from v$latch_parent
where name='transaction allocation'
ADDR | LATCH# | NAME | GETS | MISSES | SLEEPS | SPIN_GETS | WAIT_TIME |
---|---|---|---|---|---|---|---|
50010AEC | 180 | transaction allocation | 520710921 | 387182198 | 74543 | 387117330 | 380364770 |
To see what happens with this latch I used the script:
#!/usr/sbin/dtrace -Zs #pragma D option quiet pid$target::kslgetl:entry / arg0 == 0x50010AEC / { printf("%s(0x%X,wait=%d,why=0x%X,whr=%d)\n",probefunc,arg0,arg1,arg2,arg3); } pid$target::kslfre:entry / arg0 == 0x50010AEC / { printf(" %s(0x%X)\n",probefunc,arg0); } |
...
kslgetl(0x50010AEC,wait=1,why=0x0,whr=2098)
kslfre(0x50010AEC)
...
Latch “where“=2098 mean “ktcxbr: parent” in x$ksllw. Oracle acquire parent “transaction allocation” latch at this “where” during select from v$transaction. Concurrent select from this fixed view is indeed the root cause of latch contention.
And finally I would like to show the latch in memoryitself. No problem. On entry to kslgetl the arg0 is the latch address. I will check this location on entry and return from latch functions. The only thing is to remember that DTrace probe acts in kernel address space. You need to copy the latch value from user address space into kernel buffer using copyin(user_address,size) DTrace function:
#!/usr/sbin/dtrace -Zs #pragma D option quiet pid$target::kslgetl:entry, pid$target::kslfre:entry / arg0 == 0x50010AEC / { laddress = arg0; /* save laddress */ latch= *(uint32_t *)copyin(laddress, 4); /* copy latch value from user space*/ printf("%s(0x%X...) \tlatch=0x%X (entry),",probefunc,arg0,latch); } pid$target::kslgetl:return, pid$target::kslfre:return / laddress / { latch= *(uint32_t *)copyin(laddress, 4); /* copy latch value from user space*/ printf(" 0x%X (return)\n",latch); laddress =0; } |
...
kslgetl(0x50010AEC...) latch=0x00 (entry), 0xFF (return)
kslfre(0x50010AEC...) latch=0xFF (entry), 0x00 (return)
...
oracle function dtrace的更多相关文章
- oracle function学习1
oracle function学习基层: 函数就是一个有返回值的过程. 首先 知道oracle 使用限制: 函数调用限制: 1. SQL语句中只能调用存储函数(服务器端),而不能调用客户端 ...
- MySQL 5.6.20-4 and Oracle Linux DTrace
https://blogs.oracle.com/wim/entry/mysql_5_6_20_4?utm_source=tuicool&utm_medium=referral By WimC ...
- Oracle function real_st_astext,解决ArcSDE中st_astext函数返回字符串结构异常问题
项目过程中发现在Oracle中调用ArcSDE的st_astext函数返回ST_Geometry类型字段的WKT文本有时空间类型前缀没有返回,例如一个点的经度为113.4,纬度为30.6,调用st_a ...
- Oracle Function:TO_CHAR
Description The Oracle/PLSQL TO_CHAR function converts a number or date to a string.将数字转换为日期或字符串 Syn ...
- Oracle Function:COUNT
Description The Oracle/PLSQL COUNT function returns the count of an expression. The COUNT(*) functio ...
- Oracle Function: NVL
Description The Oracle/PLSQL NVL function lets you substitute a value when a null value is encounter ...
- Oracle Function
Oracle Sql 中常用函数 小写字母转大写字母:upper(); 大写字母转小写字母:lower(); 字符串截取函数:substr(str,a,b); a,b为整数,str为字符串, 截取字符 ...
- Oracle function注释
create or replace function fn_bookid_get_by_chapterid(inintChapterId in integer, outvarBookId out va ...
- Oracle function和procedure
1.返回值的区别 函数有1个返回值,而存储过程是通过参数返回的,可以有多个或者没有 2. 调用的区别,函数可以在查询语句中直接调用,而存储过程必须单独调用. 函数:一般情况下是用来计算并返回一个计算结 ...
随机推荐
- cmake命令 安装、用法简介
前言 cmake是kitware公司以及一些开源开发者在开发几个工具套件(VTK)的过程中所产生的衍生品.后来经过发展,最终形成体系,在2001年成为一个独立的开放源代码项目.其官方网站是www.cm ...
- 关于host,nslookup,dig 的安装
host,nslookup,dig依赖bind包,所以先看一下系统有没有bind包 命令如下:rpm -qa |grep bind 如果没有或者版本太低请升级安装 命令是:yum install bi ...
- Selenium2启动浏览器且加载插件
一.SELENIUM2启动浏览器 注意: SELENIUM2在启动浏览器时,都是启动一个干净的没有任务 插件及cookies信息的浏览器,即使是你之前的浏览器有设置过代理,到自动化启动时,也是没有代理 ...
- C++基础——1.变量和基本类型(基于c++11)
C++11类型 基本类型 字面值常量(literal) 比如:一个形如42的值,即为常量 变量 初始值 初始化不是赋值,初始化是创建变量的时候给一个初始值:而赋值是擦除当前值,用新值代替. 列表初始化 ...
- BZOJ 4355: Play with sequence
调了好久,还是黑盒测试有前途 我以前怕不是学了假的吉利线段树(我第一次知道还要记次小值去更新的........) #include<cstdio> #include<algorith ...
- UVa 1354 枚举子集 Mobile Computing
只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...
- Flask_Blueprint(蓝图)
在Flask中,我们需要一个可以模块化的方法. Flask自身给我们提供的就是Blueprint方法. 通过Blueprint,可以让我们实现模块化组织程序结构. 官方文档解释: 代码结构: 核心代码 ...
- PHP 教父鸟哥 Yar 的原理分析
模块越来越多,业务越来越复杂,RPC 就上场了,在 PHP 的世界里,鸟哥的作品一直备受广大网友的青睐.下面一起学习下鸟哥的 PRC 框架 Yar . 揭开 Yar 神秘面纱 RPC 采用客户端/服务 ...
- [git 学习篇]远程创库
实际情况往往是这样,找一台电脑充当服务器的角色,每天24小时开机,其他每个人都从这个“服务器”仓库克隆一份到自己的电脑上,并且各自把各自的提交推送到服务器仓库里,也从服务器仓库中拉取别人的提交. 完全 ...
- 九度oj 题目1085:求root(N, k) 清华2010年机试题目
题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k).N'为N的k进制表示的各位数字之和.输入x,y,k,输出root(x^y,k)的值 (这里^ ...