Skip to content

Instantly share code, notes, and snippets.

@hhudson
Created June 17, 2022 15:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhudson/8755719ce7a6cc71519b861346b5819d to your computer and use it in GitHub Desktop.
Save hhudson/8755719ce7a6cc71519b861346b5819d to your computer and use it in GitHub Desktop.
query used in AIT episode 78 to retrieve the dbms_hprof results
create or replace force view v_execution_stats as
with execution_stats as (
select fi.runid,
fi.symbolid,
pci.parentsymid,
rtrim(fi.module || '.' || nullif(fi.function,fi.module), '.') as unit,
nvl(pci.subtree_elapsed_time, fi.subtree_elapsed_time)/1000000 as subtree_elapsed_time_seconds,
nvl(pci.function_elapsed_time, fi.function_elapsed_time)/1000000 as function_elapsed_time_seconds,
fi.line#,
nvl(pci.calls, fi.calls) as calls,
namespace,
sql_id,
sql_text
from dbmshp_function_info fi
left join dbmshp_parent_child_info pci
on fi.runid = pci.runid
and fi.symbolid = pci.childsymid
where fi.module != 'DBMS_HPROF'
), execution_tree as (
select rownum execution_order,
runid,
rpad('.', (level-1)*2, '.') || unit as unit,
line#,
subtree_elapsed_time_seconds,
function_elapsed_time_seconds,
calls,
namespace,
sql_id,
sql_text,
level cb_level
from execution_stats
start with parentsymid is null
connect by parentsymid = prior symbolid
and runid = prior runid
)
select runid,
execution_order,
unit,
line#,
subtree_elapsed_time_seconds,
function_elapsed_time_seconds,
calls,
namespace,
sql_id,
sql_text,
cb_level,
rank() over (partition by runid order by subtree_elapsed_time_seconds desc) as time_rank
from execution_tree
order by execution_order
@hhudson
Copy link
Author

hhudson commented Jun 17, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment