Hey Connor :-),
I've seen this pretty nice graph about "Active Sessions Per Activity Class" from EMCC 13.5, take a looking at the following 2 number of screenshots.
https://quanwenzhao.files.wordpress.com/2021/11/active-sessions-per-activity-class_1.png https://quanwenzhao.files.wordpress.com/2021/11/active-sessions-per-activity-class_2.png Hence I've spent a couple of time writing the similar SQL query, here's my code:
-- Active Sessions (in ASH) Per Activity Class from EMCC in Last 1 Hour.
SET LINESIZE 200
SET PAGESIZE 200
COLUMN sample_time FORMAT a19
COLUMN activity_class FORMAT a15
ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
SELECT TRUNC(CAST(sample_time AS DATE), 'mi') sample_time
-- , CAST(sample_time AS DATE) sample_time
, DECODE(wait_class, 'User I/O', 'User I/O', NULL, 'CPU', 'Wait') activity_class
-- , time_waited consume_time
, ROUND(COUNT(*)/6e1, 4) active_sessions
FROM v$active_session_history
WHERE session_type = 'FOREGROUND'
AND (wait_class <> 'Idle' OR wait_class IS NULL)
AND CAST(sample_time AS DATE) >= SYSDATE - 1/24
GROUP BY TRUNC(CAST(sample_time AS DATE), 'mi')
, DECODE(wait_class, 'User I/O', 'User I/O', NULL, 'CPU', 'Wait')
ORDER BY activity_class
, sample_time
;
The corresponding query result is as below,
SAMPLE_TIME ACTIVITY_CLASS ACTIVE_SESSIONS
------------------- --------------- ---------------
2021-11-10 15:50:00 CPU .4167
2021-11-10 15:51:00 CPU .3
2021-11-10 15:52:00 CPU .4667
2021-11-10 15:53:00 CPU .55
2021-11-10 15:54:00 CPU 1.0333
2021-11-10 15:55:00 CPU 1.2
2021-11-10 15:56:00 CPU .3833
2021-11-10 15:57:00 CPU 1.6667
2021-11-10 15:58:00 CPU 1.4333
2021-11-10 15:59:00 CPU 3.3
2021-11-10 16:00:00 CPU 1.6
2021-11-10 16:01:00 CPU 2.0167
2021-11-10 16:02:00 CPU 1.3667
2021-11-10 16:03:00 CPU 1.9167
2021-11-10 16:04:00 CPU 3.2167
2021-11-10 16:05:00 CPU 3.0833
2021-11-10 16:06:00 CPU 5.1
2021-11-10 16:07:00 CPU 1.5667
2021-11-10 16:08:00 CPU 1.3333
2021-11-10 16:09:00 CPU .8
2021-11-10 16:10:00 CPU 1.25
2021-11-10 16:11:00 CPU 1.7667
2021-11-10 16:12:00 CPU 2.3833
2021-11-10 16:13:00 CPU 1.2833
2021-11-10 16:14:00 CPU .35
2021-11-10 16:15:00 CPU 1.3
2021-11-10 16:16:00 CPU .3333
2021-11-10 16:17:00 CPU .2167
2021-11-10 16:18:00 CPU 3.4667
2021-11-10 16:19:00 CPU .3833
2021-11-10 16:20:00 CPU .3667
2021-11-10 16:21:00 CPU .25
2021-11-10 16:22:00 CPU .7167
2021-11-10 16:23:00 CPU 3.8
2021-11-10 16:24:00 CPU 7.25
2021-11-10 16:25:00 CPU 19.55
2021-11-10 16:26:00 CPU 17.0667
2021-11-10 16:27:00 CPU 13.9
2021-11-10 16:28:00 CPU 1.1167
2021-11-10 16:29:00 CPU .4333
2021-11-10 16:30:00 CPU 4.0333
2021-11-10 16:31:00 CPU 3.7833
2021-11-10 16:32:00 CPU 6.3167
2021-11-10 16:33:00 CPU 6.0833
2021-11-10 16:34:00 CPU 4.95
2021-11-10 16:35:00 CPU 1.2167
2021-11-10 16:36:00 CPU 4.2
2021-11-10 16:37:00 CPU 12.2667
2021-11-10 16:38:00 CPU 14.4333
2021-11-10 16:39:00 CPU 12.5833
2021-11-10 16:40:00 CPU 7.7167
2021-11-10 16:41:00 CPU 6.0667
2021-11-10 16:42:00 CPU 4.0167
2021-11-10 16:43:00 CPU 2.8833
2021-11-10 16:44:00 CPU 1.2333
2021-11-10 16:45:00 CPU 1.3333
2021-11-10 16:46:00 CPU 1.1667
2021-11-10 16:47:00 CPU 1.4833
2021-11-10 16:48:00 CPU 3.4167
2021-11-10 16:49:00 CPU 1.4
2021-11-10 16:50:00 CPU 1.6333
2021-11-10 16:06:00 User I/O .0333
2021-11-10 16:11:00 User I/O .0167
2021-11-10 15:50:00 Wait .0167
2021-11-10 15:51:00 Wait .5167
2021-11-10 15:52:00 Wait .5
2021-11-10 15:53:00 Wait .4167
2021-11-10 15:54:00 Wait .6
2021-11-10 15:55:00 Wait .8
2021-11-10 15:56:00 Wait .7
2021-11-10 15:57:00 Wait .4167
2021-11-10 15:58:00 Wait .85
2021-11-10 15:59:00 Wait .3667
2021-11-10 16:00:00 Wait .6167
2021-11-10 16:01:00 Wait .5167
2021-11-10 16:02:00 Wait .8833
2021-11-10 16:03:00 Wait .2333
2021-11-10 16:04:00 Wait .6667
2021-11-10 16:05:00 Wait .2333
2021-11-10 16:06:00 Wait 4.4167
2021-11-10 16:07:00 Wait .7167
2021-11-10 16:08:00 Wait 1.0833
2021-11-10 16:09:00 Wait .4167
2021-11-10 16:10:00 Wait .7333
2021-11-10 16:11:00 Wait .4167
2021-11-10 16:12:00 Wait 1.35
2021-11-10 16:13:00 Wait .25
2021-11-10 16:14:00 Wait .3833
2021-11-10 16:15:00 Wait .2667
2021-11-10 16:16:00 Wait .3333
2021-11-10 16:17:00 Wait .1667
2021-11-10 16:18:00 Wait .35
2021-11-10 16:19:00 Wait .3167
2021-11-10 16:20:00 Wait 1.05
2021-11-10 16:21:00 Wait .35
2021-11-10 16:22:00 Wait 1.0833
2021-11-10 16:23:00 Wait .3667
2021-11-10 16:24:00 Wait 1.3
2021-11-10 16:25:00 Wait .2167
2021-11-10 16:26:00 Wait .3167
2021-11-10 16:27:00 Wait .5833
2021-11-10 16:28:00 Wait .1333
2021-11-10 16:29:00 Wait .0667
2021-11-10 16:30:00 Wait .45
2021-11-10 16:31:00 Wait .8
2021-11-10 16:32:00 Wait 1.5
2021-11-10 16:33:00 Wait .5
2021-11-10 16:34:00 Wait .35
2021-11-10 16:35:00 Wait .2833
2021-11-10 16:36:00 Wait .4833
2021-11-10 16:37:00 Wait .2333
2021-11-10 16:38:00 Wait .3167
2021-11-10 16:39:00 Wait .0667
2021-11-10 16:40:00 Wait .2167
2021-11-10 16:41:00 Wait .2667
2021-11-10 16:42:00 Wait .1667
2021-11-10 16:43:00 Wait .9333
2021-11-10 16:44:00 Wait .4
2021-11-10 16:45:00 Wait .4
2021-11-10 16:46:00 Wait .35
2021-11-10 16:47:00 Wait .7
2021-11-10 16:48:00 Wait .2833
2021-11-10 16:49:00 Wait .4167
2021-11-10 16:50:00 Wait .0667
124 rows selected.
As you can see from the previous query result the
"Wait" is "4.4167" (and
"User I/O" is ".0333") on
"2021-11-10 16:06:00" but it's not the same value (
"Wait" is "4.890" and
"User I/O" is "0.02560") from my prior screenshots between "Wait" and "User I/O"
on the same time "4:06 PM".
So my SQL query is not accurate I think at least, could you help me correcting it? Thanks in advance!
Best Regards
Quanwen Zhao
ROUND(COUNT(*)/6e1, 4) active_sessions is historical because we simply counted the rows for it to be the number of seconds.
Try this instead - this column arrived in 12.2 I think
SUM(usecs_per_row)/1e6