13

Does anyone have tools or experience with code coverage for PL/SQL. I believe this is possible using DBMS_PROFILER?

6 Answers 6

5

http://www.toadworld.com/BLOGS/tabid/67/EntryID/267/Default.aspx has info about checking code coverage using the PL/SQL profiler.

Some helpful info about profiling on 9i or 10g is included in Metalink Article 243755.1 "Implementing and Using the PL/SQL Profiler" for information on profiling code. Grab the prof.zip from the bottom of the article, it has a profiler.sql which will nicely format your results after a profiling run.

More 10g documentation is available here without a MetaLinka account: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_profil.htm

If you are running 11g there is a new Hierarchical Profiler documented here: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28424/adfns_profiler.htm

1
  • 1
    Update: After using the Hierarchical Profiler a bit this week it is not so useful for code covereage - it mainly collect data on the entry points of each function call and not on all lines of code like the original profiler.
    – David Mann
    Commented Apr 12, 2010 at 15:59
3

See SD Test Coverage Tools. We're about to release a PLSQL test coverage tool with the same capabilities as our other tools, including a GUI to display the results on top of your source code, and a generated coverage report that collects details on individual functions as well as rollups for packages.

EDIT 2/15/2011: PLSQL test coverage production tool is available.

1

There is a package you can install called DBMS_profiler. With this, you can start a profile and Oracle will store data in special tables. Then stop the profile and report from those tables.

1

With Oracle 12.2c now you can use DBMS_PLSQL_CODE_COVERAGE package. In fact, this provides basic-block level coverage.

Basic-block is the smallest executable code.

These are few references to find more information.

Oracle documentation

Tutorial

Youtube Video

0

Not sure if this is quite what you're after, but in 10g onwards there's a tool to do static PL/SQL code analysis.

Info here... http://www.psoug.org/reference/plsql_warnings.html

Note that it can be enabled at either session or database level.

In my experience it's thrown up quite a few false negatives so far.

0

I found something useful on http://www.databasejournal.com/features/oracle/article.php/10893_2197231_3 page.

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.