forked from xtender/xt_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocs_by_sid.sql
76 lines (74 loc) · 1.98 KB
/
procs_by_sid.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
prompt &_C_REVERSE *** Find procedures from ASH by sid &_C_RESET
prompt Usage: @ash/procs_by_sid sid serial# [minutes_ago]
@inc/input_vars_init;
col owner format a30;
col procedure_name format a30;
col top_level_sql_id format a13;
col object_name format a30;
col text format a120 word;
with
obj_list as
(
select
h.PLSQL_ENTRY_OBJECT_ID,h.PLSQL_ENTRY_SUBPROGRAM_ID
,h.PLSQL_OBJECT_ID ,h.PLSQL_SUBPROGRAM_ID
from v$active_session_history h
where
h.session_id = &1
and h.session_serial#='&2'
and ('&3' is null or h.sample_time>systimestamp-interval '0&3' minute)
)
,objects as
(
select *
from obj_list
unpivot(
(obj,subobj) for obj_code in ( (PLSQL_ENTRY_OBJECT_ID ,PLSQL_ENTRY_SUBPROGRAM_ID) as 'entry'
, (PLSQL_OBJECT_ID,PLSQL_SUBPROGRAM_ID ) as 'main'
)
)
)
,agg as (
select
obj_code,obj,subobj,count(*) cnt
from objects
group by obj_code,obj,subobj
order by cnt desc
)
select
agg.obj_code
,agg.obj
,agg.subobj
,p.OBJECT_TYPE
,p.owner,p.OBJECT_NAME,p.PROCEDURE_NAME
,agg.cnt
from agg
,dba_procedures p
where agg.obj = p.OBJECT_ID
and agg.subobj = p.SUBPROGRAM_ID
/
with top_level_calls as (
select h.TOP_LEVEL_SQL_ID,count(*) cnt
from v$active_session_history h
where
h.session_id = &1
and h.session_serial#='&2'
and ('&3' is null or h.sample_time>systimestamp-interval '0&3' minute)
group by h.TOP_LEVEL_SQL_ID
)
select
c.TOP_LEVEL_SQL_ID
,c.cnt
,to_char(substr(a.sql_fulltext,1,4000)) text
from top_level_calls c
,v$sqlarea a
where c.TOP_LEVEL_SQL_ID=a.sql_id
order by
cnt desc
, top_level_sql_id;
col owner clear;
col procedure_name clear;
col top_level_sql_id clear;
col object_name clear;
col text clear;
@inc/input_vars_undef;