table of contents
preface
- visualizing the oracle performance graph by average active sessions (chinese)
- visualizing the oracle performance graph by average active sessions & logic cpus (chinese)
- visualizing the oracle performance graph by average runnable processes (chinese)
- visualizing the oracle performance graph by active sessions per activity class (chinese)
dimension directory lists
active sessions per wait class in last 1 hour
exploring "cpu used" and "cpu wait"
set linesize 200
column metric_name format a30
column metric_unit format a25
select distinct metric_name
, metric_unit
from v$sysmetric_history
where metric_name like '�tabase%'
or metric_name like '%cpu%'
order by 1
;
metric_name metric_unit
------------------------------ -------------------------
background cpu usage per sec centiseconds per second
cpu usage per sec centiseconds per second <<==
cpu usage per txn centiseconds per txn
database cpu time ratio % cpu/db_time <<==
database time per sec centiseconds per second <<==
database wait time ratio % wait/db_time
host cpu usage per sec centiseconds per second
host cpu utilization (%) % busy/(idle busy)
8 rows selected.
as you can see above my query returned line 2, 4 and 5 (marked with "<<=="), we hope to get a conclusion that "cpu usage per sec" compares with "database time per sec" * "database cpu time ratio", the following is the corresponding sql query and result.
set linesize 200
set pagesize 100
column sample_time format a11
column metric_name format a11
column active_sessions format 999,999.999
with
cpu_1 as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, decode(metric_name, 'cpu usage per sec', 'cpu_1') metric_name
, round(value/1e2, 3) active_sessions
from v$sysmetric_history
where metric_name = 'cpu usage per sec'
and group_id = 2
and end_time >= sysdate - interval '60' minute
order by sample_time
),
db_cpu as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, max(decode(metric_name, 'database time per sec' , value/1e2)) aas_value
, max(decode(metric_name, 'database cpu time ratio', value/1e2)) cpu_ratio
from v$sysmetric_history
where metric_name in ('database time per sec', 'database cpu time ratio')
and group_id = 2
and end_time >= sysdate - interval '60' minute
group by to_char(end_time, 'hh24:mi:ss')
order by sample_time
),
cpu_2 as
(
select sample_time
, 'cpu_2' metric_name
, round(aas_value*cpu_ratio, 3) active_sessions
from db_cpu
)
select c1.sample_time
, c2.sample_time
, 'cpu diff' metric_name
, c1.active_sessions - c2.active_sessions active_sessions
from cpu_1 c1
, cpu_2 c2
where c1.sample_time = c2.sample_time
;
sample_time sample_time metric_name active_sessions
----------- ----------- ----------- ---------------
09:26:44 09:26:44 cpu diff .000
09:27:45 09:27:45 cpu diff .000
09:28:45 09:28:45 cpu diff .000
09:29:44 09:29:44 cpu diff .000
09:30:45 09:30:45 cpu diff .000
09:31:44 09:31:44 cpu diff .000
09:32:45 09:32:45 cpu diff .000
09:33:44 09:33:44 cpu diff .000
09:34:45 09:34:45 cpu diff .000
09:35:45 09:35:45 cpu diff .000
09:36:44 09:36:44 cpu diff .000
09:37:45 09:37:45 cpu diff .000
09:38:45 09:38:45 cpu diff .000
09:39:44 09:39:44 cpu diff .000
09:40:45 09:40:45 cpu diff .000
09:41:44 09:41:44 cpu diff .000
09:42:45 09:42:45 cpu diff .000
09:43:45 09:43:45 cpu diff .000
09:44:45 09:44:45 cpu diff .000
09:45:45 09:45:45 cpu diff .000
09:46:44 09:46:44 cpu diff .000
09:47:45 09:47:45 cpu diff .000
09:48:45 09:48:45 cpu diff .000
09:49:44 09:49:44 cpu diff .000
09:50:45 09:50:45 cpu diff .000
09:51:45 09:51:45 cpu diff .000
09:52:45 09:52:45 cpu diff .000
09:53:45 09:53:45 cpu diff .000
09:54:45 09:54:45 cpu diff .000
09:55:45 09:55:45 cpu diff .000
09:56:45 09:56:45 cpu diff .000
09:57:45 09:57:45 cpu diff .000
09:58:45 09:58:45 cpu diff .000
09:59:45 09:59:45 cpu diff .000
10:00:44 10:00:44 cpu diff .000
10:01:45 10:01:45 cpu diff .000
10:02:45 10:02:45 cpu diff .000
10:03:45 10:03:45 cpu diff .000
10:04:45 10:04:45 cpu diff .000
10:05:45 10:05:45 cpu diff .000
10:06:45 10:06:45 cpu diff .000
10:07:45 10:07:45 cpu diff .000
10:08:45 10:08:45 cpu diff .000
10:09:45 10:09:45 cpu diff .000
10:10:45 10:10:45 cpu diff .000
10:11:45 10:11:45 cpu diff .000
10:12:45 10:12:45 cpu diff .000
10:13:45 10:13:45 cpu diff .000
10:14:45 10:14:45 cpu diff .000
10:15:45 10:15:45 cpu diff .000
10:16:45 10:16:45 cpu diff .000
10:17:46 10:17:46 cpu diff .000
10:18:45 10:18:45 cpu diff .000
10:19:45 10:19:45 cpu diff .000
10:20:46 10:20:46 cpu diff .000
10:21:45 10:21:45 cpu diff .000
10:22:45 10:22:45 cpu diff .000
10:23:45 10:23:45 cpu diff .000
10:24:45 10:24:45 cpu diff .000
10:25:45 10:25:45 cpu diff .000
60 rows selected.
amazing! they're real equivalent. next we investigate the case of "database cpu time ratio" "database wait time ratio". taking a closer look at this sql query and result as below:
set linesize 200
set pagesize 100
column sample_time format a11
column metric_name format a11
column active_sessions format 999,999.999
with
cpu_and_wait_ratio as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, max(decode(metric_name, 'database cpu time ratio' , value/1e2)) cpu_ratio
, max(decode(metric_name, 'database wait time ratio', value/1e2)) wait_ratio
from v$sysmetric_history
where metric_name in ('database cpu time ratio', 'database wait time ratio')
and group_id = 2
and end_time >= sysdate - interval '60' minute
group by to_char(end_time, 'hh24:mi:ss')
order by sample_time
)
select sample_time
, 'total ratio' metric_name
, round(cpu_ratio wait_ratio, 3) total_ratio
from cpu_and_wait_ratio
order by sample_time
;
sample_time metric_name total_ratio
----------- ----------- -----------
09:41:44 total ratio 1.292
09:42:45 total ratio 1.452
09:43:45 total ratio 1.432
09:44:45 total ratio 1.425
09:45:45 total ratio 1.272
09:46:44 total ratio 1.165
09:47:45 total ratio 1.164
09:48:45 total ratio 1.061
09:49:44 total ratio 1.296
09:50:45 total ratio 1.406
09:51:45 total ratio 1.44
09:52:45 total ratio 1.365
09:53:45 total ratio 1.124
09:54:45 total ratio 1.307
09:55:45 total ratio 1.15
09:56:45 total ratio 1.255
09:57:45 total ratio 1.342
09:58:45 total ratio 1.168
09:59:45 total ratio 1.337
10:00:44 total ratio 1.323
10:01:45 total ratio 1.313
10:02:45 total ratio 1.284
10:03:45 total ratio 1.124
10:04:45 total ratio 1.204
10:05:45 total ratio 1.057
10:06:45 total ratio 1.085
10:07:45 total ratio 1
10:08:45 total ratio 1.296
10:09:45 total ratio 1.368
10:10:45 total ratio 1.326
10:11:45 total ratio 1.405
10:12:45 total ratio 1.326
10:13:45 total ratio 1.246
10:14:45 total ratio 1.326
10:15:45 total ratio 1.184
10:16:45 total ratio 1.375
10:17:46 total ratio 1.415
10:18:45 total ratio 1.061
10:19:45 total ratio 1.075
10:20:46 total ratio 1.265
10:21:45 total ratio 1.198
10:22:45 total ratio 1.34
10:23:45 total ratio 1.293
10:24:45 total ratio 1.273
10:25:45 total ratio 1.221
10:26:45 total ratio 1.254
10:27:46 total ratio 1.221
10:28:45 total ratio 1.219
10:29:46 total ratio 1.315
10:30:45 total ratio 1.087
10:31:45 total ratio 1.256
10:32:45 total ratio 1.213
10:33:45 total ratio 1.295
10:34:46 total ratio 1.394
10:35:45 total ratio 1.176
10:36:45 total ratio 1.018
10:37:45 total ratio 1.196
10:38:45 total ratio 1.169
10:39:46 total ratio 1.225
10:40:45 total ratio 1.184
60 rows selected.
wow! the ratio is exceeded 100%, why? we know, on one hand aas ("average active sessions", aka, "database time per sec") includes the cpu time and wait time (non-idle) on oracle database, on the other hand cpu time on oracle database also contains cpu used and cpu wait, i think that the metric_name "database wait time ratio" should include the ratio of cpu wait and wait time (non-idle), otherwise the prior total ratio is impossible to exceed 100%. in other words oracle calculates cpu wait twice in "database cpu time ratio" and "database wait time ratio". however, our aim is to acquire cpu used and cpu wait from total cpu time. now the current workaround retrieving cpu used is like this, "database time per sec" * (1 - "database wait time ratio"), next cpu wait is such as, "cpu usage per sec" - "cpu used". certainly, the subsequent sql query and result is as follows:
-- the sql statement about 'cpu used' and 'cpu wait' is right.
set linesize 200
set pagesize 150
column sample_time format a11
column metric_name format a11
column active_sessions format 999,999.999
with
all_cpu as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, decode(metric_name, 'cpu usage per sec', 'cpu') metric_name
, round(value/1e2, 3) active_sessions
from v$sysmetric_history
where metric_name = 'cpu usage per sec'
and group_id = 2
and end_time >= sysdate - interval '60' minute
order by sample_time
),
db_wait as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, max(decode(metric_name, 'database time per sec' , value/1e2)) aas_value
, max(decode(metric_name, 'database wait time ratio', value/1e2)) wait_ratio
from v$sysmetric_history
where metric_name in ('database time per sec', 'database wait time ratio')
and group_id = 2
and end_time >= sysdate - interval '60' minute
group by to_char(end_time, 'hh24:mi:ss')
order by sample_time
),
cpu_used as
(
select sample_time
, 'cpu used' metric_name
, round(aas_value*(1-wait_ratio), 3) active_sessions
from db_wait
),
cpu_wait as
(
select cu.sample_time
, 'cpu wait' metric_name
, ac.active_sessions - cu.active_sessions active_sessions
from all_cpu ac
, cpu_used cu
where ac.sample_time = cu.sample_time
)
select * from cpu_used
union all
select * from cpu_wait
;
sample_time metric_name active_sessions
----------- ----------- ---------------
10:30:45 cpu used .386
10:31:45 cpu used .301
10:32:45 cpu used .240
10:33:45 cpu used .261
10:34:46 cpu used .200
10:35:45 cpu used .290
10:36:45 cpu used .312
10:37:45 cpu used .244
10:38:45 cpu used .274
10:39:46 cpu used .268
10:40:45 cpu used .283
10:41:45 cpu used .193
10:42:45 cpu used .209
10:43:45 cpu used .263
10:44:46 cpu used .242
10:45:45 cpu used .257
10:46:45 cpu used .285
10:47:46 cpu used .222
10:48:45 cpu used .615
10:49:45 cpu used .179
10:50:45 cpu used .196
10:51:45 cpu used .204
10:52:45 cpu used .251
10:53:45 cpu used .317
10:54:46 cpu used .225
10:55:45 cpu used .211
10:56:45 cpu used .242
10:57:46 cpu used .287
10:58:45 cpu used .253
10:59:45 cpu used .209
11:00:46 cpu used .182
11:01:46 cpu used .254
11:02:45 cpu used .255
11:03:46 cpu used .291
11:04:45 cpu used .435
11:05:46 cpu used .430
11:06:46 cpu used .485
11:07:45 cpu used .343
11:08:45 cpu used .224
11:09:46 cpu used .226
11:10:46 cpu used .206
11:11:45 cpu used .257
11:12:46 cpu used .218
11:13:46 cpu used .237
11:14:46 cpu used .219
11:15:46 cpu used .222
11:16:45 cpu used .194
11:17:46 cpu used .218
11:18:45 cpu used .624
11:19:45 cpu used .206
11:20:46 cpu used .212
11:21:45 cpu used .246
11:22:46 cpu used .272
11:23:46 cpu used .283
11:24:45 cpu used .252
11:25:46 cpu used .414
11:26:46 cpu used .356
11:27:45 cpu used .249
11:28:46 cpu used .426
11:29:46 cpu used .263
10:30:45 cpu wait .033
10:31:45 cpu wait .077
10:32:45 cpu wait .051
10:33:45 cpu wait .077
10:34:46 cpu wait .079
10:35:45 cpu wait .051
10:36:45 cpu wait .006
10:37:45 cpu wait .048
10:38:45 cpu wait .047
10:39:46 cpu wait .060
10:40:45 cpu wait .052
10:41:45 cpu wait .084
10:42:45 cpu wait .080
10:43:45 cpu wait .033
10:44:46 cpu wait .035
10:45:45 cpu wait .033
10:46:45 cpu wait .062
10:47:46 cpu wait .075
10:48:45 cpu wait .070
10:49:45 cpu wait .089
10:50:45 cpu wait .083
10:51:45 cpu wait .071
10:52:45 cpu wait .039
10:53:45 cpu wait .048
10:54:46 cpu wait .058
10:55:45 cpu wait .066
10:56:45 cpu wait .054
10:57:46 cpu wait .029
10:58:45 cpu wait .070
10:59:45 cpu wait .068
11:00:46 cpu wait .082
11:01:46 cpu wait .022
11:02:45 cpu wait .044
11:03:46 cpu wait .049
11:04:45 cpu wait .064
11:05:46 cpu wait .064
11:06:46 cpu wait .037
11:07:45 cpu wait .072
11:08:45 cpu wait .074
11:09:46 cpu wait .064
11:10:46 cpu wait .079
11:11:45 cpu wait .039
11:12:46 cpu wait .056
11:13:46 cpu wait .067
11:14:46 cpu wait .063
11:15:46 cpu wait .054
11:16:45 cpu wait .074
11:17:46 cpu wait .068
11:18:45 cpu wait .062
11:19:45 cpu wait .072
11:20:46 cpu wait .060
11:21:45 cpu wait .038
11:22:46 cpu wait .034
11:23:46 cpu wait .020
11:24:45 cpu wait .032
11:25:46 cpu wait .063
11:26:46 cpu wait .076
11:27:45 cpu wait .073
11:28:46 cpu wait .059
11:29:46 cpu wait .080
120 rows selected.
[back to aspwc in last 1 hour]
exploring the rest of wait class
i would like to thank kyle hailey because his sql code snippet (also mentioned in my previous blog note) gave me some inspiration and thought. see here:
......
select
decode(n.wait_class,'user i/o','user i/o',
'commit','commit',
'wait') class,
sum(round(m.time_waited/m.intsize_csec,3)) aas,
begin_time ,
end_time
from v$waitclassmetric m,
v$system_wait_class n
where m.wait_class_id=n.wait_class_id
and n.wait_class != 'idle'
group by decode(n.wait_class,'user i/o','user i/o', 'commit','commit', 'wait'), begin_time, end_time
......
finally the sql about wait class (due to so many returned lines thus omitted it) like this,
-- wait class (but no found 'queueing').
set linesize 200
set pagesize 800
column sample_time format a11
column metric_name format a15
column active_sessions format 999,999.999
select to_char(wcmh.end_time, 'hh24:mi:ss') sample_time
, swc.wait_class metric_name
, round(wcmh.time_waited_fg/wcmh.intsize_csec, 3) active_sessions
from v$waitclassmetric_history wcmh
, v$system_wait_class swc
where wcmh.wait_class_id = swc.wait_class_id
and swc.wait_class <> 'idle'
and wcmh.end_time >= sysdate - interval '60' minute
order by decode(swc.wait_class, 'scheduler' , 1
, 'user i/o' , 2
, 'system i/o' , 3
, 'concurrency' , 4
, 'application' , 5
, 'commit' , 6
, 'configuration' , 7
, 'administrative', 8
, 'network' , 9
, 'queueing' , 10
, 'cluster' , 11
, 'other' , 12
)
, sample_time
;
nevertheless i've no found this wait class with "queueing" from above query result, you know, we can see the legend of "queueing" from emcc 13.5 in the following screenshot.
[back to aspwc in last 1 hour]
adding "queueing"
we can separately check the column "wait_class" from the view "v$system_wait_class" and "v$event_name", they're as below:
select distinct wait_class from v$system_wait_class order by 1;
wait_class
---------------
administrative
application
commit
concurrency
configuration
idle
network
other
scheduler
system i/o
user i/o
11 rows selected.
select distinct wait_class from v$event_name order by 1;
wait_class
---------------
administrative
application
cluster
commit
concurrency
configuration
idle
network
other
queueing <<==
scheduler
system i/o
user i/o
13 rows selected.
good! there exists "queueing" on the sql query of view "v$event_name". so we have to slightly adjust the preceding sql about wait class, such as,
-- wait class (it has 'queueing').
set linesize 200
set pagesize 800
column sample_time format a11
column metric_name format a15
column active_sessions format 999,999.999
with en_wc as
(
select distinct wait_class_id
, wait_class
from v$event_name
)
select to_char(wcmh.end_time, 'hh24:mi:ss') sample_time
, ew.wait_class metric_name
, round(wcmh.time_waited_fg/wcmh.intsize_csec, 3) active_sessions
from v$waitclassmetric_history wcmh
, en_wc ew
where wcmh.wait_class_id = ew.wait_class_id
and ew.wait_class <> 'idle'
and wcmh.end_time >= sysdate - interval '60' minute
order by decode(ew.wait_class, 'scheduler' , 1
, 'user i/o' , 2
, 'system i/o' , 3
, 'concurrency' , 4
, 'application' , 5
, 'commit' , 6
, 'configuration' , 7
, 'administrative', 8
, 'network' , 9
, 'queueing' , 10
, 'cluster' , 11
, 'other' , 12
)
, sample_time
;
[back to aspwc in last 1 hour]
integrating "cpu used", "cpu wait" and "wait class" by "with xxx as () ..."
the big query finished integrating "cpu used", "cpu wait" and "wait class" by "with xxx as () ..." is as follows.
-- active sessions per wait class from emcc 13.5 in last 1 hour.
set linesize 200
set pagesize 1000
column sample_time format a11
column metric_name format a15
column active_sessions format 999,999.999
with
all_cpu as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, decode(metric_name, 'cpu usage per sec', 'cpu') metric_name
, round(value/1e2, 3) active_sessions
from v$sysmetric_history
where metric_name = 'cpu usage per sec'
and group_id = 2
and end_time >= sysdate - interval '60' minute
order by sample_time
),
db_wait as
(
select to_char(end_time, 'hh24:mi:ss') sample_time
, max(decode(metric_name, 'database time per sec' , value/1e2)) aas_value
, max(decode(metric_name, 'database wait time ratio', value/1e2)) wait_ratio
from v$sysmetric_history
where metric_name in ('database time per sec', 'database wait time ratio')
and group_id = 2
and end_time >= sysdate - interval '60' minute
group by to_char(end_time, 'hh24:mi:ss')
order by sample_time
),
cpu_used as
(
select sample_time
, 'cpu used' metric_name
, round(aas_value*(1-wait_ratio), 3) active_sessions
from db_wait
),
cpu_wait as
(
select cu.sample_time
, 'cpu wait' metric_name
, ac.active_sessions - cu.active_sessions active_sessions
from all_cpu ac
, cpu_used cu
where ac.sample_time = cu.sample_time
),
en_wc as
(
select distinct wait_class_id
, wait_class
from v$event_name
),
wait_class as
(
select to_char(wcmh.end_time, 'hh24:mi:ss') sample_time
, ew.wait_class metric_name
, round(wcmh.time_waited_fg/wcmh.intsize_csec, 3) active_sessions
from v$waitclassmetric_history wcmh
, en_wc ew
where wcmh.wait_class_id = ew.wait_class_id
and ew.wait_class <> 'idle'
and wcmh.end_time >= sysdate - interval '60' minute
order by decode(ew.wait_class, 'scheduler' , 1
, 'user i/o' , 2
, 'system i/o' , 3
, 'concurrency' , 4
, 'application' , 5
, 'commit' , 6
, 'configuration' , 7
, 'administrative', 8
, 'network' , 9
, 'queueing' , 10
, 'cluster' , 11
, 'other' , 12
)
, sample_time
)
select * from cpu_used
union all
select * from cpu_wait
union all
select * from wait_class
;
[back to aspwc in last 1 hour]
visualizing aspwc by oracle sql developer 21.2
imported by clicking "open report" that you'll find when right clicking the mouse on the section "user defined reports" (showing in reports tab, you can find "reports" in the top menu "view") on oracle sql developer 21.2, next i've noticed that the rest 9 number of legend colors of the graph is different from emcc 13.5 when connecting to my oracle db to check it. yes, sql developer 21.2 has only set the default 5 number of legend colors in the section "series options" of plot area on the "edit report" dialog box. taking a look at the following 3 screenshots.
fortunately gave me a nice workaround, here i quoted his approach and screenshots as below.
save the report as xml and amend it according the screenshot. then open the report from xml. you can change the color scheme in sqldev for all 14 values. however,
is lost when the report is saved.
now we use the previously same steps to import to "user defined reports" of sql developer and then recheck the graph. here's the screenshot.
[back to aspwc in last 1 hour]
the graph from sql developer versus emcc
let's compare the graph between sql developer and emcc, here's almost identical result.
[back to aspwc in last 1 hour]
active sessions per wait class in last 1 minute
due to spend plenty of time talking about the final visualizing graph on the preceding section hence i'll use the simple several steps to finish visualizing the graph in this section. we directly import to "user defined reports" of oracle sql developer 21.2, here's the corresponding the graph.
how to acquire the legend colors from emcc
first of all, we use a screen-capture tool to capture each legend color on the graph "active sessions per wait class" from emcc 13.5, secondly save it to a local file, thirdly uploading this picture to that is able to identify the rgb value (it's hexadecimal starting with "#"), fourthly converting "#xxxxxx" to "rgb (xxx, xxx, xxx)" using . ultimately we've gotten the following rgb value.
-- each legend color from the graph of "active sessions per wait class" of emcc 13.5.
--
-- cpu used , #35c387 -> rgb (53 , 195, 135)
-- cpu wait , #a9f89c -> rgb (169, 248, 156)
-- scheduler , #cbe8cd -> rgb (203, 232, 205)
-- user i/o , #0072ca -> rgb (0 , 114, 202)
-- system i/o , #04dede -> rgb (4 , 222, 222)
-- concurrency , #8b60c9 -> rgb (139, 96 , 201)
-- application , #ff5c38 -> rgb (255, 92 , 56 )
-- commit , #ffb146 -> rgb (255, 177, 70 )
-- configuration , #faf37d -> rgb (250, 243, 125)
-- administrative, #ffcc48 -> rgb (255, 204, 72 )
-- network , #00c0f0 -> rgb (0 , 192, 240)
-- queueing , #c5b79b -> rgb (197, 183, 155)
-- cluster , #cbc2af -> rgb (203, 194, 175)
-- other , #f76aae -> rgb (247, 106, 174)
at this very moment all of the content about this blog note has been introduced completely. you can acquire all of source codes from and . any suggestion and opinion is always welcome, don't hesitate to leave your comments in the bottom of comment area. i'll read every message and reply to you as soon as possible.