Run Profiler, Execution Plan.....on Package

jknj72
jknj72 used Ask the Experts™
on
I want to run a Profile and/or Execution PLan on my Package to see where the most resources are being used when I run my process. I am using SQL Developer and have been reading about different ways to do this but would like to know an easy way to just see what my procedure(in my package) is looking like as far as Table Scans, Reads, etc.. and maybe what I can do to help optimize what I have now before I go and redo this a more efficient way. We will be using this for now and when I have some down time I will come back and rewrite it, using some experts advice, and get it to run more efficiently.
I just need to be able to see how its doing via a Profile and/or an Execution plan now to see what I can do ? Also, if your real good at these types of thing you can tell me what to look for when I actually get the Plan back? Or I can look that part up ;)

Thanks
JK
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I have set up the Preferences already but if I need to have something explicitly checked please let me know
Preferences.jpg
Most Valuable Expert 2011
Top Expert 2012

Commented:
Plans are for sql statements - not pl/sql objects
Profiles are for pl/sql objects  - not for sql statements

A plan will show you table and index usage.

A profile will show you which lines of code are executed, how long they took and how often they were run


Using auto trace you can get a summary of ALL session statistics during the run of a procedure but not anything at the individual sub-routines or lines.
Most Valuable Expert 2011
Top Expert 2012

Commented:
So,  if you want to do a performance analysis on your pl/sql then I suggest you use the profiler.

When it's done, run a report to see which lines are the most expensive in terms of total time and then, if those lines are sql,  then generate a plan for those lines and see what can be done about them.

There is no direct path from pl/sql to table/index usage that you are looking for.  You'll have to do it in steps.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
ok thanks for the lesson. How can I run the profiler? I see the profiler icon on the package level but not on the Body where the procedures are. DO I turn it on in the package level and run it from there? Also, where would I find the profile info when Im done.
Most Valuable Expert 2011
Top Expert 2012
Commented:
if you're using the standard profiler then something like this...

BEGIN
    Dbms_Profiler.start_profiler('jknj72');  -- it's not required, but helpful to give your profile runs distinct names
    Your_package.Your_Procedure;
    dbms_profiler.stop_profiler;
END;

Then you can query the results with something like this...
SELECT   u.unit_type, u.unit_owner, u.unit_name, d.line#, d.total_occur,
         TO_CHAR(d.total_time / 1000000000, '990.999999') total_seconds,
         TO_CHAR(d.min_time / 1000000000, '990.999999') min_seconds,
         TO_CHAR(d.max_time / 1000000000, '990.999999') max_seconds,
         TO_CHAR(d.total_time / 1000000000 / d.total_occur,
                 '990.999999'
                ) avg_seconds,
         (SELECT TRIM(s.text)
            FROM dba_source s
           WHERE u.unit_owner = s.owner
             AND u.unit_type = s.TYPE
             AND u.unit_name = s.NAME
             AND d.line# = s.line) "text (as of now)",
         TO_CHAR(r.run_total_time / 1000000000,
                 '9990.999'
                ) total_profiled_time
    FROM plsql_profiler_runs r, plsql_profiler_data d, plsql_profiler_units u
   WHERE r.run_comment = 'jknj72'
     AND d.runid = r.runid
     AND u.runid = d.runid
     AND d.unit_number = u.unit_number
     AND d.total_occur != 0
ORDER BY d.total_time DESC

Open in new window


if you're using the hierarchical profiler then you'll need access to the db server


BEGIN
    DBMS_HPROF.start_profiling (location => 'YOUR_PROFILING_DIRECTORY',  filename => 'jknj72.txt');
    Your_package.Your_Procedure;
    DBMS_HPROF.stop_profiling;
END;

Then you can use   plshprof   to generate a report on your output file.

plshprof -output  jknj72.report.txt  jknj72.txt
Most Valuable Expert 2011
Top Expert 2012

Commented:
alternately,  you can use dbms_hprof to extract the contents of the file into tables similar to the standard profiler.

You can read more about that here

http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_profiler.htm#g3350546

Author

Commented:
Thanks stuber!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial