请教dbms_utility.get_cpu_time 和 get_time有什么区别?

[复制链接]
查看11 | 回复8 | 2008-6-29 16:06:00 | 显示全部楼层 |阅读模式
SQL> select dbms_utility.get_time,dbms_utility.get_cpu_time from dual;

GET_TIME GET_CPU_TIME
---------- ------------
539529245
4

SQL> select dbms_utility.get_time,dbms_utility.get_cpu_time from dual;

GET_TIME GET_CPU_TIME
---------- ------------
539529950
4

SQL> select dbms_utility.get_time,dbms_utility.get_cpu_time from dual;

GET_TIME GET_CPU_TIME
---------- ------------
539530148
4

SQL> select dbms_utility.get_time,dbms_utility.get_cpu_time from dual;

GET_TIME GET_CPU_TIME
---------- ------------
539530236
5

差很多啊,但是在过程里看倒是一样的
SQL> declare
2n number := dbms_utility.get_time ;
3m number := dbms_utility.get_cpu_time ;
4begin
5dbms_output.put_line('n:'||n);
6dbms_output.put_line('m:'||m);
7
8for i in 0 .. 10000 loop
9insert into test values(i);
10end loop;
11
12n := n - dbms_utility.get_time;
13m := m - dbms_utility.get_cpu_time;
14
15dbms_output.put_line('n:'||n);
16dbms_output.put_line('m:'||m);
17
18end;
19/

n:539582338
m:72
n:-28
m:-28

PL/SQL procedure successfully completed

请问这个cpu_time是什么意思?
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
自己顶一记
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
get_cpu_time返回的是cpu的时间,单位是百分之一秒,而get_time返回的是系统时间,单位也是百分之一秒,我的理解是cpu时间是每个进程开始从1开始计数的,而系统的时间则是全局的,所有进程共享,不知道这样理解对不对
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
那怎么解释不同的select里,get_cpu_time和get_time的差距越来越大呢?
这应该都是在同一个进程里的。
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
一个是cpu时间,一个是总时间(cpu time+wait time),是不一样的。
你的例子里面get cpu time=get time试因为你的测试里面绝大多数时间都耗在CPU上了,换个IO比较大的操作就不一样了。
SQL> declare
2n number := dbms_utility.get_time ;
3m number := dbms_utility.get_cpu_time ;
4begin
5dbms_output.put_line('n:'||n);
6dbms_output.put_line('m:'||m);
7
8insert /*+ append */ into test select rownum from dba_extents;
9
10 n := n - dbms_utility.get_time;
11 m := m - dbms_utility.get_cpu_time;
12
13 dbms_output.put_line('n:'||n);
14 dbms_output.put_line('m:'||m);
15
16 end;
17 /
n:5044212
m:90
n:-1453
m:-88
PL/SQL 过程已成功完成。
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
原帖由 decode360 于 2009-5-12 21:03 发表
那怎么解释不同的select里,get_cpu_time和get_time的差距越来越大呢?
这应该都是在同一个进程里的。

如果你间隔1个小时查get time和cpu time,get time间隔应该是1小时,cpu time间隔应该很小,只包括你的两个sql执行耗费的cpu time.
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
就是说,get time 是总的时间,而cpu time 只是你执行sql中使用掉的有效的cpu时间,是吗
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
了解了,感谢
回复

使用道具 举报

千问 | 2008-6-29 16:06:00 | 显示全部楼层
http://www.oracle-developer.net/display.php?id=307
measuring cpu time in 10g
Developers have long been familiar with the DBMS_UTILITY.GET_TIME function. It is commonly used in test harnesses for measuring the elapsed time between two points in a process. In 10g, Oracle has added to this with the DBMS_UTILITY.GET_CPU_TIME function. This new function enables us to measure the amount of CPU time used between two points. This short article demonstrates the difference between the new GET_CPU_TIME function and the existing GET_TIME function.
a cpu-bound example
The first example below is CPU-intensive; there is no I/O. This highlights the fact that for CPU-bound operations, the GET_TIME and GET_CPU_TIME return roughly the same timing (allowing for +/- measurement error). Note that like GET_TIME, GET_CPU_TIME measures in hundredths of a second.
SQL> DECLARE
2
3 b1 PLS_INTEGER;
4 b2 PLS_INTEGER;
5 e1 PLS_INTEGER;
6 e2 PLS_INTEGER;
7
8BEGIN
9
10 b1 := DBMS_UTILITY.GET_TIME();
11 b2 := DBMS_UTILITY.GET_CPU_TIME();
12
13 FOR i IN 1 .. 100000000 LOOP
14NULL;
15 END LOOP;
16
17 e1 := DBMS_UTILITY.GET_TIME() - b1;
18 e2 := DBMS_UTILITY.GET_CPU_TIME() - b2;
19
20 DBMS_OUTPUT.PUT_LINE( 'GET_TIME elapsed = ' || e1 || ' hsecs.' );
21 DBMS_OUTPUT.PUT_LINE( 'GET_CPU_TIME elapsed = ' || e2 || ' hsecs.' );
22
23END;
24/
GET_TIME elapsed = 157 hsecs.
GET_CPU_TIME elapsed = 158 hsecs.
PL/SQL procedure successfully completed.
an i/o bound example
This time we'll take a look at an example that includes some I/O. This is possibly more representative of a typical PL/SQL workload that mixes data access with procedural logic. We can now see a difference in the reported timings.
SQL> DECLARE
2
3 b1 PLS_INTEGER;
4 b2 PLS_INTEGER;
5 e1 PLS_INTEGER;
6 e2 PLS_INTEGER;
7
8BEGIN
9
10 b1 := DBMS_UTILITY.GET_TIME();
11 b2 := DBMS_UTILITY.GET_CPU_TIME();
12
13 FOR r IN ( SELECT * FROM all_source ) LOOP
14NULL;
15 END LOOP;
16
17 e1 := DBMS_UTILITY.GET_TIME() - b1;
18 e2 := DBMS_UTILITY.GET_CPU_TIME() - b2;
19
20 DBMS_OUTPUT.PUT_LINE( 'GET_TIME elapsed = ' || e1 || ' hsecs.' );
21 DBMS_OUTPUT.PUT_LINE( 'GET_CPU_TIME elapsed = ' || e2 || ' hsecs.' );
22
23END;
24/
GET_TIME elapsed = 278 hsecs.
GET_CPU_TIME elapsed = 175 hsecs.
PL/SQL procedure successfully completed.
source code
The source code for the examples in this article can be downloaded from here.
Adrian Billington, June 2004
Back to Top
[ 本帖最后由 〇〇 于 2010-7-14 16:31 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行