[Home] [Help]
PACKAGE BODY: APPS.PO_TIMING_UTL
Source
1 PACKAGE BODY PO_TIMING_UTL AS
2 /* $Header: PO_TIMING_UTL.plb 120.0 2005/07/20 10:42 bao noship $ */
3
4 -- Use this pacakge to record timing information of the program modules
5 -- for the current session.
6 -- All modules are identified by module name, which will be provided by the
7 -- caller.
8 -- To start timing, call procedure start_time
9 -- To end timing for a particular module, call procedure end_time
10 -- get_formatted_timing_info() returns a list of modules with the time recorded,
11 -- represented as strings. The caller can then put these information to log
12 -- or debug file
13 -- Internally, each module provided by the caller will be tracked with a
14 -- number attached, starting from '1'. If the same module gets timed multiple
15 -- times, there will be multiple entries tracked in this package, with
16 -- module_name being equal to <module_name>-1, <module_name>-2,... etc.
17 --
18 -- Example:
19 -- DECLARE
20 -- l_timing PO_TBL_VARCHAR4000;
21 -- BEGIN
22 -- PO_TIMING_UTL.init;
23 -- PO_TIMING_UTL.start_time('A');
24 -- PO_TIMING_UTL.start_time('B');
25 -- PO_TIMING_UTL.stop_time('B');
26 -- PO_TIMING_UTL.start_time('B');
27 -- PO_TIMING_UTL.stop_time('B');
28 -- PO_TIMING_UTL.stop_time('A');
29 --
30 -- PO_TIMING_UTL.get_formatted_timing_info (FND_API.G_TRUE, l_timing);
31 -- END;
32 --
33 -- In this example, l_timing record will contain entries like the following:
34 -- A-1: Start=11:33:25.529, End=11:33:25.529, Duration=+00 00:00:00.000140
35 -- B-1: Start=11:33:25.529, End=11:33:25.529, Duration=+00 00:00:00.000020
36 -- B-2: Start=11:33:25.529, End=11:33:25.529, Duration=+00 00:00:00.000020
37
38 d_pkg_name CONSTANT VARCHAR2(50) :=
39 PO_LOG.get_package_base('PO_TIMING_UTL');
40
41 g_module_list PO_TBL_VARCHAR100;
42
43 TYPE timing_rec_type IS RECORD (start_time timestamp, end_time timestamp);
44 TYPE timing_tbl_type IS TABLE OF timing_rec_type INDEX BY VARCHAR2(100);
45
46 g_timing_list timing_tbl_type;
47
48 TYPE module_index_tbl_type IS TABLE OF NUMBER INDEX BY VARCHAR2(100);
49
50 g_module_index_list MODULE_INDEX_TBL_TYPE;
51
52 -------------------------------------------------------
53 -------------- PUBLIC PROCEDURES ----------------------
54 -------------------------------------------------------
55
56 -----------------------------------------------------------------------
57 --Start of Comments
58 --Name: init
59 --Function:
60 -- Initialize the structure that tracks the timing information of the
61 -- modules
62 --Parameters:
63 --IN:
64 --IN OUT:
65 --OUT:
66 --End of Comments
67 ------------------------------------------------------------------------
68 PROCEDURE init IS
69
70 d_api_name CONSTANT VARCHAR2(30) := 'init';
71 d_module CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
72 d_position NUMBER;
73
74
75 BEGIN
76 d_position := 0;
77
78 g_module_list := PO_TBL_VARCHAR100();
79 g_timing_list.DELETE;
80 g_module_index_list.DELETE;
81
82 EXCEPTION
83 WHEN OTHERS THEN
84 PO_MESSAGE_S.add_exc_msg
85 ( p_pkg_name => d_pkg_name,
86 p_procedure_name => d_api_name || '.' || d_position
87 );
88 RAISE;
89 END init;
90
91
92 -----------------------------------------------------------------------
93 --Start of Comments
94 --Name: start_time
95 --Function:
96 -- Starts timing for a given module. If the same module has been
97 -- recorded previously, a new number will be attached to the module
98 -- name
99 --Parameters:
100 --IN:
101 --p_module
102 -- Module name
103 --IN OUT:
104 --OUT:
105 --End of Comments
106 ------------------------------------------------------------------------
107 PROCEDURE start_time
108 ( p_module IN VARCHAR2
109 )
110 IS
111
112 d_api_name CONSTANT VARCHAR2(30) := 'start_time';
113 d_module CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
114 d_position NUMBER;
115
116
117 l_module_name VARCHAR2(100);
118
119 BEGIN
120 d_position := 0;
121
122 IF (NOT g_module_index_list.EXISTS(p_module)) THEN
123 g_module_index_list(p_module) := 1;
124 ELSE
125 g_module_index_list(p_module) := g_module_index_list(p_module) + 1;
126 END IF;
127
128 d_position := 10;
129
130 l_module_name := p_module || '-' || g_module_index_list(p_module);
131
132 g_module_list.EXTEND;
133 g_module_list(g_module_list.COUNT) := l_module_name;
134 g_timing_list(l_module_name).START_TIME := SYSTIMESTAMP;
135
136 EXCEPTION
137 WHEN OTHERS THEN
138 PO_MESSAGE_S.add_exc_msg
139 ( p_pkg_name => d_pkg_name,
140 p_procedure_name => d_api_name || '.' || d_position
141 );
142 RAISE;
143 END start_time;
144
145 -----------------------------------------------------------------------
146 --Start of Comments
147 --Name: stop_time
148 --Function:
149 -- Stop timing for a particular module. If the same module has been
150 -- recorded multiple times, the latest record will be updated with
151 -- the stop time information
152 --Parameters:
153 --IN:
154 --p_module
155 -- Module name
156 --IN OUT:
157 --OUT:
158 --End of Comments
159 ------------------------------------------------------------------------
160 PROCEDURE stop_time
161 ( p_module IN VARCHAR2
162 )
163 IS
164
165 d_api_name CONSTANT VARCHAR2(30) := 'stop_time';
166 d_module CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
167 d_position NUMBER;
168
169 l_module_name VARCHAR2(100);
170 BEGIN
171
172 d_position := 0;
173
174 IF (NOT g_module_index_list.EXISTS(p_module)) THEN
175 d_position := 10;
176
177 g_module_index_list(p_module) := 1;
178
179 g_module_list.EXTEND;
180 g_module_list(g_module_list.COUNT) := p_module || '-' || g_module_index_list(p_module);
181 END IF;
182
183 l_module_name := p_module || '-' || g_module_index_list(p_module);
184
185 g_timing_list(l_module_name).end_time := SYSTIMESTAMP;
186
187 EXCEPTION
188 WHEN OTHERS THEN
189 PO_MESSAGE_S.add_exc_msg
190 ( p_pkg_name => d_pkg_name,
191 p_procedure_name => d_api_name || '.' || d_position
192 );
193 RAISE;
194 END stop_time;
195
196 -----------------------------------------------------------------------
197 --Start of Comments
198 --Name: get_formatted_timing_info
199 --Function:
200 -- Returns a record of strings containing timing information for all
201 -- modules with time recorded
202 --Parameters:
203 --IN:
204 --p_cleanup
205 -- Whether we should clear all timing information after calling this
206 --IN OUT:
207 --OUT:
208 --x_timing_info
209 -- Formatted text with module name, start time, end time, and duration info
210 --End of Comments
211 ------------------------------------------------------------------------
212 PROCEDURE get_formatted_timing_info
213 ( p_cleanup IN VARCHAR2,
214 x_timing_info OUT NOCOPY PO_TBL_VARCHAR4000
215 )
216 IS
217
218 d_api_name CONSTANT VARCHAR2(30) := 'get_formatted_timing_info';
219 d_module CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
220 d_position NUMBER;
221
222 l_start_time timestamp;
223 l_end_time timestamp;
224
225 l_duration INTERVAL DAY TO SECOND;
226 BEGIN
227 d_position := 0;
228
229 x_timing_info := PO_TBL_VARCHAR4000();
230 x_timing_info.EXTEND(g_module_list.COUNT);
231
232 FOR i IN 1..g_module_list.COUNT LOOP
233 d_position := 10;
234
235 l_start_time := g_timing_list(g_module_list(i)).start_time;
236 l_end_time := g_timing_list(g_module_list(i)).end_time;
237
238 l_duration := l_end_time - l_start_time;
239
240 x_timing_info(i) := g_module_list(i) || ': ' ||
241 'Start=' || TO_CHAR(l_start_time, 'HH24:MI:SS.FF3') || ', ' ||
242 'End=' || TO_CHAR(l_end_time, 'HH24:MI:SS.FF3') || ', ' ||
243 'Duration=' || l_duration;
244
245 END LOOP;
246
247 IF (p_cleanup = FND_API.G_TRUE) THEN
248 -- reinitialize global variables.
249 init;
250 END IF;
251
252 EXCEPTION
253 WHEN OTHERS THEN
254 PO_MESSAGE_S.add_exc_msg
255 ( p_pkg_name => d_pkg_name,
256 p_procedure_name => d_api_name || '.' || d_position
257 );
258 RAISE;
259 END get_formatted_timing_info;
260
261 END PO_TIMING_UTL;