-
Notifications
You must be signed in to change notification settings - Fork 16
/
systime
executable file
·531 lines (502 loc) · 26.4 KB
/
systime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#!/bin/env python
##################################################################################################
# Name: systime #
# Author: Randy Johnson #
# Description: This script prints a report FROM V$SYS_TIME_MODEL and GV$SYS_TIME_MODEL. #
# #
# Usage: systime [options] #
# #
# Options: #
# -h, --help show this help message and exit #
# -g search gv$sysemtric (default is v$sysmetric) #
# -i INSTANCES WHERE inst_id IN (1,2,3,...) #
# -m NAME WHERE UPPER(stat_name) LIKE '%CPU%' #
# -s print SQL query. #
# -v print version info. #
# #
# History: #
# #
# Date Ver. Who Change Description #
# ---------- ---- ---------------- ------------------------------------------------------------- #
# 07/31/2015 1.00 Randy Johnson Initial write. #
# 08/06/2015 2.00 Randy Johnson Changed to hierarchial report format andd global options. #
# 09/04/2015 2.01 Randy Johnson Changed to -m option to -n #
##################################################################################################
# --------------------------------------
# ---- Import Python Modules -----------
# --------------------------------------
from optparse import OptionParser
from os import environ
from os.path import basename
from sys import argv
from sys import exit
from sys import version_info
from signal import SIGPIPE
from signal import SIG_DFL
from signal import signal
from Oracle import RunSqlplus
from Oracle import SetOracleEnv
from Oracle import ParseConnectString
from Oracle import PrintError
# --------------------------------------
# ---- Main Program --------------------
# --------------------------------------
if (__name__ == '__main__'):
Cmd = basename(argv[0]).split('.')[0]
CmdDesc = 'Report System Time'
Version = '2.01'
VersionDate = 'Tue Sep 15 21:02:11 CDT 2015'
DevState = 'Production'
Banner = CmdDesc + ': Release ' + Version + ' ' + DevState + '. Last updated: ' + VersionDate
Sql = ''
SqlHeader = '/***** ' + CmdDesc.upper() + ' *****/'
ErrChk = False
ArgParser = OptionParser()
InStr = ''
ConnStr = ''
InstList = []
# For handling termination in stdout pipe; ex: when you run: oerrdump | head
signal(SIGPIPE, SIG_DFL)
# Check/setup the Oracle environment
if (not('ORACLE_SID' in list(environ.keys()))):
print('ORACLE_SID is required.')
exit(1)
else:
# Set the ORACLE_HOME just in case it isn't set already.
if (not('ORACLE_HOME' in list(environ.keys()))):
(OracleSid, OracleHome) = SetOracleEnv(environ['ORACLE_SID'])
ArgParser.add_option('-g', dest='Global', action='store_true', default=False, help="search gv$sysemtric (default is v$sysmetric)")
ArgParser.add_option('-i', dest='Instances', default='', type=str, help="WHERE inst_id IN (1,2,3,...)")
ArgParser.add_option('--s', dest='Show', action='store_true', default=False, help="print SQL query.")
ArgParser.add_option('--v', dest='ShowVer', action='store_true', default=False, help="print version info.")
# Parse command line arguments
Options, args = ArgParser.parse_args()
Global = Options.Global
Instances = Options.Instances
Show = Options.Show
ShowVer = Options.ShowVer
if (ShowVer == True):
print('\n%s' % Banner)
exit()
if(Instances != ''):
Global = True
InstList = Instances.split(',')
try:
if (version_info[0] >= 3):
InstList = list(map(int, InstList))
InstList = list(map(str, InstList))
else:
InstList = map(int, InstList)
InstList = map(str, InstList)
except:
print("Instance list must be in integer form, eg. -i 1,2,3,4")
exit(1)
if (Global == False ):
Sql = "set linesize 100\n"
Sql += "set echo off\n"
Sql += "column stat_name format a60 heading 'Stat Name'\n"
Sql += "column seconds format 999,999,999,999,999.99 heading 'Seconds'\n"
Sql += "column minutes format 999,999,999.99 heading 'Minutes'\n"
Sql += "\n"
Sql += " SELECT " + SqlHeader + "\n"
Sql += " LPAD(' ', 2*level-1)||stat_name stat_name\n"
Sql += " , ROUND(value/1000000,2) seconds\n"
Sql += " , ROUND(value/1000000/60,2) minutes\n"
Sql += " FROM (select 0 id, 9 pid, null stat_name, null value from dual\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'DB time',10) id\n"
Sql += " , DECODE(stat_name,'DB time',0) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'DB time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'DB CPU',20) id\n"
Sql += " , DECODE(stat_name,'DB CPU',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'DB CPU'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'connection management call elapsed time',21) id\n"
Sql += " , DECODE(stat_name,'connection management call elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'connection management call elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'sequence load elapsed time',22) id\n"
Sql += " , DECODE(stat_name,'sequence load elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'sequence load elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'sql execute elapsed time',23) id\n"
Sql += " , DECODE(stat_name,'sql execute elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'sql execute elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'parse time elapsed',24) id\n"
Sql += " , DECODE(stat_name,'parse time elapsed',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'parse time elapsed'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse elapsed time',30) id\n"
Sql += " , DECODE(stat_name,'hard parse elapsed time',24) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse (sharing criteria) elapsed time',40) id\n"
Sql += " , DECODE(stat_name,'hard parse (sharing criteria) elapsed time',30) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse (sharing criteria) elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse (bind mismatch) elapsed time',50) id\n"
Sql += " , DECODE(stat_name,'hard parse (bind mismatch) elapsed time',40) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse (bind mismatch) elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'failed parse elapsed time',31) id\n"
Sql += " , DECODE(stat_name,'failed parse elapsed time',24) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'failed parse elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'failed parse (out of shared memory) elapsed time',41) id\n"
Sql += " , DECODE(stat_name,'failed parse (out of shared memory) elapsed time',31) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'failed parse (out of shared memory) elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'PL/SQL execution elapsed time',25) id\n"
Sql += " , DECODE(stat_name,'PL/SQL execution elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'PL/SQL execution elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'inbound PL/SQL rpc elapsed time',26) id\n"
Sql += " , DECODE(stat_name,'inbound PL/SQL rpc elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'inbound PL/SQL rpc elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'PL/SQL compilation elapsed time',27) id\n"
Sql += " , DECODE(stat_name,'PL/SQL compilation elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'PL/SQL compilation elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'Java execution elapsed time',28) id\n"
Sql += " , DECODE(stat_name,'Java execution elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'Java execution elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'repeated bind elapsed time',29) id\n"
Sql += " , DECODE(stat_name,'repeated bind elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'repeated bind elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'background elapsed time',1) id\n"
Sql += " , DECODE(stat_name,'background elapsed time',0) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'background elapsed time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'background cpu time',2) id\n"
Sql += " , DECODE(stat_name,'background cpu time',1) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'background cpu time'\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'RMAN cpu time (backup/restore)',3) id\n"
Sql += " , DECODE(stat_name,'RMAN cpu time (backup/restore)',2) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM v$sys_time_model\n"
Sql += " WHERE stat_name = 'RMAN cpu time (backup/restore)'\n"
Sql += " )\n"
Sql += "CONNECT BY PRIOR id = pid START WITH id = 0;\n\n"
else:
if (InstList == []):
Sql = "set pages 0\n"
Sql += "SELECT inst_id FROM gv$sys_time_model GROUP BY inst_id ORDER BY 1;"
# Check/setup the Oracle environment
if (not('ORACLE_SID' in list(environ.keys()))):
print('ORACLE_SID is required.')
exit(1)
else:
# Set the ORACLE_HOME just in case it isn't set already.
if (not('ORACLE_HOME' in list(environ.keys()))):
(OracleSid, OracleHome) = SetOracleEnv(environ['ORACLE_SID'])
# Execute the Sql to get the inst_id's
# Parse the connect string if any, prompt for username, password if needed.
if (len(args) > 0):
InStr = args[0]
ConnStr = ParseConnectString(InStr)
Rc = 0
ErrStack = []
if (ConnStr != ''):
(Rc,Stdout,ErrList) = RunSqlplus(Sql, True, ConnStr)
else:
(Rc,Stdout,ErrList) = RunSqlplus(Sql, True)
Stdout.strip()
if (Rc == 0):
for line in Stdout.split('\n'):
InstList.append(line.strip())
else:
PrintError(Sql, Stdout, ErrList)
exit(1)
Sql = ""
for InstId in InstList:
Sql += "set linesize 100\n"
Sql += "set echo off\n"
Sql += "column stat_name format a60 heading 'Stat Name'\n"
Sql += "column seconds format 999,999,999,999,999.99 heading 'Seconds'\n"
Sql += "column minutes format 999,999,999.99 heading 'Minutes'\n"
Sql += "\n"
Sql += "prompt\n"
Sql += "prompt\n"
Sql += "prompt Instance: " + InstId + "\n"
Sql += "prompt\n"
Sql += " SELECT " + SqlHeader + "\n"
Sql += " LPAD(' ', 2*level-1)||stat_name stat_name\n"
Sql += " , ROUND(value/1000000,2) seconds\n"
Sql += " , ROUND(value/1000000/60,2) minutes\n"
Sql += " FROM (select 0 id, 9 pid, null stat_name, null value from dual\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'DB time',10) id\n"
Sql += " , DECODE(stat_name,'DB time',0) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'DB time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'DB CPU',20) id\n"
Sql += " , DECODE(stat_name,'DB CPU',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'DB CPU'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'connection management call elapsed time',21) id\n"
Sql += " , DECODE(stat_name,'connection management call elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'connection management call elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'sequence load elapsed time',22) id\n"
Sql += " , DECODE(stat_name,'sequence load elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'sequence load elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'sql execute elapsed time',23) id\n"
Sql += " , DECODE(stat_name,'sql execute elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'sql execute elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'parse time elapsed',24) id\n"
Sql += " , DECODE(stat_name,'parse time elapsed',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'parse time elapsed'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse elapsed time',30) id\n"
Sql += " , DECODE(stat_name,'hard parse elapsed time',24) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse (sharing criteria) elapsed time',40) id\n"
Sql += " , DECODE(stat_name,'hard parse (sharing criteria) elapsed time',30) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse (sharing criteria) elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'hard parse (bind mismatch) elapsed time',50) id\n"
Sql += " , DECODE(stat_name,'hard parse (bind mismatch) elapsed time',40) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'hard parse (bind mismatch) elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'failed parse elapsed time',31) id\n"
Sql += " , DECODE(stat_name,'failed parse elapsed time',24) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'failed parse elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'failed parse (out of shared memory) elapsed time',41) id\n"
Sql += " , DECODE(stat_name,'failed parse (out of shared memory) elapsed time',31) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'failed parse (out of shared memory) elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'PL/SQL execution elapsed time',25) id\n"
Sql += " , DECODE(stat_name,'PL/SQL execution elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'PL/SQL execution elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'inbound PL/SQL rpc elapsed time',26) id\n"
Sql += " , DECODE(stat_name,'inbound PL/SQL rpc elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'inbound PL/SQL rpc elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'PL/SQL compilation elapsed time',27) id\n"
Sql += " , DECODE(stat_name,'PL/SQL compilation elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'PL/SQL compilation elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'Java execution elapsed time',28) id\n"
Sql += " , DECODE(stat_name,'Java execution elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'Java execution elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'repeated bind elapsed time',29) id\n"
Sql += " , DECODE(stat_name,'repeated bind elapsed time',10) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'repeated bind elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'background elapsed time',1) id\n"
Sql += " , DECODE(stat_name,'background elapsed time',0) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'background elapsed time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'background cpu time',2) id\n"
Sql += " , DECODE(stat_name,'background cpu time',1) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'background cpu time'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " UNION\n"
Sql += " SELECT DECODE(stat_name,'RMAN cpu time (backup/restore)',3) id\n"
Sql += " , DECODE(stat_name,'RMAN cpu time (backup/restore)',2) pid\n"
Sql += " , stat_name\n"
Sql += " , value\n"
Sql += " FROM gv$sys_time_model\n"
Sql += " WHERE stat_name = 'RMAN cpu time (backup/restore)'\n"
Sql += " AND inst_id = " + InstId + "\n"
Sql += " )\n"
Sql += "CONNECT BY PRIOR id = pid START WITH id = 0;\n\n"
###~ # Old non-Heirarchial Report
###~ # -----------------------------
###~ Sql = "set pagesize 1000\n"
###~ Sql += "column inst_id format 9999 heading 'Inst'\n"
###~ Sql += "column stat_name format a60 heading 'Statistic'\n"
###~ Sql += "column value format 999,999,999,999,999,999.99 heading 'Seconds'\n"
###~ Sql += "break on inst_id\n"
###~ Sql += "\n"
###~ Sql += " SELECT " + SqlHeader + "\n"
###~ if (Global == True):
###~ Sql += " inst_id\n"
###~ Sql += " , stat_name\n"
###~ else:
###~ Sql += " stat_name\n"
###~ Sql += " , TRUNC(value/1000000,2) value\n"
###~ if (Global == True):
###~ Sql += " FROM gv$sys_time_model\n"
###~ else:
###~ Sql += " FROM v$sys_time_model\n"
###~ if (Name != '' or InstList != []):
###~ Sql += " WHERE 1=1\n"
###~ if (Name != ''):
###~ Sql += " AND upper(stat_name) LIKE upper('%" + Name + "%') \n"
###~ if (Global == True and InstList != []):
###~ Sql += " AND inst_id IN(" + Instances + ")\n"
###~ if (Global == True):
###~ Sql += "ORDER BY inst_id\n"
###~ Sql += " , value DESC;\n"
###~ else:
###~ Sql += "ORDER BY value DESC;\n"
Sql = Sql.strip()
if(Show):
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
print(Sql)
print('-----------cut-----------cut-----------cut-----------cut-----------cut-----------')
exit()
# Check/setup the Oracle environment
if (not('ORACLE_SID' in list(environ.keys()))):
print('ORACLE_SID is required.')
exit(1)
else:
# Set the ORACLE_HOME just in case it isn't set already.
if (not('ORACLE_HOME' in list(environ.keys()))):
(OracleSid, OracleHome) = SetOracleEnv(environ['ORACLE_SID'])
# Parse the connect string if any, prompt for username, password if needed.
if (len(args) > 0 and Show == False):
InStr = args[0]
ConnStr = ParseConnectString(InStr)
# Execute the report
if (ConnStr != ''):
(Stdout) = RunSqlplus(Sql, ErrChk, ConnStr)
else:
(Stdout) = RunSqlplus(Sql, ErrChk)
Stdout = '\n'.join(Stdout.split('\n\n')) # cheap fix for the funky '\n\n' between the report header and report body.
# Print the Report
if (Stdout != ''):
print('\n%s' % Stdout)
exit(0)
# --------------------------------------
# ---- End Main Program ----------------
# --------------------------------------