NyQuest logo
HomeBanner 7 FAQTips & Tricksnavtab
menubar
Monitoring CPU Usage

-------------------------------------------------------
-- pl/sql  CPU analysis
-- the follow script will measure CPU usage per session
-------------------------------------------------------
set echo off
-------------------------------------------------------
-- CPU usage by session
-------------------------------------------------------

SET SERVEROUTPUT ON;
DECLARE
  v_str     varchar2(30);
  v_Out   VARCHAR2(250);

cursor c1 is
select  ss.username || '(' || se.sid || ')' user_process, value
  from v$session ss, v$sesstat se, v$statname sn
 where  se.statistic# = sn.statistic#
   and  name  like '%CPU used by this session%'
   and  se.sid = ss.sid
   and  ss.username is not null
 order  by user_process,value desc;

BEGIN

  DBMS_OUTPUT.ENABLE(1000000);

DBMS_OUTPUT.PUT_LINE('   ');
select 'Snapshot Date: ' || to_char(sysdate,'MM/DD/YY HH:MI:SS')
into v_out from dual;
select name into v_str from v$database;
DBMS_OUTPUT.PUT_LINE( v_out || ' Database: ' || v_str );
DBMS_OUTPUT.PUT_LINE('   ');
DBMS_OUTPUT.PUT_LINE('CPU used by this session');
DBMS_OUTPUT.PUT_LINE('------------------------');

for c1_rec in c1 loop
  DBMS_OUTPUT.PUT_LINE( rpad(c1_rec.user_process,15) ||
lpad(c1_rec.value,9));
end loop;
DBMS_OUTPUT.PUT_LINE('   ');

select 'Note: Requires timed_statistics be set to TRUE.' into
v_out
 from dual
 where 'FALSE' in (select value from v$parameter where
name='timed_statistics');
DBMS_OUTPUT.PUT_LINE( v_out );

exception
when no_data_found then
DBMS_OUTPUT.PUT_LINE('   ');

end;
/



The contents of www.nyquest.com are Copyright © 2007 by Nyquest Consulting.
Sungard® and Banner® are registered trademarks of Sungard® Corporation.
Nyquest is not affiliated in any way with Sungard®.
All Rights Reserved.