PROMPT Task that reports specified session statistics over a given time period.
PROMPT Two tasks are used - one for initial snapshot and another to produce report.

CONN &&tascha_schema/&&tascha_password

SET SERVEROUTPUT ON

DECLARE
	L_task_id	NUMBER;
	L_sched_id	NUMBER;
	L_statname	VARCHAR2 (100) := 'CPU used by this session';
BEGIN
	tascha_pkg.create_task(	I_procedure_name => 'sesstats'
			,	I_title		=> 'Session Statistics Report'
			,	I_category	=> 'DBA'
			,	O_task_id	=> L_task_id);

	dbms_output.put_line('task:'||L_task_id);

	/* Request initial snapshot task */

	tascha_pkg.schedule_task(I_task_id 	=> L_task_id
			,	I_title		=> 'CPU Used Snapshot'
			,	I_hour 		=> '11'
			,	I_min 		=> '00'
			,	I_dow 		=> 'MON-FRI'
			,	O_sched_id 	=> L_sched_id);

	dbms_output.put_line('sched:'||L_sched_id);

	tascha_pkg.add_task_prm(L_sched_id,	'I_stat_name',	L_statname);
	tascha_pkg.add_task_prm(L_sched_id,	'I_which',	1);

	/* Request second snapshot which also reports (10 mins after first) */

	tascha_pkg.create_task(	I_procedure_name => 'sesstats'
			,	I_title		=> 'Session Statistics Report'
			,	I_success_email => '&&email_output_to'
			,	I_category	=> 'DBA'
			,	O_task_id	=> L_task_id);

	dbms_output.put_line('task:'||L_task_id);

	tascha_pkg.schedule_task(	I_task_id	=> L_task_id
				,	I_title		=> 'CPU Used Report'
				,	I_hour		=> '11'
				,	I_min		=> '10'
				,	I_dow		=> 'MON-FRI'
				,	O_sched_id	=> L_sched_id);

	dbms_output.put_line('sched:'||L_sched_id);

	tascha_pkg.add_task_prm(L_sched_id,	'I_stat_name',	L_statname);
	tascha_pkg.add_task_prm(L_sched_id,	'I_which',	2);

	COMMIT;
END;
/
