国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > Oracle > 正文

Oracle’s DBMS_Profiler:PL/SQL 性能調(diào)整

2024-08-29 13:49:21
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  
                  Oracle’s DBMS_PRofiler:PL/SQL 性能調(diào)整

 

DBMS_PROFILER 包舉例

 

       下面是我提供的怎樣使用配置的簡(jiǎn)單例子,運(yùn)行配置文件來(lái)測(cè)試下面例程的性能. 例程用到的自定義腳本緊隨其后.

1.         創(chuàng)建過(guò)程.

            create or replace procedure am_perf_chk (pi_seq     in            number,

                                                     pio_status in out nocopy varchar2) is

              l_dat date := sysdate;

            begin

              if trunc(l_dat) = '21-sep-02' and pi_seq = 1 then

                pio_status := 'OK';

              else

                pio_status := 'Invalid tape loaded';

              end if;

            exception

              when others then

                pio_status := 'Error in am_perf_chek';

            end;

 

2.         用配置文件調(diào)用例程

       替換上面的例程, 執(zhí)行call_profiler.sql腳本(腳本代碼參見(jiàn)下面),傳入pi_seq=2

SQL> @d:/am/call_profiler.sql

            Profiler started

            Invalid tape loaded

            PL/SQL procedure sUCcessfully completed.

            Profiler stopped

            Profiler flushed

            runid:8

 

3.         評(píng)估執(zhí)行時(shí)間:
執(zhí)行eavluate_profiler_results.sql腳本,得到時(shí)間統(tǒng)計(jì)

SQL> @d:/am/evaluate_profiler_results.sql

Enter value for runid: 8

Enter value for name: am_perf_chk

Enter value for owner: scott

      Line      Occur       Msec Text

---------- ---------- ---------- -------------------------------------------------------------------

         1                       procedure am_perf_chk (pi_seq     in            number,

         2                                              pio_status in out nocopy varchar2) is

         3          2   43.05965   l_dat date := sysdate;

         4                       begin

         5          1   86.35732   if trunc(l_dat) = '21-sep-02' and pi_seq = 1 then

         6          0          0     pio_status := 'OK';

         7                         else

         8          1   8.416151     pio_status := 'Invalid tape loaded';

         9                         end if;

        10                       exception

        11                         when others then

        12          0          0     pio_status := 'Error in am_perf_chek';!

        13          1   2.410361 end;

13 rows selected.

 

Code% coverage

--------------

    66.6666667

 

4.         正如你看到的,第三行執(zhí)行時(shí)間提高到86毫秒.但是改變if語(yǔ)句,重新執(zhí)行上面的過(guò)程,將會(huì)得到新的結(jié)果:

                          Line      Occur       Msec Text

---------- ---------- ---------- -------------------------------------------------------------------

         1                       procedure am_perf_chk (pi_seq     in            number,

         2                                              pio_status in out nocopy varchar2) is

         3          2  17.978816   l_dat date := sysdate;

         4                       begin

         5          1   8.419503   if pi_seq = 1 and trunc(l_dat) = '21-sep-02' then

         6          0          0     pio_status := 'OK';

         7                         else

         8          1   7.512684     pio_status := 'Invalid tape loaded';

         9                         end if;

        10                       exception

        11                         when others then

        12          0          0     pio_status := 'Error in !am_perf_chek';

        13          1    .731657 end;

13 rows selected.

 

Code% coverage

--------------

    66.6666667

 

5.         正如你看到的, 這種情境下第三行執(zhí)行時(shí)間從86毫秒減少到8毫秒,多余的時(shí)間是由于內(nèi)置trunc()函數(shù)引起., 這種情境下假如第一個(gè)條件為false,則不會(huì)執(zhí)行trunc()函數(shù).這僅僅是個(gè)簡(jiǎn)單的例子,當(dāng)你測(cè)試的例程越大,你面臨的挑戰(zhàn)更大.

這個(gè)配置結(jié)果也證實(shí)了執(zhí)行期間代碼被覆蓋多少行,從而讓我們知道處于性能監(jiān)視中的代碼范圍。
假如任何PL/SQL塊性能出現(xiàn)問(wèn)題,它也能提煉出各種不同情景的正在在執(zhí)行的代碼并檢查配置結(jié)果,從而查明問(wèn)題所在。

6.         對(duì)于一個(gè)特定的情景,假如執(zhí)行一段非凡的代碼段,可以得到合理的分析,即使代碼根本一點(diǎn)都不能運(yùn)行。

 

環(huán)境的創(chuàng)建

       默認(rèn)安裝或數(shù)據(jù)庫(kù)的創(chuàng)建狀態(tài)下,DBMS_PROFILER包不會(huì)自動(dòng)安裝,請(qǐng)DBA用profload.sql腳本創(chuàng)建它.用一個(gè)權(quán)限較大的或一個(gè)單獨(dú)的用戶,創(chuàng)建存儲(chǔ)統(tǒng)計(jì)信息的表。假如

