public static void printStackTrace(Throwable th) {
for (StackTraceElement ste : th.getStackTrace()) {
System.out.println("file " + ste.getFileName() + ", method " + ste.getMethodName() + ", line "
+ ste.getLineNumber() + ", " + th.getMessage());
}
if (th.getCause() != null) {
System.out.println("... cause ...");
printStackTrace(th.getCause());
}
}
this blog is intended to be a place to store code snippets, examples, notes... in order to have them handy and to quickly find during the everyday work
Search This Blog
Monday, 4 June 2012
print java stack trace
this is a Java static method that prints on the System.out the stack trace of a Throwable object. It goes recursively through the chain of Throwable objects, printing also the causing objects.
Wednesday, 4 April 2012
free space in tablespace
SELECT /* + RULE */ df.tablespace_name "Tablespace",
df.bytes / (1024 * 1024) "Size (MB)",
SUM(fs.bytes) / (1024 * 1024) "Free (MB)",
Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",
Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"
FROM dba_free_space fs,
(SELECT tablespace_name,SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) df
WHERE fs.tablespace_name (+) = df.tablespace_name
--AND df.tablespace_name LIKE 'UNDO%'
GROUP BY df.tablespace_name,df.bytes
UNION ALL
SELECT /* + RULE */ df.tablespace_name tspace,
fs.bytes / (1024 * 1024),
SUM(df.bytes_free) / (1024 * 1024),
Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),
Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)
FROM dba_temp_files fs,
(SELECT tablespace_name,bytes_free,bytes_used
FROM v$temp_space_header
GROUP BY tablespace_name,bytes_free,bytes_used) df
WHERE fs.tablespace_name (+) = df.tablespace_name
--and df.tablespace_name LIKE 'UNDO%'
GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
ORDER BY 4 DESC;
Tuesday, 31 January 2012
Oracle, resource-consuming queries
SELECT DISTINCT p.Sql_Id AS Sql_Id,
CASE
WHEN p.Id = 0 THEN
Sq.Module
ELSE
NULL
END AS Module,
p.Id,
Lpad(' ', 4 * Depth) || p.Operation AS Operation,
p.Options AS "Access",
p.Object_Name AS "Object",
p.Cost AS "Cost",
Trunc(p.Cpu_Cost / 1000000, 2) AS "Cpu_Seconds",
p.Cardinality,
p.Io_Cost AS "IO Cost",
p.TIME,
p.Filter_Predicates,
p.Access_Predicates,
CASE
WHEN p.Id = 0 THEN
Sq.Sql_Text
ELSE
NULL
END AS Sql_Text,
CASE
WHEN p.Id = 0 THEN
Sq.Last_Active_Time
ELSE
NULL
END AS Last_Active_Time,
Filtro.Costosum
FROM V$sql_Plan p
INNER JOIN V$sql Sq
ON Sq.Sql_Id = p.Sql_Id
INNER JOIN (SELECT Filtro_Rownum.Sql_Id, Filtro_Rownum.Costosum
FROM (SELECT Tmp.Sql_Id, SUM(Tmp.Cost) AS Costosum
FROM (SELECT s.Sql_Text,
p.Sql_Id,
p.Plan_Hash_Value,
p.Cost
FROM V$sql s
INNER JOIN V$sql_Plan p
ON s.Sql_Id = p.Sql_Id
WHERE 1 = 1
AND Upper(s.Sql_Text) NOT LIKE
'%EXPLAIN PLAN%'
AND s.Last_Active_Time > SYSDATE - 0.3
AND upper(s.Module) <> Upper('PL/SQL Developer')
AND p.Cost IS NOT NULL
AND p.ID = 0
ORDER BY p.Cost DESC,
p.Cpu_Cost DESC,
p.Io_Cost DESC) Tmp
GROUP BY Tmp.Sql_Id
order by sum(tmp.cost) desc) Filtro_Rownum
WHERE Rownum < 200) Filtro
ON Filtro.Sql_Id = p.Sql_Id
ORDER BY Filtro.Costosum DESC, p.Sql_Id, p.Id
Thursday, 5 January 2012
Oracle profiling session
SQL> select
2 u_dump.value || '/' ||
3 db_name.value || '_ora_' ||
4 v$process.spid ||
5 nvl2(v$process.traceid, '_' || v$process.traceid, null )
6 || '.trc' "Trace File"
7 from
8 v$parameter u_dump
9 cross join v$parameter db_name
10 cross join v$process
11 join v$session
12 on v$process.addr = v$session.paddr
13 where
14 u_dump.name = 'user_dump_dest' and
15 db_name.name = 'db_name' and
16 v$session.audsid=sys_context('userenv','sessionid');
Trace File
--------------------------------------------------------------------------------
C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORCL\UDUMP/cfdev_ora_9576.trc
SQL> alter session set sql_trace = true;
Session altered.
SQL> -- your SQL or PL/SQL CODE
2 /
PL/SQL procedure successfully completed.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options
C:\>
then analyze C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORCL\UDUMP/cfdev_ora_9576.trc with tkprof
tkprof C:\ORACLE\PRODUCT\10.2.0\ADMIN\CFDEV\UDUMP/cfdev_ora_9576.trc out.txt sys=no
Subscribe to:
Comments (Atom)