Based on
Performing Application Tracing in Oracle Database 12.1 SQL Tuning Guide
Add the following to your application code:
ALTER SESSION SET TRACEFILE_IDENTIFIER = 'PublishInfoModule';
exec DBMS_APPLICATION_INFO.SET_CLIENT_INFO (client_info=>'BroadcastPublish');
exec DBMS_APPLICATION_INFO.SET_MODULE(module_name=>'Broadcast', action_name=>NULL);
Right before a SELECT statement:
exec DBMS_APPLICATION_INFO.SET_ACTION(action_name=>'GetRows');
Right before an UPDATE statement:
exec DBMS_APPLICATION_INFO.SET_ACTION(action_name=>'MarkAsPublished');
Enable statistics gathering for End-to-End Tracing. Note that the names of service, module and actions are case sensitive, and need to be referred to as they are found in v$sessions and v$services:
exec DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name=>'proddb01',module_name=>'Broadcast',action_name=>'BroadcastPublish');
exec DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name=>'proddb01',module_name=>'Broadcast',action_name =>'MarkAsPublished', WAITS=>TRUE,binds=>TRUE,plan_stat=>'FIRST_EXECUTION');
Go to the trace file location, found as a subdirectory in the location specified by diagnostic_dest:
show parameter diagnostic_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
diagnostic_dest string /u01/oracle
In my case:
cd /u01/oracle/diag/rdbms/proddb01/proddb01/trace
You should now find files named according to your SET TRACEFILE_IDENTIFIER command previously:
-rw-r----- 1 oracle dba 732258822 Feb 26 07:49 alert_proddb01.log
-rw-r----- 1 oracle dba 24398 Feb 26 08:21 proddb01_ora_54248.trc
-rw-r----- 1 oracle dba 120418 Feb 26 08:21 proddb01_ora_54248.trm
-rw-r----- 1 oracle dba 3077570 Feb 26 08:26 proddb01_ora_35967_PublishInfoModule.trm
-rw-r----- 1 oracle dba 133643579 Feb 26 08:26 proddb01_ora_35967_PublishInfoModule.trc
Disable statistics gathering, and disable the trace:
exec DBMS_MONITOR.SERV_MOD_ACT_STAT_DISABLE(service_name=>'proddb01',module_name=>'Broadcast',action_name=>'BroadcastPublish');
exec DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name=>'proddb01',module_name=>'Broadcast',action_name =>'MarkAsPublished');
You can now format these using tkprof:
tkprof /u01/oracle/diag/rdbms/proddb01/proddb01/trace/proddb01_ora_35967_PublishInfoModule.trc
/u01/oracle/admin/proddb01/sql/tuning/tkprof2/tkprof_2.out
waits=yes
sort=EXEDSK
insert=insert.sql
sys=no
explain=broadcaster/****
record=tkprof_sqlstmts.sql
table=sys.PLAN_TABLE$
The output will be the file /u01/oracle/admin/proddb01/sql/tuning/tkprof2/tkprof_2.out
tkprof has many
options and you should take some time to get familiarized with the tool before you start. A key point is to minimize the information so that you find what's relevant to you.
For a shortlist of commands, see
this post.
If you have many trace files generated by multiple sessions, you need to use another tool called
trcsess to merge all these into one single trace file that you then format with tkprof, which I will demonstrate next.
In the following example, I am creating tracefiles for a specific action set in the application code.
The application code uses this code:
ALTER SESSION SET TRACEFILE_IDENTIFIER = 'Reporter';
BEGIN
DBMS_APPLICATION_INFO.SET_ACTION(action_name=>'getNextOutlook/actions/report');
END;
/
So I will execute
cd trace
trcsess output=getNextOutlook.out action='getNextOutlook/actions/report' pks_*report*.trc
Which will search all trace files matching the wildkard pks_*report*.trc and generate the file
getNextOutlook.out