用如SYS用戶創(chuàng)建,則給其它用戶授予DML權(quán)限,并且對(duì)這些表創(chuàng)建一個(gè)共同的簡(jiǎn)寫(xiě)名.

 

       創(chuàng)建表的如下:

       PLSQL_PROFILER_RUNS表:PL/SQL配置的運(yùn)行細(xì)節(jié).

       PLSQL_PROFILER_UNITS表:運(yùn)行中每一個(gè)庫(kù)單元的信息.

       PLSQL_PROFILER_DATA表:所有配置文件運(yùn)行時(shí)的數(shù)據(jù)累積.

       PLSQL_PROFILER_RUNNUMBER序列提供了RUNID

 

運(yùn)行和解釋配置數(shù)據(jù)

       ORACLE提供了三個(gè)表來(lái)統(tǒng)計(jì),填充RUNID。有許多第三方的工具可以提供自定義的基于這些數(shù)據(jù)的報(bào)告,ORACLE提供profrep.sql腳本評(píng)估數(shù)據(jù)(在<oracle_home>/plsql/demo/目錄下),下面的兩個(gè)簡(jiǎn)單腳本就是上面用到的,用來(lái)檢查程序單元的執(zhí)行時(shí)間.執(zhí)行時(shí)間以毫秒存儲(chǔ)

            -----------------------------------------------------------

Script: call_profiler.sql

-----------------------------------------------------------

set head off

set pages 0

select decode(dbms_profiler.start_profiler, '0', 'Profiler started', 'Profiler error')

from   dual;

 

--< place your routine in the below block >--

declare

  l_status varchar2(200);

begin

  am_perf_chk(2, l_status);

  dbms_output.put_line(l_status);

end;

/

 

select decode(dbms_profiler.stop_profiler, '0', 'Profiler stopped', 'Profiler error')

from   dual;

select decode(dbms_profiler.flush_data, '0', 'Profiler flushed', 'Profiler error')

from   dual;

select 'runid:' plsql_profiler_runnumber.currval

from   dual;

set head on

set pages 200

 

-----------------------------------------------------------

Script: evaluate_profiler_results.sql

-----------------------------------------------------------

undef runid

undef owner

undef name

set verify off

select s.line "Line", p.total_occur "Occur", p.total_time "Msec", s.text "Text"

from   all_source s, (select u.unit_owner, u.unit_name, u.unit_type, d.line#,

                             d.total_occur, d.total_time/1000000 total_time

                      from   plsql_profiler_data d, plsql_profiler_units u

                      where  u.runid = &&runid

                      and    u.runid = d.runid

                      and    u.unit_number = d.unit_number) p

where  s.owner = p.unit_owner (+)

and    s.name = p.unit_name (+)

and    s.type = p.unit_type (+)

and    s.line = p.line# (+)

and    s.name = upper('&&name')

and    s.owner = upper('&&owner')

order by s.line;

select exec.cnt/total.cnt * 100 "Code% coverage"

from  (select count(1) cnt

      from plsql_profiler_data d, plsql_profiler_units u

      where d.runid = &&runid

      and u.runid = d.runid

      and u.unit_number = d.unit_number

     and u.unit_name = upper('&&name')

      and u.unit_owner = upper('&&owner')) total,

     (select count(1) cnt

      from plsql_profiler_data d, plsql_profiler_units u

      where d.runid = &&runid

      and u.runid = d.runid

      and u.unit_number = d.unit_number

      and u.unit_name = upper('&&name')

      and u.unit_owner = upper('&&owner')

      and d.total_occur > 0) exec;

undef runid

undef owner

undef name

 

結(jié)論

       DBMS_PROFILER是非常強(qiáng)大的工具,其一就是可以識(shí)別PL/SQL的性能問(wèn)題.這個(gè)工具最好用在開(kāi)發(fā)時(shí)期,用來(lái)調(diào)整基于各種應(yīng)用的情景的代碼,它也能用很好的調(diào)整已在使用中的例程并且采取顯而易見(jiàn)的時(shí)間去執(zhí)行。
總之,這個(gè)工具可以給每一行代碼給予性能統(tǒng)計(jì),它可以幫助我們?cè)u(píng)估和調(diào)整到一個(gè)出色的水平,當(dāng)檢查SQL語(yǔ)句的性能問(wèn)題時(shí),PL/SQL代碼不應(yīng)該忽略,相反應(yīng)該調(diào)整到最佳的結(jié)果.

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 射洪县| 乌兰察布市| 大洼县| 石河子市| 海城市| 台江县| 民乐县| 赤峰市| 天峻县| 东乌珠穆沁旗| 鹰潭市| 大丰市| 富平县| 阿合奇县| 昌宁县| 松潘县| 蒙城县| 葫芦岛市| 台南市| 武义县| 会东县| 五莲县| 大新县| 康乐县| 苏尼特右旗| 弥勒县| 凉山| 涟水县| 苍南县| 潼南县| 九寨沟县| 普宁市| 利辛县| 贵定县| 漯河市| 清徐县| 庆元县| 罗源县| 青铜峡市| 绥棱县| 高淳县|