├── .gitattributes ├── .gitignore ├── README.md ├── TrcExtProf.sql ├── acl_preprocessing.stp ├── bitops2.sql ├── cpu_profiler.sh ├── db_link_password_decrypt.sql ├── db_link_password_decrypt_standalone.sql ├── dbgdChkEventIntV_event_list.txt ├── dbgdChkEventIntV_event_list_extended.txt ├── dbgdChkEventIntV_event_list_extended19c.txt ├── event_extractor.sh ├── eventsname.sql ├── extract_func_info.sh ├── func_offset.stp ├── hugepage_usage_ins.sh ├── jira_model_classif_inference.py ├── jira_model_classif_train.py ├── kernel_io_outlier_simul.stp ├── latch_callgraph.stp ├── latch_callgraph2.stp ├── latch_callgraph3.stp ├── latch_monitor.c ├── latchname.sql ├── line_tracker.stp ├── load_sql_patch.sql ├── mini_db_firewall.stp ├── monitor_latch.stp ├── new_proc_sus.stp ├── oracle_function_to_event_mapping18c.sed ├── oracle_function_to_event_mapping18c.txt ├── oracle_function_to_event_mapping19c.sed ├── oracle_function_to_event_mapping19c.txt ├── plsql_memory_leak.sh ├── plsql_obj.sql ├── plsql_profiler.sh ├── plsql_tracer.stp ├── schedtimes_wsi.stp ├── socktop_wsi.sh ├── sql_resolver.sh ├── sql_resolver2.sh ├── stapora.stp ├── trace_mem_alloc.stp ├── trace_mem_alloc_resov.sh ├── trace_plsql_func_args.sh ├── where_why_decode.sql └── write_consistency.stp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # For informations on the scripts listed here please visit my blog : https://mahmoudhatem.wordpress.com/ 2 | -------------------------------------------------------------------------------- /acl_preprocessing.stp: -------------------------------------------------------------------------------- 1 | probe process("oracle").function("skudmio_prep") { 2 | 3 | if ( user_string(register("rdx")) == "/tmp/execute_me.sh" ) { 4 | printf("Access granted %s\n",user_string(register("rdx"))); 5 | } else { 6 | printf("Access denied %s\n",user_string(register("rdx"))); 7 | replace_string(register("rdx"),"/deny"); 8 | } 9 | } 10 | 11 | function replace_string(old_text:long,new_text:string) %{ 12 | char *oldtext; 13 | char *newtext; 14 | oldtext = (char *) STAP_ARG_old_text; 15 | newtext = (char *) STAP_ARG_new_text; 16 | strcpy(oldtext,newtext); 17 | %} 18 | -------------------------------------------------------------------------------- /bitops2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * Script from http://www.jlcomp.demon.co.uk/faq/bitwise.html 3 | * Author's name: Connor McDonald 4 | */ 5 | 6 | 7 | CREATE OR REPLACE package bitops2 is 8 | 9 | function bitand(p_dec1 number, p_dec2 number) return varchar2 ; 10 | function bitor(p_dec1 number, p_dec2 number) return varchar2 ; 11 | function bitxor(p_dec1 number, p_dec2 number) return varchar2 ; 12 | 13 | end; 14 | / 15 | 16 | 17 | CREATE OR REPLACE package body bitops2 is 18 | 19 | function raw_ascii(p_dec number) return raw is 20 | v_result varchar2(1999); 21 | v_tmp1 number := p_dec; 22 | begin 23 | loop 24 | v_result := chr(mod(v_tmp1,256)) || v_result ; 25 | v_tmp1 := trunc(v_tmp1/256); 26 | exit when v_tmp1 = 0; 27 | end loop; 28 | return utl_raw.cast_to_raw(v_result); 29 | end; 30 | 31 | function ascii_raw(p_raw varchar2) return number is 32 | v_result number := 0; 33 | begin 34 | for i in 1 .. length(p_raw) loop 35 | v_result := v_result * 256 + ascii(substr(p_raw,i,1)); 36 | end loop; 37 | return v_result; 38 | end; 39 | 40 | function bitand(p_dec1 number, p_dec2 number) return varchar2 is 41 | begin 42 | return 43 | ascii_raw( 44 | utl_raw.cast_to_varchar2( 45 | utl_raw.bit_and( 46 | raw_ascii(p_dec1), 47 | raw_ascii(p_dec2) 48 | ) 49 | ) 50 | ); 51 | end; 52 | 53 | function bitor(p_dec1 number, p_dec2 number) return varchar2 is 54 | begin 55 | return 56 | ascii_raw( 57 | utl_raw.cast_to_varchar2( 58 | utl_raw.bit_or( 59 | raw_ascii(p_dec1), 60 | raw_ascii(p_dec2) 61 | ) 62 | ) 63 | ); 64 | end; 65 | 66 | function bitxor(p_dec1 number, p_dec2 number) return varchar2 is 67 | begin 68 | return 69 | ascii_raw( 70 | utl_raw.cast_to_varchar2( 71 | utl_raw.bit_xor( 72 | raw_ascii(p_dec1), 73 | raw_ascii(p_dec2) 74 | ) 75 | ) 76 | ); 77 | end; 78 | 79 | end; 80 | / 81 | -------------------------------------------------------------------------------- /cpu_profiler.sh: -------------------------------------------------------------------------------- 1 | # This script generate extended off_cpu,on_cpu,Hot/Cold flamegaph for a specific Oracle session 2 | # Author : Hatem Mahmoud 3 | # BLOG : https://mahmoudhatem.wordpress.com 4 | # 5 | # Example : cpu_profiler.sh PID SAMPLE_TIME_SEC 6 | # 7 | # Run eventsname.sql and place the output file eventsname.sed in the current directory 8 | # Update the folowing variable before running the script 9 | # 10 | 11 | oracle_path=/oracle11/install/bin/oracle 12 | flamegraph_base=/home/oracle/scripts/FlameGraph-master 13 | 14 | 15 | echo "**********************" 16 | echo "Begin data collection for " $2 " Seconds" 17 | echo "Target process " $1 18 | echo "**********************" 19 | 20 | 21 | rm -f wait.data* 22 | rm -f wait_* 23 | rm -f on_perf.data* 24 | rm -f off_perf.data* 25 | rm -f all_perf.data* 26 | 27 | perf probe -x $oracle_path kskthbwt event=%dx 28 | perf probe -x $oracle_path kskthewt event=%si 29 | perf record -e probe_oracle:kskthbwt -e probe_oracle:kskthewt -o wait.data.raw -p $1 sleep $2 & 30 | perf record -F 999 -g -o on_perf.data0 -p $1 sleep $2 & 31 | perf record -e sched:sched_stat_sleep -e sched:sched_switch -e sched:sched_process_exit -g -o off_perf.data.raw -p $1 sleep $2 32 | 33 | 34 | echo "**********************" 35 | echo "Begin of data analysis" 36 | echo "**********************" 37 | 38 | 39 | #Wait event analysis 40 | 41 | perf script -i wait.data.raw > wait.data0 42 | 43 | wait_number=`wc -l wait.data0 | awk '{print $1}'` 44 | wait_begin=0 45 | wait_end=0 46 | wait_event=0 47 | wait_line_nb=1 48 | wait_end=0 49 | 50 | #Formating Wait event trace as "wait_begin wait_end wait_event#" 51 | 52 | while test $wait_number -gt $wait_line_nb 53 | do 54 | if [[ $wait_line_nb == 1 && `sed -n "$wait_line_nb"p wait.data0` == *"kskthewt"* ]] 55 | then 56 | wait_line_nb=$(($wait_line_nb+1)) 57 | fi 58 | wait_begin=`sed -n "$wait_line_nb"p wait.data0 | awk '{split($4,array,".") ; print array[1] substr(array[2],1,length(array[2])-1)}'` 59 | wait_event=`sed -n "$wait_line_nb"p wait.data0 | awk '{print $7}'` 60 | wait_line_nb=$(($wait_line_nb+1)) 61 | wait_end=`sed -n "$wait_line_nb"p wait.data0 | awk '{split($4,array,".") ; print array[1] substr(array[2],1,length(array[2])-1)}'` 62 | wait_line_nb=$(($wait_line_nb+1)) 63 | echo $wait_begin" "$wait_end" "$wait_event >> wait_list.txt 64 | done 65 | 66 | #Off cpu analysis 67 | 68 | echo "---" 69 | echo "Generating Off cpu flamegraph" 70 | echo "---" 71 | 72 | perf inject -v -s -i off_perf.data.raw -o off_perf.data0 73 | perf script -F comm,pid,tid,cpu,time,period,event,ip,sym,dso,trace -i off_perf.data0 > off_perf.data1 74 | 75 | wait_line_nb=-1 76 | 77 | while read -r line 78 | do 79 | if [[ $line == "oracle"* ]] 80 | then 81 | stack_timestamp=`echo "$line" | awk '{split($4,array,".") ; print array[1] substr(array[2],1,length(array[2])-1)}'` 82 | echo "$line" >> off_perf.data2 83 | 84 | wait_event="On_cpu(oracle)" 85 | 86 | while read -r wait_line 87 | do 88 | wait_line_nb=`echo $wait_line | awk '{print $1}'` 89 | w_b=`echo $wait_line | awk '{print $2}'` 90 | w_e=`echo $wait_line | awk '{print $3}'` 91 | w_n=`echo $wait_line | awk '{print $4}'` 92 | if [[ $stack_timestamp -ge $w_b && $stack_timestamp -le $w_e ]] 93 | then 94 | wait_event=$w_n 95 | break 96 | elif [[ $stack_timestamp -lt $w_e ]] 97 | then 98 | break 99 | fi 100 | 101 | done <= var { print $0}') 103 | EOF 104 | 105 | elif [[ -z $line ]] 106 | then 107 | echo "xxxxxxxxxx Off_cpu(system)()" >> off_perf.data2 108 | echo "xxxxxxxxxx "$wait_event "()">> off_perf.data2 109 | echo $line >> off_perf.data2 110 | else 111 | echo $line >> off_perf.data2 112 | fi 113 | done < off_perf.data1 114 | 115 | 116 | 117 | nb_cpu=`lscpu -p=cpu | grep -v "#" | wc -l` 118 | cat off_perf.data2 | awk -v var=$nb_cpu ' NF > 4 { exec = $1; period_ms = int($5 / 1000000 / var) } NF > 1 && NF <= 4 && period_ms > 0 { print $2 } NF < 2 && period_ms > 0 { printf "%s\n%d\n\n", exec, period_ms }' | $flamegraph_base/stackcollapse.pl | sed -f eventsname.sed > off_perf.data3 119 | cat off_perf.data3| $flamegraph_base/flamegraph.pl --countname=ms --title="Off-CPU Time Flame Graph" --colors=io > offcpu.svg 120 | 121 | #On cpu analysis 122 | 123 | echo "---" 124 | echo "Generating On cpu flamegraph" 125 | echo "---" 126 | 127 | perf script -i on_perf.data0 > on_perf.data1 128 | 129 | wait_line_nb=-1 130 | 131 | while read -r line 132 | do 133 | if [[ $line == "oracle"* ]] 134 | then 135 | stack_timestamp=`echo "$line" | awk '{split($3,array,".") ; print array[1] substr(array[2],1,length(array[2])-1)}'` 136 | echo "$line" >> on_perf.data2 137 | 138 | wait_event="On_cpu(oracle) ()" 139 | while read -r wait_line 140 | do 141 | wait_line_nb=`echo $wait_line | awk '{print $1}'` 142 | w_b=`echo $wait_line | awk '{print $2}'` 143 | w_e=`echo $wait_line | awk '{print $3}'` 144 | w_n=`echo $wait_line | awk '{print $4}'` 145 | 146 | if [[ $stack_timestamp -ge $w_b && $stack_timestamp -le $w_e ]] 147 | then 148 | wait_event=$w_n 149 | break 150 | elif [[ $stack_timestamp -lt $w_e ]] 151 | then 152 | break 153 | fi 154 | 155 | done <= var { print $0}') 157 | EOF 158 | 159 | elif [[ -z $line ]] 160 | then 161 | echo "xxxxxxxxxx On_cpu(system) ()" >> on_perf.data2 162 | echo "xxxxxxxxxx "$wait_event" ()" >> on_perf.data2 163 | echo $line >> on_perf.data2 164 | else 165 | echo $line >> on_perf.data2 166 | fi 167 | done < on_perf.data1 168 | 169 | 170 | cat on_perf.data2 | $flamegraph_base/stackcollapse-perf.pl | sed -f eventsname.sed > on_perf.data3 171 | cat on_perf.data3 | $flamegraph_base/flamegraph.pl --title="On-CPU Time Flame Graph" > oncpu.svg 172 | 173 | 174 | 175 | #On Cpu /Off cpu Mixed flame graph 176 | echo "---" 177 | echo "Generating Mixed cpu flamegraph" 178 | echo "---" 179 | 180 | cat off_perf.data3 > all_perf.data 181 | cat on_perf.data3 >> all_perf.data 182 | cat all_perf.data | $flamegraph_base/flamegraph.pl --countname=ms --title="Mixed-CPU Time Flame Graph" > allcpu.svg 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /db_link_password_decrypt.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE PROCEDURE db_link_password_decrypt ( 2 | NO_USERID_VERIFIER_SALT VARCHAR2, 3 | password_link VARCHAR2) 4 | AS 5 | /* 6 | * Author : Hatem Mahmoud 7 | * BLOG : https://mahmoudhatem.wordpress.com 8 | * 9 | * Contributor : 10 | * Adric Norris (landstander668) : Strip decrypted password to plaintext portion 11 | * Adric Norris (landstander668) : Allow script to be run using SQL*Plus 12 | * 13 | * 14 | * Decrypting database Link password 15 | * Tested in oracle 12.1.0.2.6/12.2.0.1 16 | * Parameters : 17 | * NO_USERID_VERIFIER_SALT from sys.props$ 18 | * PASSWORDX from sys.link$ 19 | */ 20 | ztcshpl_v6 VARCHAR2 (32767); 21 | ztcshpl_v6_offset NUMBER; 22 | password_link_offset NUMBER; 23 | encryption_key_part_1 VARCHAR2 (64); 24 | encryption_key_part_2 VARCHAR2 (64); 25 | encryption_key VARCHAR2 (128); 26 | Ciphertext VARCHAR2 (64); 27 | initialization_vector VARCHAR2 (32); 28 | decrypted_raw RAW (1000); 29 | output_string VARCHAR2 (2000); 30 | encryption_type PLS_INTEGER 31 | := -- total encryption type 32 | DBMS_CRYPTO.ENCRYPT_AES256 33 | + DBMS_CRYPTO.CHAIN_CBC 34 | + DBMS_CRYPTO.PAD_NONE; 35 | BEGIN 36 | password_link_offset := 3; 37 | ztcshpl_v6 := 38 | '000200010600000000000202020000000102030000020002000102020202000002000000000000000400000102010002030200000201010001000100010000030100010002010300040002000001000202010101000000000000000101000001030000010000010201010100000202010200020000000004000000000500010102010000000000020001000200000001020200000200050201020004030300030101030101000000010000000001010000000101010000020103000000000103030104000100000001000000000302000000000200000002020100010000000001010000030001020200010200000001010201050002010100020103000200010000010000010100010203010001000000010000000000000100000000020001000701010000010202060000000002000003000b01000200010100000400000100010001010001030000000000000003010100000101030004030000010100000100000003000004000101000300010001010702000202000200000401000000000301000100000001020000000000020000000001000003000100010000010002060207000000040000010000000006010001000301010003010100000000030001000401010000000101020001020001000304000100010001000002010004000101000002000100000202010500000004000001000100000001010400000100010101000202000101000000010301000001010100000000010100020000010000000001020002000403000000010202000301000403020101000000010501010000000100010001000203010202010002000101050002000101020000030000030001000100000100020000000103000101020100040300020000000000000000020100000100010200010100000001010000000001000100020303030000000100030004010202000001010100030204000100020100020100010100010302000200000102000200040002010101040000000100000000010001000500020104020200000000020000000001010000000000020003000202020100000102000101010000030200000200000000040000000402000001010002000000020501010100020200020000000004050002000000010100000002010201010000000201010200000000000200050000060000040200010000010201030000000002010201000000000000010201000000050203000002000000030100000100000201000000020201000100010001000000000303000000000000000002020001020402020001000300010103040100020003000200000201010001000201010001000000000100000000010303010005000600030200020001000100000000000200010' || 39 | '000010200010200000004000000010200070000030100010001000000010000010200030002010100000001020100010000000101010101020400020000000200030002010502030002030100010100000000010100010001000100020100000100000000020000020300000000040100010002000003000001000000020003010101010003000000000000000702010103010300000202000200000102030301000401000000010201010100000301000000000200000000030001000100040000000008000000010101000103030000010102000002000001000100010001000000000201000000000000010203000100010600000102010001030200000100000000040200010102000102000400000202000200010103010201000101030005010002000201010400000000000100000002030100030100020200020200000100000000030100010100000102000000020001010000010000040400000101000202020003000000000000000100020104000002000200040301010100000002000000000103050000030300010100020102000000010003000001000000000001000001000200000002000000010002010105010001000000010501030001000104010000030001000002000100020200030100010003000202000401000000060000020000010600000000020000000200020202000200040101000000000005030802000000000000010000000002000000000100010000000101020000040004020004000100000000000001010000030000000000010103010001000100010602010100030000000500040000020000000000000300000300000103000001000000000000000200020000020300020303000200000002000000000307010000000101000001000001000000010406000001010100030100010001010101010100030000010200010001000100000300010100010001010000020100010102020101010000010002030002030101000401040101000000000102000000030201010005000000000003010102020001000101000001000000040100000003010000000100010200000002000300000005020000000000010702010100010000000000020004020001000201000002000100000000000102010101000304000101010100040001010002000002000000000101030700010001010300000302020000020100040001000502010100010101000202010002030200020101000000000001000003010000000001000201000100000002010100000004000000030000000102010003000001000001000203000000020007010000000000000100000000030500000206010003030101000000000400000001000201010101000200' || 40 | '000100000104010001000003000000000200010501000003000000010003030201000002010000000101030002030000000304000200020000000001000000000000010000010200000201020101000200000000020202030203000300030000010001010005010001000304000000020101000000010002000300010102000000010500020000000400010100000101010100010001020101000202000001030001000401000001010000010000010100000502000001050000020002020002000000010001000001000409000001000301010200000002010200030000010300000002020100000002000100000000020101020001000300000001000300010202000200000400000001000203000200000401010000040000000000020400000400000000000200000001000300000101000000000200040500010202000000010300000001000100050600000100010302020001030001000300010000010001000000020100010002000102000000000201000002020400000201000001000100000000000200010100030000050100010000040101000401000003030301000000000001000202020001000100000200000002020102030101010000000100010000000500010000010201030403030002010000020000010202010000010100040001000000020101000002000000010002010600000000000000010001030300000003010100000200000100010200020303000101010200000000000102000100030301010000000100010301010000030200030100020305000003000200000501000000030100010102000100000004000000010001020001000200000103000100000006010000040002010000010000010000010002020000010201030005030101000201010100040002000001000001010002010001000200000004000000020301000100000000050100000301000000000000020100000002010000000200000000000000000000000201010004000000000a02010306010000010101000103000002010100020201010203010000000000000100010201000000000201070000040002010000010600000100000000010002010400020000010201010200000100010000000000020005000101000000000000010101020000010104010200000000010101010000000102000100000100010101010000000001070004000100000001000004020200000004060300000000010005030106000101000101000002000002010001000201000001000000020001030101000200010001000004000001000101000101000102000103000000040000000000000103000001050302000201000001000000000000000001000001000001030100000' || 41 | '402020004010001030102070000000200030003000001000002000001010000020001000000000000000301020302030101020101000101020000000203040201010101000301000100020001000102000000000000010003050000010200000001010201010001010201000004000303000001010100010001040002000002000003010100000204020000000100010102000001000000000204050001010000000000010000000000000000000600000003010001010300000002020200010100020000000200050006000100000000010001000003010000000000000000000001000000000002000102000200010103020600000000010000000500020001000003020001020302010100020100010400000001000105000001000203000300000401000004000101000000020000030000000000000100010006010100000002010000000300000200010101030000010100000305030001000100020000020100000001000201000002000103000202010000000004010103000000010101000000000403000007060100000100000001000100010201000102000000020003000101020001020900020100020101010100000202010200000100010000010000000000000300000202020200010002000000010201020003010000010001010000010100000300000200010201000200010001020002000000060001000201040000010100000201040700000101000100010000000000000100010101000004000500000000010000010101020002020100000600000000020001000002020101020103040002000101000102000003000200010000010100000000000501010001000000000101000001000000000502000000030000000000000000020000010005010102090300010201010102010000010005000201020000000000060101000100020003000000010001010100000702010001000000010100000100010002000404000301010000000002030100000002000100000003010001000100010001020000000001000002020000000001010304000000010100010001040002040500000100000001010001020004020005000000000001010001010003000100000001000102010000000100000000000200030001000202020300000501010100000201010001000002000101000202020800020100020005020000000101000700020200000002000200020100030200000000010000000205000000020000000000000001020100020000010102010003000000010100000101050002020102000100000101040003000100010300000000000003000002000000000100000200010002000000040200000200020500030000010001030000000001' || 42 | '000000050000020103010000000004000000000300000004020201000003040001040101000200020300010202000001000000000100000102000000020101010006010000000201000102000005000002000301020000010500000100010200020000000000020100020004000003000002000200000000030100010001000100010105050500020000000100000000000000020000000000020100010103010700000002000201020100000001000100020102000200020000000000030001030102000001000001010000000203000001000100000001000201020100000002030000000401000806000000000301000003010001000000000105000201000102000101000000000300000007010201000000000102040000010101030001000001000007010100000100030000000401000000000002000200020001020100000000000100000105050001000000030101030201000000000002080000030201010000010000020001000000010102000001010102000001000101020300000002000000010102000000000001010300010003000001010100010000080402000003030000000202000200000101000101020100010103000000020001000100000100000001020001000000000200000000000302040101000200010000030002010101020001010106000106000300000001020001000301000100000500010002010000040000000000000100000103050001000000020101000400000100000001010200010000020c01000002000001000000020001000001000000000100010001000206000000000002000001000203010103000200000300000101020300020401000001020500000105000000000000010103000001000100020000010000010102000300040200000000010000000001010102010304000000000201000004020100020100000101000100000004050200000000000201010000000004040300000000030201000000060000010101000001010000000000070200050101000001000001010004000100000100010200000200030101030200000104020300010001020002030000000003000200010201020001000400020000000000000000000002010000000000030000020000020001000300010104030004000300000101000101030101020000000000000200010002000000000001030303010000000001000101000200000003010202000004000106040001020000050005020000010002000003000000000001000000000002010001000000020000000000020001010004000100070000010000000200000003010101010201000700000200010001010003000000000003000301000300000100000100010203000' || 43 | '001010002030001000101000101000000010500010300000102010001000101000201000200010109000000000200000001000000010200000001000200010002010303020200020000030100000302000100000000000000000000000000050000010203000003000300000001010102000000000205000001030002020101000101000100000200030100010200000201010100010003000c01010000000101000002000101010001010102040000030000010001000200020102000100000000010102000103000000010001000100020002010502000001000100010000000000010202020000020200000003000502010001020000020000010001010004010100010000000000050102010100000002000002000001000100030000000300000000000002000001050101030300040001030001000102000001000002010302000200010102010300000000000202000100010100010200010103000000010002010002000002030101000203000001000100000102000101000400000800040100000100000101000100020000010003000000010100010000000002000000000100000400030402020002000003010004020009010100000100010200030100000004000000000100020100010100000000000000000100030003000701000001000100000102010001030101010001000102020301000000000101030001020100010200010002000001020103000100000001000003010100000001000100000100000008000003010100030000020001000001030104000000020003000000020000040200010200000004020000010001000001000101010102000000040001000001010000000300050301010201000000030002020000000002010004000200000300020000000500030000000201000101010000050101000002000100040101000103000100010000000001000005000200010100000002010101020200000004030000000100000100040200000101000002010200070000000300000000010000010001010200000101000200020000000000040200020100000301020000010100000000010501000009010003010400050000020001020000020200010002020103000000020003000000000100000100010001000101000008020001000001020000000000010101000000000100000200000301030103000000030001010400000101000100010100030200020000000502010300010000000201010007000000000100000101010001010100020000010002000001000202000000010205020001010000010000010002020600000100000001010000010300000103000100010301010400000102020100000000000000000001020100' || 44 | '010102000100020100020201000100010000010202000100010301010101010000030201000503010202010000000101010004000202030001020000000100000001020002060000030003040101010002000000000001000400000000020100000000000005000000000001020001000103020100000000000003000200040000000204010100000001000202000000010100010001030002000300010102010000020105010100010000000000060000010000010002020100040300010100000003000104010000040000010001000403000000010005010000010001000400030000000001000000010103000101000000000100010100030001000000020500010000000004040203010200000000030008000000000000000105040000000000010000000100010201030100000001020000000200000201020100000002010601020100000103010102000101010200010000000200010001010000050002000000020101000102000200000201010001010002000100030001000001000000000100040003000900010000020500000000020100030100040101000100040000000001000001000100010102000003050001020201000002020002000201000601000100000000010105020000000100000100010000000100000200000000010000000002000004010800000000000101000003030001060001040000000000000001020006010001020001000103000101020001010000000000010001000003010300020403000000000000010004000100000100000005010101010300000300000001000000000500010001010201010105010001020000040000010001000001000001000001000301020001000101000100000100000000010001020103000100030301010001000301020001000107020101010200030201000100030004000000000000010001010001030002010005020000060300000100000500010000000000010100000000000000010102000001000000010300020001030401000001000101020100000100000301000001000101010001000100000201000001010205020301020002020200000006030000000001000002040102010200000000000102000000010000000000000000030201010100000201000000010101000001050201000001000101000000030100010302000100010002000003020001020000060200000003000000020201020403010001000000000204000000000000020100050000010200000200000000010000010203040102000200000000010000000100000100000303000000010002010101000202010001010001000002020100000001020001040000020000000100000100000005000702010' || 45 | '000000000030000060102020000020500000000000000000000000001030500010001000300010000020100000400020100010100030200000002010001000100020001000105000001000000050200020100010001000001020000030001000000010000020400000000040401010000000000010000000001060000010200000005010301000002000100030201000101020300020100010200020002000200000001020100000008000000030101000004020000000000000200060000020101000000020000000000040000000001000002000100000000000001000101020001010000000003030300040000010009020000000200010105000002000002000000000101000203010002000101000300020000010000030002010001010202000002020000000201020001000100000000000104060100000300010002000001000500000103000100010001010102030100010000010000000000050001000201000100010100020000000001000104020001020200000201010003000100000602000301010000000103000000000003020000000400010201010001010000000305000004000001030300010105000001000000000002010200020000010202000101010001010100000100000302000200030200000000010001020200000102000200000201000403030100010400000000020300010000000000030001010000020100010200000000030000000201000003030103000100000302010004010000000100000300010100010100000000000003010000020400000000030001000007010000010200010000020300010000020000020201010201000400010301000500000200010100020002020101020100010000000202000100010102010201000100000100000001000000000302030000000102030101010000010103010002000000000200000000010100030003000102060000010003010201000000000200050100000100000204000006000301010001000300000101000002000102000000000000000100010103010200000004000100030000040000020000010000000001030500010100000103000200010300000007010100020000000201000000000000000102010100010001050100000000030002010000020002030000000300020002010307030200000002010000000100000101000101000100010200000001000202000300010000000200000200000304000301010001000103000000000000030302000102000000000000010006020303010100000201000202010001010002000000050106000002000000010201020000000100000200010000000000000105000101010001020302040303010101000000030000' || 46 | '000000010101000003000000000002000000010100030200000001010100010004010001010100010202010200010000020302010100000100010000000002000100010101030002030200000102010400010100010001010001010301010400030001000002000100000000010001010001010001000003000102020200000002020001030100040102000302010000020001010400000000000201000101000100000000000403000001020200000204000000020400010201040003000100000300000301010000010205000001000105000002000100000100010000000200000000000000000402000000010004020201000002010000020000000002000001000101000003020001020000000200020100000001020001000000000002010100020005020205030001040000000001000101000300030001040003010100000400010002000100010100020001000001000000000300000100000103010002000100020000000002080001000002010101000002000100000000000100000103000400000001000102020100020003000400020300000003010000020100000000020002040101000102000303000000000000020002010102000201020000000002000200000007000200020002080000000000010100030200000000010000000000010200000302000202000000000400000101020202010000000100010000020000030200000100000002000001020000020101000100020004030004000002010201000000030100000300000000010100010200000100060000020100000200000100030000000000000101010001000001030500020600060001000000000201010100040003010002000200000000010000010200020003010000030100010200000006000001020301000302000200010000010100000300000001010003010001000000020005010000000000010600020100010002080002000000030000000000000000000003020102020100010100000102000101020000000000010102020001000300020000010003000001000400010100000101000000010201000100030202000002010001000000060000010100010102000003000204010000000303000001000003000003000000000502000201000100000102000203000103000101040100000000020002010100000102040000000000010101020000020101000201000300000001000701030301000002000102030000000102010000010400000000000300000101040001030101000000000000000202030300000000000001000200010203000000000000000000000302010201000400030000000000010100010603010000000000000001000002000000000001000' || 47 | '106000201000201000802010000000100000000020001020005000000000105040001010000000000050000010501020003000100000300010000010000040000010102040000000100000301010101030002000000050003010000010100000001000000020000000100020301030000000101010000010002020102030000000002000102010101000004000200000000000501040200040000000400020000010001000000010000010000010006000000010100000300020300000100030001020201010200000000000001000400000100000000000001000201020002000000000000010102000103020302010200040001000100010003020301000001010003010000000105010300000100000001000001000001000001030001000001000000020004000206000101020005010000000000000001050300020002000404000001000200000001000001020204000001010102020000020102010100040200000000000100040001010000000101000000010002050000000100000200000100000203000100010000010000010004010000010004010104000100000201000000010000030004010004000400000100020000010000010201000000010000090100000300000200010000000101040101010200000003040101000000000100000001000006020200010000030101020200010000000100020001010006000200000100020100000200000802000101000001000200000101010002000101070000020000000100000001010103010100030003000000010001000000030200000000010001000201010000030100000302000100000001000101000001010000000001000007050003010000000200020002020002000001000100000000020307000000000000000500010000000100000101020001000400030000010000010304000000000501010101010100000201020204010000000200000000010103000002000002040001000000010000000201000000030000050104010000010000000100000102010004000203000202020000010001020002010000000001000501000100010001010100040504010000030100000201000502000000000000010001000003000000000000000300010001010000000000010002020403000000020104000000000101000102010001010000040200010000000002020101030102040000010002010000000002030001020002030004000000000001000100010004020000000301020000000000000000020402010201000000010600000001010200000300010100010300010201010001020102000005000002000000000202010005000000000101020000000201010102010000000000010100' || 48 | '000105000000000000010100010100040001010400000106030100030000000202010301000000000100070000020002010300000002000000000000000100010201030203030101000000000101020101000400000100000100020002000002000401000201000000000002010000010000000001010304020100020000010102000000050003000201000200020000000001010100000000010001020205020002000201010302010000000000020100000000000000000001000102000002000103030103000000000302010301010001030000000202000001000205020400020000000300040100030000000202010303000101020002000000040000000001020300000000010500020100000200000000000000000400020103000100000003000101000000010202000001010100010202010000010000000101000202030100000002000202000001020200030005000000000000010300000202010102020100020000010000010000020201000201000001000000000100000001050001000101000100040201010101000100050300020103000002010203000000010001000201000000000000040002010001020001000101000000000000000100060002020200030200000100010101010002000101000500010001000200010603010002000002020000000000010001020100030001030101000100000103020000010000010002000003000100010001010201000004020001000103010103000500010000000000030101040000020102000008000000030100030000000100030000030201030000000201000000000003000100000000000000030001000201010500010001000001000204000000010300000001010300030001000001010000030201000100030000000201000207000102020000000001020100000102000003000000000103010300000200000402000000000101020000000400000000010103020000020005000000020001000202010103000100040100000002020100000100000001000101020100010200000202000900020000000000010100000202020000000201020501010001000002020100000100000000010001000105000200000001020102010000020305010000010100010000000400010001020203030000000000000002010000020000000200000200000100020000050000010202000100000000010001010001010302030000000000000000000207020000040101010001010100000100040001000100000000020200000401000000010400010300000000010000000001000000000000000009000100000000000000010001010204000001020100000204000100000000000101070300030600020' || 49 | '002010201000004000101030101000200010100020000000000010202020303040000010302030000000200000100020000000001000501000000020001000200000100010400000001000200000102000000000301000002010000000001010000040000000101000100010604000002000002020101000404000200000001010005000001030102000200010000000205000200010002000000000104000101020102000201010100020000030001000101000200000200000101010000020102000200010001000002000000000204020000000100010200010100020000010000000702000100020004000200030004000001020100010005000301010000000000010001040003010002030001010001000100000002000003010000000300000000020000000005010004030101010000000000010000000201000001030000010500000100010001000100010000000100000101000204020000030001000001020001000000010002000401020000000004030202020101000000070400000200010000020100040100000101010300000104010002000401000000000006010000000000020102030000030101000002010000000000020003000104000100000101000001020200000201010002000001000000000101050000020100000c00000000010200000000000001000000020103000100000002000000050002040002000100070203010102050200000101000001010000010000000201000000000004000201010100010202000001010000000003000000000101030001020000010001020001040200010401010001000003010001000704000101000100010000000100020301000001000201000201000101000100000000000201000001020200020000000203000301010002000000030203000000000300000400000100010000000001010000000000010001000101010100020100030104010601010101000000010101000001000100010102000101010101000206000002000000020200000200040502020101000200000300000200010001010200000001000000000001000201010000030000000400010200010101000102000100000301010000020403000102000101010100000002020000020007000000020300000001000000010000000001010103010002010400010401000002000000000002000101010100010100010000000100010002070301020100010100020202000000000300000201030006010101020200010000010001040200000203010002030000000101000000020000000201000003020003000002000000000101000101010000000100010003020101000001010000010000010002000000000001010103' || 50 | '000000010204010100010300000201020201000004000104030001000004020001000100010000000700040001000300010200000000000003000100000005040003000200000000000300000102000000000101000000030200010000010402020102030007010000010001010002020000000000010000010000010102040002000001000001030000000000010103010001000001020006020000000000000001020101010001000000010000010400000400000100000400060002000003020000000000060600030000000401010001000000000200010100000000000100010001020002000100000002000203000001000200010207010000010002000100000000020000010000000100030201010600010002010302000101000003000001000000000500000000010301020004000000010000030100050000010000000000000004000002040100030000020100000103000201000002010002000302050003000003000000010001000200000000010000030000000004020100010302030100000205010000000002020002010100000101030000000000010301000102010003010201000401020102000101000000010200020200020101010000000002010002020104000102010000000101030000020000000100000002000001000100010100020101000100000000020100000301020002010400000002000201000205020000000000010104020001010000030002000001010201000201010000050101020001010400000103000500000002000101000003000100050002030000000000020004000001000001000002000101000001010100000002020600000001010300000100000001010000020100010003000003020000000002000101030103000200030101040103000000000101000100030000000000020004000002000101000104000100050100000000020000000004030003000201000000000200010000000201030000060000000000040000000002000201010000000002000201000000000101040004000101030100000100010000030000000100010003010303000101020100030200000000010101000205000101000000020000020102010102010000010000010000000500030002000100000301000100000001000102010005020001010001020000000001020201010001000500000100000801020007020000000100000005010000010000000200000201000000010000020105000402000000010100010300000000000004000101000100010000000000040000000103000000010300000000000100010402020202010000000100020101020000000101040200000100000101000001020101000000030404000' || 51 | '00001010000030000000501010100000401010002030101000002000001010200010000010003030001000300000003000000010101020005020000000002000101000200000200000001010100010003010008010300000000000101020000010100030000030103010000000206010502000000000000000101000100000001000000010000010002000000000002010100010200000300010002010000000000000200010003000000010001000200010000010000040009000001060402000000010000000002010000000004020100010000010000030000040000040000000100000200050500010100010000060101050101000000000005010000000000000102030000000100000200000004020001000100020000000300020001010100000200000200000100020303000002020300000c000100010000010000000200010101000000030000000000010000000000080002000100000102010100040000040100030000020200010000010101000001000102010403010201000400000201000000010300000401040000010000020004000001040400000000000001000201000100010101000000010003010200000101000003000001030000010000020000000401000302000200030100000201020100000002010200000301000000000201010000010100020000040001010301020001000200000101050101060300020001000000000000000001030300030302000001000001000300000100010004000001010000000202030300000100000000000000010300000200040001000200010000010001010400000001000003000500040000010000060100000000000102020000000100040300010004020000010200000000000100010100000100020102000204000100010200000000010101010100000000070105010100000201020202000000000600000000000001000002010002020100040200010302000100000001030001020001010202000000030001000400010000000000030000020000010001000100010502000001000000030101020201000000050003010000010001010000000100000100000000010002010302040002000001020402000002020000000000030000000300000003010300000302000104000306020000010000020000000000000602010000000000030003000004010200000001000001010101000000000100020202000001010100000400010100020000000104000201010100000201000000000102050000010106000002000000000400010201000000010000010205000000000000010200000000010000000101000001020001000100020000000000000004000001010000020200020000010200' || 52 | '0001020000000100030203000103050000010101040201010000040002010205010002000000010000000004000002000000030101010400010000050000030300000100010100010003000000020000010100000102000000000000040001030001000007000500000200020201000500000000000200010100000202000201000000020001000201030001040000020000000100000200000000010101010100000200010000010102010200000001000002060004000000020003000101000000030100010300010000000001010101010101000004000001020300000000000102000000000600000100000202000000020100060001020201010301010000010300000300010302000101000001010101010000000201000300000001000100010003020001010102020004020303000000000000010400040003010000000101000401000100000201000101010000000403000000000100000000000100000c0002000103010002030301000100030000000100030100000201020001020100010100010000000000000100000201010000000101000101020000010002000200000000010202000301020000000001010001000004020000010000000500000402000101000103000002010000020105020001010000020002010001000201000001010001010000000201010100000400020000010200010200020000000300010201070100000200020400000003000100030000010100010001010900000001000201000200000202000003000000000002010200020000000100040100020100020003000100020102010000000100000103000200010201000602000101000100030002000202000401000100000001000200000104040002000201000000000201000100000100020002010000000001020202000100000001000002000000000000050103000002000102030001070000000000000001000000010303000100000000000402010200020101020500000101010000020101000000050001000002000100010000000301000200020100000001030001020001000100010102040201010201010100000002000200000101000106000101020102010101010100000102040001000000010000010001000202000000000202000104000100030002020001010002000100000400000202030200000000010300020501000400000000000000010300000002000203000101020101020001000100000000010000000000050102000000010000000100030400000001050002000201010001010000010202000001010000010001040201010001010301010100020000040201000000000000020001020000000202040101010002000107000003000' || 53 | '400000200010000000000000104000302010600000000000100030101000000000000010000000101010000020100010002000002010600000001000201000006000100000100010003010201000001000104000000000000040000020101000000000002010107040101010000000100030001010101000000020002010403000300000100000000010000010004000102010103000000000101000200030000010001000002010201000001020001000000010600000002060002020100000000000000030002020100030401000001000003000103000000000101000000000303010000000100000100000101010106000300000000070000000100000103010002000201000100010000000004000304020000000103000006000000010100000101010200000101010100010401000101000200010100020000040000000102020000010100000000000001000307020001010107010000000001000001020000000000000300000002000100050100010000050100010100000100000100050001020102010100010300000000020102000103050103000001010001000400000102010200010000000001000100000102020000010003000001030001000102000000000300000202000200010100030302000000010001010000000000000600000101010004070002000001000200020000000300020000010002000001010102000000000201000001000101000102000002030004030200000100000001030100000401000200000100000202040202010102010003010103010001000001020201010101010202000003000000000001000001000102000000000500040100010400000101000002020002010004000200000000000101010200050000000005020000010100000101020100010103030000000300000002010101020100000101000103000200000000010001020103000300000201000001000001020101020001010200000000040002010001000001010000000100000000000200000107010200010001010502000100010401020200010002000000000402000001000200010600020100000000000002010200000106000400000001000102010101010000040102000002000000030001000300000100000400000002000101000600030004000203000102000000000100060000010100000001010200010102000001010003040100000100000000010000020100000001000100000100050000000004040500020101000000010101010002010200000000000302020203030100000101000000000000000102000200000000010300010000010003000402000001000101030001050101000400010002000000010000010202000300' || 54 | '000005020101040000000003000101000001000000010100000102000100000402010000010000020000000003000200040401040000000103000001060200000301010100000000000001010000000300000000010101010104000100020200000000030101010100000000000001020102010204010201030000000100000000000102000000020103000400010100020001010300010100010201010001000003020000000000000101040100000200000003050100010100020200010202010300010302000000000000040001010101000000000002020100000000000007000300000201000002000001000001010000000002000000000203020100050004000000030202000101000000000000030000010405000002020000010301000200000200010003000200010001000001000001000000050100000102000000050001000100000104010003010300010001000201030201000301000700000303000402000201000000000100000000000200060101010001000100000000010000000100000102000002010202010102000100010200020103000300010000010002020002010003000000050100000000000203010000000301000100020300000004030200020001000'; 55 | 56 | encryption_key_part_2 := 57 | DBMS_CRYPTO.hash (src => NO_USERID_VERIFIER_SALT, 58 | typ => DBMS_CRYPTO.HASH_SH256); 59 | 60 | FOR i IN 0 .. 63 61 | LOOP 62 | --Logical shift shl in assembly 63 | ztcshpl_v6_offset := 64 | (TO_NUMBER (SUBSTR (password_link, 3, 2), 'xx') * POWER (2, 6)) 65 | * 2 66 | + 1 67 | + i * 2; 68 | 69 | IF (initialization_vector IS NULL) 70 | THEN 71 | initialization_vector := SUBSTR (ztcshpl_v6, ztcshpl_v6_offset, 32); 72 | END IF; 73 | 74 | password_link_offset := 75 | password_link_offset 76 | + TO_NUMBER (SUBSTR (ztcshpl_v6, ztcshpl_v6_offset, 2), 'xx') * 2 77 | + 2; 78 | 79 | IF (i < 32) 80 | THEN 81 | encryption_key_part_1 := 82 | encryption_key_part_1 83 | || SUBSTR (password_link, password_link_offset, 2); 84 | ELSE 85 | Ciphertext := 86 | Ciphertext || SUBSTR (password_link, password_link_offset, 2); 87 | END IF; 88 | END LOOP; 89 | 90 | 91 | encryption_key :=utl_raw.bit_xor(encryption_key_part_1,encryption_key_part_2); 92 | 93 | 94 | decrypted_raw := 95 | DBMS_CRYPTO.DECRYPT (src => Ciphertext, 96 | typ => encryption_type, 97 | key => encryption_key, 98 | iv => initialization_vector); 99 | output_string := UTL_I18N.RAW_TO_CHAR ( utl_raw.substr( decrypted_raw, 2, 100 | to_number( rawtohex( utl_raw.substr( decrypted_raw, 1, 1 ) ), 'XX' ) 101 | ) 102 | ); 103 | 104 | 105 | 106 | DBMS_OUTPUT.put_line ( 107 | '----------Decrypting DB Link password--------------'); 108 | DBMS_OUTPUT.put_line ('Initialization_vector :'); 109 | DBMS_OUTPUT.put_line (initialization_vector); 110 | DBMS_OUTPUT.put_line ( 111 | '---------------------------------------------------'); 112 | DBMS_OUTPUT.put_line ('Ciphertext :'); 113 | DBMS_OUTPUT.put_line (Ciphertext); 114 | DBMS_OUTPUT.put_line ( 115 | '---------------------------------------------------'); 116 | DBMS_OUTPUT.put_line ('Encryption key part 1 :'); 117 | DBMS_OUTPUT.put_line (encryption_key_part_1); 118 | DBMS_OUTPUT.put_line ('Encryption key part 2 :'); 119 | DBMS_OUTPUT.put_line (encryption_key_part_2); 120 | DBMS_OUTPUT.put_line ( 121 | '---------------------------------------------------'); 122 | DBMS_OUTPUT.put_line ('Encryption key (Part 1 XOR Part 2) : '); 123 | DBMS_OUTPUT.put_line (encryption_key); 124 | DBMS_OUTPUT.put_line ( 125 | '---------------------------------------------------'); 126 | DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string); 127 | DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || decrypted_raw); 128 | END; 129 | / 130 | -------------------------------------------------------------------------------- /db_link_password_decrypt_standalone.sql: -------------------------------------------------------------------------------- 1 | set define "&" serveroutput on size unlimited format wrapped 2 | 3 | declare 4 | v_salt varchar2(100); 5 | v_enc_passwd varchar2(1000); 6 | 7 | PROCEDURE db_link_password_decrypt ( 8 | NO_USERID_VERIFIER_SALT VARCHAR2, 9 | password_link VARCHAR2) 10 | AS 11 | /* 12 | * Author : Hatem Mahmoud 13 | * BLOG : https://mahmoudhatem.wordpress.com 14 | * 15 | * Contributor : 16 | * Adric Norris (landstander668) : Strip decrypted password to plaintext portion 17 | * Adric Norris (landstander668) : Allow script to be run using SQL*Plus 18 | * 19 | * 20 | * Decrypting database Link password 21 | * Tested in oracle 12.1.0.2.6/12.2.0.1 22 | * Parameters : 23 | * NO_USERID_VERIFIER_SALT from sys.props$ 24 | * PASSWORDX from sys.link$ 25 | */ 26 | ztcshpl_v6 VARCHAR2 (32767); 27 | ztcshpl_v6_offset NUMBER; 28 | password_link_offset NUMBER; 29 | encryption_key_part_1 VARCHAR2 (64); 30 | encryption_key_part_2 VARCHAR2 (64); 31 | encryption_key VARCHAR2 (128); 32 | Ciphertext VARCHAR2 (64); 33 | initialization_vector VARCHAR2 (32); 34 | decrypted_raw RAW (1000); 35 | output_string VARCHAR2 (2000); 36 | encryption_type PLS_INTEGER 37 | := -- total encryption type 38 | DBMS_CRYPTO.ENCRYPT_AES256 39 | + DBMS_CRYPTO.CHAIN_CBC 40 | + DBMS_CRYPTO.PAD_NONE; 41 | BEGIN 42 | password_link_offset := 3; 43 | ztcshpl_v6 := 44 | '000200010600000000000202020000000102030000020002000102020202000002000000000000000400000102010002030200000201010001000100010000030100010002010300040002000001000202010101000000000000000101000001030000010000010201010100000202010200020000000004000000000500010102010000000000020001000200000001020200000200050201020004030300030101030101000000010000000001010000000101010000020103000000000103030104000100000001000000000302000000000200000002020100010000000001010000030001020200010200000001010201050002010100020103000200010000010000010100010203010001000000010000000000000100000000020001000701010000010202060000000002000003000b01000200010100000400000100010001010001030000000000000003010100000101030004030000010100000100000003000004000101000300010001010702000202000200000401000000000301000100000001020000000000020000000001000003000100010000010002060207000000040000010000000006010001000301010003010100000000030001000401010000000101020001020001000304000100010001000002010004000101000002000100000202010500000004000001000100000001010400000100010101000202000101000000010301000001010100000000010100020000010000000001020002000403000000010202000301000403020101000000010501010000000100010001000203010202010002000101050002000101020000030000030001000100000100020000000103000101020100040300020000000000000000020100000100010200010100000001010000000001000100020303030000000100030004010202000001010100030204000100020100020100010100010302000200000102000200040002010101040000000100000000010001000500020104020200000000020000000001010000000000020003000202020100000102000101010000030200000200000000040000000402000001010002000000020501010100020200020000000004050002000000010100000002010201010000000201010200000000000200050000060000040200010000010201030000000002010201000000000000010201000000050203000002000000030100000100000201000000020201000100010001000000000303000000000000000002020001020402020001000300010103040100020003000200000201010001000201010001000000000100000000010303010005000600030200020001000100000000000200010' || 45 | '000010200010200000004000000010200070000030100010001000000010000010200030002010100000001020100010000000101010101020400020000000200030002010502030002030100010100000000010100010001000100020100000100000000020000020300000000040100010002000003000001000000020003010101010003000000000000000702010103010300000202000200000102030301000401000000010201010100000301000000000200000000030001000100040000000008000000010101000103030000010102000002000001000100010001000000000201000000000000010203000100010600000102010001030200000100000000040200010102000102000400000202000200010103010201000101030005010002000201010400000000000100000002030100030100020200020200000100000000030100010100000102000000020001010000010000040400000101000202020003000000000000000100020104000002000200040301010100000002000000000103050000030300010100020102000000010003000001000000000001000001000200000002000000010002010105010001000000010501030001000104010000030001000002000100020200030100010003000202000401000000060000020000010600000000020000000200020202000200040101000000000005030802000000000000010000000002000000000100010000000101020000040004020004000100000000000001010000030000000000010103010001000100010602010100030000000500040000020000000000000300000300000103000001000000000000000200020000020300020303000200000002000000000307010000000101000001000001000000010406000001010100030100010001010101010100030000010200010001000100000300010100010001010000020100010102020101010000010002030002030101000401040101000000000102000000030201010005000000000003010102020001000101000001000000040100000003010000000100010200000002000300000005020000000000010702010100010000000000020004020001000201000002000100000000000102010101000304000101010100040001010002000002000000000101030700010001010300000302020000020100040001000502010100010101000202010002030200020101000000000001000003010000000001000201000100000002010100000004000000030000000102010003000001000001000203000000020007010000000000000100000000030500000206010003030101000000000400000001000201010101000200' || 46 | '000100000104010001000003000000000200010501000003000000010003030201000002010000000101030002030000000304000200020000000001000000000000010000010200000201020101000200000000020202030203000300030000010001010005010001000304000000020101000000010002000300010102000000010500020000000400010100000101010100010001020101000202000001030001000401000001010000010000010100000502000001050000020002020002000000010001000001000409000001000301010200000002010200030000010300000002020100000002000100000000020101020001000300000001000300010202000200000400000001000203000200000401010000040000000000020400000400000000000200000001000300000101000000000200040500010202000000010300000001000100050600000100010302020001030001000300010000010001000000020100010002000102000000000201000002020400000201000001000100000000000200010100030000050100010000040101000401000003030301000000000001000202020001000100000200000002020102030101010000000100010000000500010000010201030403030002010000020000010202010000010100040001000000020101000002000000010002010600000000000000010001030300000003010100000200000100010200020303000101010200000000000102000100030301010000000100010301010000030200030100020305000003000200000501000000030100010102000100000004000000010001020001000200000103000100000006010000040002010000010000010000010002020000010201030005030101000201010100040002000001000001010002010001000200000004000000020301000100000000050100000301000000000000020100000002010000000200000000000000000000000201010004000000000a02010306010000010101000103000002010100020201010203010000000000000100010201000000000201070000040002010000010600000100000000010002010400020000010201010200000100010000000000020005000101000000000000010101020000010104010200000000010101010000000102000100000100010101010000000001070004000100000001000004020200000004060300000000010005030106000101000101000002000002010001000201000001000000020001030101000200010001000004000001000101000101000102000103000000040000000000000103000001050302000201000001000000000000000001000001000001030100000' || 47 | '402020004010001030102070000000200030003000001000002000001010000020001000000000000000301020302030101020101000101020000000203040201010101000301000100020001000102000000000000010003050000010200000001010201010001010201000004000303000001010100010001040002000002000003010100000204020000000100010102000001000000000204050001010000000000010000000000000000000600000003010001010300000002020200010100020000000200050006000100000000010001000003010000000000000000000001000000000002000102000200010103020600000000010000000500020001000003020001020302010100020100010400000001000105000001000203000300000401000004000101000000020000030000000000000100010006010100000002010000000300000200010101030000010100000305030001000100020000020100000001000201000002000103000202010000000004010103000000010101000000000403000007060100000100000001000100010201000102000000020003000101020001020900020100020101010100000202010200000100010000010000000000000300000202020200010002000000010201020003010000010001010000010100000300000200010201000200010001020002000000060001000201040000010100000201040700000101000100010000000000000100010101000004000500000000010000010101020002020100000600000000020001000002020101020103040002000101000102000003000200010000010100000000000501010001000000000101000001000000000502000000030000000000000000020000010005010102090300010201010102010000010005000201020000000000060101000100020003000000010001010100000702010001000000010100000100010002000404000301010000000002030100000002000100000003010001000100010001020000000001000002020000000001010304000000010100010001040002040500000100000001010001020004020005000000000001010001010003000100000001000102010000000100000000000200030001000202020300000501010100000201010001000002000101000202020800020100020005020000000101000700020200000002000200020100030200000000010000000205000000020000000000000001020100020000010102010003000000010100000101050002020102000100000101040003000100010300000000000003000002000000000100000200010002000000040200000200020500030000010001030000000001' || 48 | '000000050000020103010000000004000000000300000004020201000003040001040101000200020300010202000001000000000100000102000000020101010006010000000201000102000005000002000301020000010500000100010200020000000000020100020004000003000002000200000000030100010001000100010105050500020000000100000000000000020000000000020100010103010700000002000201020100000001000100020102000200020000000000030001030102000001000001010000000203000001000100000001000201020100000002030000000401000806000000000301000003010001000000000105000201000102000101000000000300000007010201000000000102040000010101030001000001000007010100000100030000000401000000000002000200020001020100000000000100000105050001000000030101030201000000000002080000030201010000010000020001000000010102000001010102000001000101020300000002000000010102000000000001010300010003000001010100010000080402000003030000000202000200000101000101020100010103000000020001000100000100000001020001000000000200000000000302040101000200010000030002010101020001010106000106000300000001020001000301000100000500010002010000040000000000000100000103050001000000020101000400000100000001010200010000020c01000002000001000000020001000001000000000100010001000206000000000002000001000203010103000200000300000101020300020401000001020500000105000000000000010103000001000100020000010000010102000300040200000000010000000001010102010304000000000201000004020100020100000101000100000004050200000000000201010000000004040300000000030201000000060000010101000001010000000000070200050101000001000001010004000100000100010200000200030101030200000104020300010001020002030000000003000200010201020001000400020000000000000000000002010000000000030000020000020001000300010104030004000300000101000101030101020000000000000200010002000000000001030303010000000001000101000200000003010202000004000106040001020000050005020000010002000003000000000001000000000002010001000000020000000000020001010004000100070000010000000200000003010101010201000700000200010001010003000000000003000301000300000100000100010203000' || 49 | '001010002030001000101000101000000010500010300000102010001000101000201000200010109000000000200000001000000010200000001000200010002010303020200020000030100000302000100000000000000000000000000050000010203000003000300000001010102000000000205000001030002020101000101000100000200030100010200000201010100010003000c01010000000101000002000101010001010102040000030000010001000200020102000100000000010102000103000000010001000100020002010502000001000100010000000000010202020000020200000003000502010001020000020000010001010004010100010000000000050102010100000002000002000001000100030000000300000000000002000001050101030300040001030001000102000001000002010302000200010102010300000000000202000100010100010200010103000000010002010002000002030101000203000001000100000102000101000400000800040100000100000101000100020000010003000000010100010000000002000000000100000400030402020002000003010004020009010100000100010200030100000004000000000100020100010100000000000000000100030003000701000001000100000102010001030101010001000102020301000000000101030001020100010200010002000001020103000100000001000003010100000001000100000100000008000003010100030000020001000001030104000000020003000000020000040200010200000004020000010001000001000101010102000000040001000001010000000300050301010201000000030002020000000002010004000200000300020000000500030000000201000101010000050101000002000100040101000103000100010000000001000005000200010100000002010101020200000004030000000100000100040200000101000002010200070000000300000000010000010001010200000101000200020000000000040200020100000301020000010100000000010501000009010003010400050000020001020000020200010002020103000000020003000000000100000100010001000101000008020001000001020000000000010101000000000100000200000301030103000000030001010400000101000100010100030200020000000502010300010000000201010007000000000100000101010001010100020000010002000001000202000000010205020001010000010000010002020600000100000001010000010300000103000100010301010400000102020100000000000000000001020100' || 50 | '010102000100020100020201000100010000010202000100010301010101010000030201000503010202010000000101010004000202030001020000000100000001020002060000030003040101010002000000000001000400000000020100000000000005000000000001020001000103020100000000000003000200040000000204010100000001000202000000010100010001030002000300010102010000020105010100010000000000060000010000010002020100040300010100000003000104010000040000010001000403000000010005010000010001000400030000000001000000010103000101000000000100010100030001000000020500010000000004040203010200000000030008000000000000000105040000000000010000000100010201030100000001020000000200000201020100000002010601020100000103010102000101010200010000000200010001010000050002000000020101000102000200000201010001010002000100030001000001000000000100040003000900010000020500000000020100030100040101000100040000000001000001000100010102000003050001020201000002020002000201000601000100000000010105020000000100000100010000000100000200000000010000000002000004010800000000000101000003030001060001040000000000000001020006010001020001000103000101020001010000000000010001000003010300020403000000000000010004000100000100000005010101010300000300000001000000000500010001010201010105010001020000040000010001000001000001000001000301020001000101000100000100000000010001020103000100030301010001000301020001000107020101010200030201000100030004000000000000010001010001030002010005020000060300000100000500010000000000010100000000000000010102000001000000010300020001030401000001000101020100000100000301000001000101010001000100000201000001010205020301020002020200000006030000000001000002040102010200000000000102000000010000000000000000030201010100000201000000010101000001050201000001000101000000030100010302000100010002000003020001020000060200000003000000020201020403010001000000000204000000000000020100050000010200000200000000010000010203040102000200000000010000000100000100000303000000010002010101000202010001010001000002020100000001020001040000020000000100000100000005000702010' || 51 | '000000000030000060102020000020500000000000000000000000001030500010001000300010000020100000400020100010100030200000002010001000100020001000105000001000000050200020100010001000001020000030001000000010000020400000000040401010000000000010000000001060000010200000005010301000002000100030201000101020300020100010200020002000200000001020100000008000000030101000004020000000000000200060000020101000000020000000000040000000001000002000100000000000001000101020001010000000003030300040000010009020000000200010105000002000002000000000101000203010002000101000300020000010000030002010001010202000002020000000201020001000100000000000104060100000300010002000001000500000103000100010001010102030100010000010000000000050001000201000100010100020000000001000104020001020200000201010003000100000602000301010000000103000000000003020000000400010201010001010000000305000004000001030300010105000001000000000002010200020000010202000101010001010100000100000302000200030200000000010001020200000102000200000201000403030100010400000000020300010000000000030001010000020100010200000000030000000201000003030103000100000302010004010000000100000300010100010100000000000003010000020400000000030001000007010000010200010000020300010000020000020201010201000400010301000500000200010100020002020101020100010000000202000100010102010201000100000100000001000000000302030000000102030101010000010103010002000000000200000000010100030003000102060000010003010201000000000200050100000100000204000006000301010001000300000101000002000102000000000000000100010103010200000004000100030000040000020000010000000001030500010100000103000200010300000007010100020000000201000000000000000102010100010001050100000000030002010000020002030000000300020002010307030200000002010000000100000101000101000100010200000001000202000300010000000200000200000304000301010001000103000000000000030302000102000000000000010006020303010100000201000202010001010002000000050106000002000000010201020000000100000200010000000000000105000101010001020302040303010101000000030000' || 52 | '000000010101000003000000000002000000010100030200000001010100010004010001010100010202010200010000020302010100000100010000000002000100010101030002030200000102010400010100010001010001010301010400030001000002000100000000010001010001010001000003000102020200000002020001030100040102000302010000020001010400000000000201000101000100000000000403000001020200000204000000020400010201040003000100000300000301010000010205000001000105000002000100000100010000000200000000000000000402000000010004020201000002010000020000000002000001000101000003020001020000000200020100000001020001000000000002010100020005020205030001040000000001000101000300030001040003010100000400010002000100010100020001000001000000000300000100000103010002000100020000000002080001000002010101000002000100000000000100000103000400000001000102020100020003000400020300000003010000020100000000020002040101000102000303000000000000020002010102000201020000000002000200000007000200020002080000000000010100030200000000010000000000010200000302000202000000000400000101020202010000000100010000020000030200000100000002000001020000020101000100020004030004000002010201000000030100000300000000010100010200000100060000020100000200000100030000000000000101010001000001030500020600060001000000000201010100040003010002000200000000010000010200020003010000030100010200000006000001020301000302000200010000010100000300000001010003010001000000020005010000000000010600020100010002080002000000030000000000000000000003020102020100010100000102000101020000000000010102020001000300020000010003000001000400010100000101000000010201000100030202000002010001000000060000010100010102000003000204010000000303000001000003000003000000000502000201000100000102000203000103000101040100000000020002010100000102040000000000010101020000020101000201000300000001000701030301000002000102030000000102010000010400000000000300000101040001030101000000000000000202030300000000000001000200010203000000000000000000000302010201000400030000000000010100010603010000000000000001000002000000000001000' || 53 | '106000201000201000802010000000100000000020001020005000000000105040001010000000000050000010501020003000100000300010000010000040000010102040000000100000301010101030002000000050003010000010100000001000000020000000100020301030000000101010000010002020102030000000002000102010101000004000200000000000501040200040000000400020000010001000000010000010000010006000000010100000300020300000100030001020201010200000000000001000400000100000000000001000201020002000000000000010102000103020302010200040001000100010003020301000001010003010000000105010300000100000001000001000001000001030001000001000000020004000206000101020005010000000000000001050300020002000404000001000200000001000001020204000001010102020000020102010100040200000000000100040001010000000101000000010002050000000100000200000100000203000100010000010000010004010000010004010104000100000201000000010000030004010004000400000100020000010000010201000000010000090100000300000200010000000101040101010200000003040101000000000100000001000006020200010000030101020200010000000100020001010006000200000100020100000200000802000101000001000200000101010002000101070000020000000100000001010103010100030003000000010001000000030200000000010001000201010000030100000302000100000001000101000001010000000001000007050003010000000200020002020002000001000100000000020307000000000000000500010000000100000101020001000400030000010000010304000000000501010101010100000201020204010000000200000000010103000002000002040001000000010000000201000000030000050104010000010000000100000102010004000203000202020000010001020002010000000001000501000100010001010100040504010000030100000201000502000000000000010001000003000000000000000300010001010000000000010002020403000000020104000000000101000102010001010000040200010000000002020101030102040000010002010000000002030001020002030004000000000001000100010004020000000301020000000000000000020402010201000000010600000001010200000300010100010300010201010001020102000005000002000000000202010005000000000101020000000201010102010000000000010100' || 54 | '000105000000000000010100010100040001010400000106030100030000000202010301000000000100070000020002010300000002000000000000000100010201030203030101000000000101020101000400000100000100020002000002000401000201000000000002010000010000000001010304020100020000010102000000050003000201000200020000000001010100000000010001020205020002000201010302010000000000020100000000000000000001000102000002000103030103000000000302010301010001030000000202000001000205020400020000000300040100030000000202010303000101020002000000040000000001020300000000010500020100000200000000000000000400020103000100000003000101000000010202000001010100010202010000010000000101000202030100000002000202000001020200030005000000000000010300000202010102020100020000010000010000020201000201000001000000000100000001050001000101000100040201010101000100050300020103000002010203000000010001000201000000000000040002010001020001000101000000000000000100060002020200030200000100010101010002000101000500010001000200010603010002000002020000000000010001020100030001030101000100000103020000010000010002000003000100010001010201000004020001000103010103000500010000000000030101040000020102000008000000030100030000000100030000030201030000000201000000000003000100000000000000030001000201010500010001000001000204000000010300000001010300030001000001010000030201000100030000000201000207000102020000000001020100000102000003000000000103010300000200000402000000000101020000000400000000010103020000020005000000020001000202010103000100040100000002020100000100000001000101020100010200000202000900020000000000010100000202020000000201020501010001000002020100000100000000010001000105000200000001020102010000020305010000010100010000000400010001020203030000000000000002010000020000000200000200000100020000050000010202000100000000010001010001010302030000000000000000000207020000040101010001010100000100040001000100000000020200000401000000010400010300000000010000000001000000000000000009000100000000000000010001010204000001020100000204000100000000000101070300030600020' || 55 | '002010201000004000101030101000200010100020000000000010202020303040000010302030000000200000100020000000001000501000000020001000200000100010400000001000200000102000000000301000002010000000001010000040000000101000100010604000002000002020101000404000200000001010005000001030102000200010000000205000200010002000000000104000101020102000201010100020000030001000101000200000200000101010000020102000200010001000002000000000204020000000100010200010100020000010000000702000100020004000200030004000001020100010005000301010000000000010001040003010002030001010001000100000002000003010000000300000000020000000005010004030101010000000000010000000201000001030000010500000100010001000100010000000100000101000204020000030001000001020001000000010002000401020000000004030202020101000000070400000200010000020100040100000101010300000104010002000401000000000006010000000000020102030000030101000002010000000000020003000104000100000101000001020200000201010002000001000000000101050000020100000c00000000010200000000000001000000020103000100000002000000050002040002000100070203010102050200000101000001010000010000000201000000000004000201010100010202000001010000000003000000000101030001020000010001020001040200010401010001000003010001000704000101000100010000000100020301000001000201000201000101000100000000000201000001020200020000000203000301010002000000030203000000000300000400000100010000000001010000000000010001000101010100020100030104010601010101000000010101000001000100010102000101010101000206000002000000020200000200040502020101000200000300000200010001010200000001000000000001000201010000030000000400010200010101000102000100000301010000020403000102000101010100000002020000020007000000020300000001000000010000000001010103010002010400010401000002000000000002000101010100010100010000000100010002070301020100010100020202000000000300000201030006010101020200010000010001040200000203010002030000000101000000020000000201000003020003000002000000000101000101010000000100010003020101000001010000010000010002000000000001010103' || 56 | '000000010204010100010300000201020201000004000104030001000004020001000100010000000700040001000300010200000000000003000100000005040003000200000000000300000102000000000101000000030200010000010402020102030007010000010001010002020000000000010000010000010102040002000001000001030000000000010103010001000001020006020000000000000001020101010001000000010000010400000400000100000400060002000003020000000000060600030000000401010001000000000200010100000000000100010001020002000100000002000203000001000200010207010000010002000100000000020000010000000100030201010600010002010302000101000003000001000000000500000000010301020004000000010000030100050000010000000000000004000002040100030000020100000103000201000002010002000302050003000003000000010001000200000000010000030000000004020100010302030100000205010000000002020002010100000101030000000000010301000102010003010201000401020102000101000000010200020200020101010000000002010002020104000102010000000101030000020000000100000002000001000100010100020101000100000000020100000301020002010400000002000201000205020000000000010104020001010000030002000001010201000201010000050101020001010400000103000500000002000101000003000100050002030000000000020004000001000001000002000101000001010100000002020600000001010300000100000001010000020100010003000003020000000002000101030103000200030101040103000000000101000100030000000000020004000002000101000104000100050100000000020000000004030003000201000000000200010000000201030000060000000000040000000002000201010000000002000201000000000101040004000101030100000100010000030000000100010003010303000101020100030200000000010101000205000101000000020000020102010102010000010000010000000500030002000100000301000100000001000102010005020001010001020000000001020201010001000500000100000801020007020000000100000005010000010000000200000201000000010000020105000402000000010100010300000000000004000101000100010000000000040000000103000000010300000000000100010402020202010000000100020101020000000101040200000100000101000001020101000000030404000' || 57 | '00001010000030000000501010100000401010002030101000002000001010200010000010003030001000300000003000000010101020005020000000002000101000200000200000001010100010003010008010300000000000101020000010100030000030103010000000206010502000000000000000101000100000001000000010000010002000000000002010100010200000300010002010000000000000200010003000000010001000200010000010000040009000001060402000000010000000002010000000004020100010000010000030000040000040000000100000200050500010100010000060101050101000000000005010000000000000102030000000100000200000004020001000100020000000300020001010100000200000200000100020303000002020300000c000100010000010000000200010101000000030000000000010000000000080002000100000102010100040000040100030000020200010000010101000001000102010403010201000400000201000000010300000401040000010000020004000001040400000000000001000201000100010101000000010003010200000101000003000001030000010000020000000401000302000200030100000201020100000002010200000301000000000201010000010100020000040001010301020001000200000101050101060300020001000000000000000001030300030302000001000001000300000100010004000001010000000202030300000100000000000000010300000200040001000200010000010001010400000001000003000500040000010000060100000000000102020000000100040300010004020000010200000000000100010100000100020102000204000100010200000000010101010100000000070105010100000201020202000000000600000000000001000002010002020100040200010302000100000001030001020001010202000000030001000400010000000000030000020000010001000100010502000001000000030101020201000000050003010000010001010000000100000100000000010002010302040002000001020402000002020000000000030000000300000003010300000302000104000306020000010000020000000000000602010000000000030003000004010200000001000001010101000000000100020202000001010100000400010100020000000104000201010100000201000000000102050000010106000002000000000400010201000000010000010205000000000000010200000000010000000101000001020001000100020000000000000004000001010000020200020000010200' || 58 | '0001020000000100030203000103050000010101040201010000040002010205010002000000010000000004000002000000030101010400010000050000030300000100010100010003000000020000010100000102000000000000040001030001000007000500000200020201000500000000000200010100000202000201000000020001000201030001040000020000000100000200000000010101010100000200010000010102010200000001000002060004000000020003000101000000030100010300010000000001010101010101000004000001020300000000000102000000000600000100000202000000020100060001020201010301010000010300000300010302000101000001010101010000000201000300000001000100010003020001010102020004020303000000000000010400040003010000000101000401000100000201000101010000000403000000000100000000000100000c0002000103010002030301000100030000000100030100000201020001020100010100010000000000000100000201010000000101000101020000010002000200000000010202000301020000000001010001000004020000010000000500000402000101000103000002010000020105020001010000020002010001000201000001010001010000000201010100000400020000010200010200020000000300010201070100000200020400000003000100030000010100010001010900000001000201000200000202000003000000000002010200020000000100040100020100020003000100020102010000000100000103000200010201000602000101000100030002000202000401000100000001000200000104040002000201000000000201000100000100020002010000000001020202000100000001000002000000000000050103000002000102030001070000000000000001000000010303000100000000000402010200020101020500000101010000020101000000050001000002000100010000000301000200020100000001030001020001000100010102040201010201010100000002000200000101000106000101020102010101010100000102040001000000010000010001000202000000000202000104000100030002020001010002000100000400000202030200000000010300020501000400000000000000010300000002000203000101020101020001000100000000010000000000050102000000010000000100030400000001050002000201010001010000010202000001010000010001040201010001010301010100020000040201000000000000020001020000000202040101010002000107000003000' || 59 | '400000200010000000000000104000302010600000000000100030101000000000000010000000101010000020100010002000002010600000001000201000006000100000100010003010201000001000104000000000000040000020101000000000002010107040101010000000100030001010101000000020002010403000300000100000000010000010004000102010103000000000101000200030000010001000002010201000001020001000000010600000002060002020100000000000000030002020100030401000001000003000103000000000101000000000303010000000100000100000101010106000300000000070000000100000103010002000201000100010000000004000304020000000103000006000000010100000101010200000101010100010401000101000200010100020000040000000102020000010100000000000001000307020001010107010000000001000001020000000000000300000002000100050100010000050100010100000100000100050001020102010100010300000000020102000103050103000001010001000400000102010200010000000001000100000102020000010003000001030001000102000000000300000202000200010100030302000000010001010000000000000600000101010004070002000001000200020000000300020000010002000001010102000000000201000001000101000102000002030004030200000100000001030100000401000200000100000202040202010102010003010103010001000001020201010101010202000003000000000001000001000102000000000500040100010400000101000002020002010004000200000000000101010200050000000005020000010100000101020100010103030000000300000002010101020100000101000103000200000000010001020103000300000201000001000001020101020001010200000000040002010001000001010000000100000000000200000107010200010001010502000100010401020200010002000000000402000001000200010600020100000000000002010200000106000400000001000102010101010000040102000002000000030001000300000100000400000002000101000600030004000203000102000000000100060000010100000001010200010102000001010003040100000100000000010000020100000001000100000100050000000004040500020101000000010101010002010200000000000302020203030100000101000000000000000102000200000000010300010000010003000402000001000101030001050101000400010002000000010000010202000300' || 60 | '000005020101040000000003000101000001000000010100000102000100000402010000010000020000000003000200040401040000000103000001060200000301010100000000000001010000000300000000010101010104000100020200000000030101010100000000000001020102010204010201030000000100000000000102000000020103000400010100020001010300010100010201010001000003020000000000000101040100000200000003050100010100020200010202010300010302000000000000040001010101000000000002020100000000000007000300000201000002000001000001010000000002000000000203020100050004000000030202000101000000000000030000010405000002020000010301000200000200010003000200010001000001000001000000050100000102000000050001000100000104010003010300010001000201030201000301000700000303000402000201000000000100000000000200060101010001000100000000010000000100000102000002010202010102000100010200020103000300010000010002020002010003000000050100000000000203010000000301000100020300000004030200020001000'; 61 | 62 | encryption_key_part_2 := 63 | DBMS_CRYPTO.hash (src => NO_USERID_VERIFIER_SALT, 64 | typ => DBMS_CRYPTO.HASH_SH256); 65 | 66 | FOR i IN 0 .. 63 67 | LOOP 68 | --Logical shift shl in assembly 69 | ztcshpl_v6_offset := 70 | (TO_NUMBER (SUBSTR (password_link, 3, 2), 'xx') * POWER (2, 6)) 71 | * 2 72 | + 1 73 | + i * 2; 74 | 75 | IF (initialization_vector IS NULL) 76 | THEN 77 | initialization_vector := SUBSTR (ztcshpl_v6, ztcshpl_v6_offset, 32); 78 | END IF; 79 | 80 | password_link_offset := 81 | password_link_offset 82 | + TO_NUMBER (SUBSTR (ztcshpl_v6, ztcshpl_v6_offset, 2), 'xx') * 2 83 | + 2; 84 | 85 | IF (i < 32) 86 | THEN 87 | encryption_key_part_1 := 88 | encryption_key_part_1 89 | || SUBSTR (password_link, password_link_offset, 2); 90 | ELSE 91 | Ciphertext := 92 | Ciphertext || SUBSTR (password_link, password_link_offset, 2); 93 | END IF; 94 | END LOOP; 95 | 96 | 97 | encryption_key :=utl_raw.bit_xor(encryption_key_part_1,encryption_key_part_2); 98 | 99 | 100 | decrypted_raw := 101 | DBMS_CRYPTO.DECRYPT (src => Ciphertext, 102 | typ => encryption_type, 103 | key => encryption_key, 104 | iv => initialization_vector); 105 | output_string := UTL_I18N.RAW_TO_CHAR ( utl_raw.substr( decrypted_raw, 2, 106 | to_number( rawtohex( utl_raw.substr( decrypted_raw, 1, 1 ) ), 'XX' ) 107 | ) 108 | ); 109 | 110 | 111 | 112 | DBMS_OUTPUT.put_line ( 113 | '----------Decrypting DB Link password--------------'); 114 | DBMS_OUTPUT.put_line ('Initialization_vector :'); 115 | DBMS_OUTPUT.put_line (initialization_vector); 116 | DBMS_OUTPUT.put_line ( 117 | '---------------------------------------------------'); 118 | DBMS_OUTPUT.put_line ('Ciphertext :'); 119 | DBMS_OUTPUT.put_line (Ciphertext); 120 | DBMS_OUTPUT.put_line ( 121 | '---------------------------------------------------'); 122 | DBMS_OUTPUT.put_line ('Encryption key part 1 :'); 123 | DBMS_OUTPUT.put_line (encryption_key_part_1); 124 | DBMS_OUTPUT.put_line ('Encryption key part 2 :'); 125 | DBMS_OUTPUT.put_line (encryption_key_part_2); 126 | DBMS_OUTPUT.put_line ( 127 | '---------------------------------------------------'); 128 | DBMS_OUTPUT.put_line ('Encryption key (Part 1 XOR Part 2) : '); 129 | DBMS_OUTPUT.put_line (encryption_key); 130 | DBMS_OUTPUT.put_line ( 131 | '---------------------------------------------------'); 132 | DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string); 133 | DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || decrypted_raw); 134 | END db_link_password_decrypt; 135 | 136 | 137 | begin 138 | 139 | begin 140 | select p.value$ into v_salt 141 | from props$ p 142 | where p.name = 'NO_USERID_VERIFIER_SALT'; 143 | exception 144 | when NO_DATA_FOUND then 145 | raise_application_error( -20001, 'Unable to identify NO_USERID_VERIFIER_SALT for database', TRUE ); 146 | end; 147 | 148 | begin 149 | select rawtohex( l.passwordx ) into v_enc_passwd 150 | from sys.link$ l 151 | where l.owner# = ( select u.user_id from dba_users u 152 | where u.username = upper( '&owner' ) 153 | ) 154 | and l.name = upper( '&dblink' ); 155 | exception 156 | when NO_DATA_FOUND then 157 | raise_application_error( -20002, 'Database link "' || upper( '&dblink' ) || '" in schema "' || 158 | upper( '&owner' ) || '" not found', 159 | TRUE 160 | ); 161 | end; 162 | 163 | -- time to make the donuts! 164 | db_link_password_decrypt( v_salt, v_enc_passwd ); 165 | end; 166 | / 167 | -------------------------------------------------------------------------------- /event_extractor.sh: -------------------------------------------------------------------------------- 1 | #Extact events that are checked in a specified core oracle function 2 | #Inspired from Franck Pachot Script https://blog.dbi-services.com/12cr2-no-cardinality-feedback-for-small-queries/ 3 | #Example : ./event_extractor.sh kslwtectx 4 | 5 | gdb oracle <<< "disas $1" | awk --non-decimal-data '/mov .*,%edi$/{gsub(/[$,]/," ");a=$4}/EventRdbmsErr/{printf "dbkdChkEventRdbmsErr %d\n", a}' | sort -u 6 | gdb oracle <<<"disas $1" | awk --non-decimal-data '/mov .*,%.*cx$/{gsub(/[$,]/," ");a=$4}/mov .*\$.*,%.*dx$/{gsub(/[$,]/," ");b=$4; if (b < 10999 && b > 10000) {c=$4 } }/mov .*\$[0-9a-zA-Z]*,%eax$/{gsub(/[$,]/," "); if ($4 < 10999 && $4 > 10000) {c=$4 }}/dbgdChkEventIntV/{if(b == 18219009 ) { if ( a != 33882161 ) { printf "dbgdChkEventIntV EDX:%x ECX:%x \n", b,a; } else { printf "dbgdChkEventIntV EDX:%x ECX:%x KST_EVENT:%d \n", b,a,c; }} else { printf "dbgdChkEventIntV EDX:%x \n", b ; } }' | sort -u 7 | 8 | -------------------------------------------------------------------------------- /eventsname.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- eventsname.sql 3 | -- 4 | -- This sqlplus script generates a sed script file to replace oracle wait event numbers with even names 5 | -- intended to be used together the systemtap trace scripts 6 | -- 7 | -- L.C. Aug 2014 8 | -- 9 | --A slightly modified version of Luca Canali script https://github.com/LucaCanali/Linux_tracing_scripts/blob/master/SystemTap_Userspace_Oracle/eventsname.sql 10 | 11 | set echo off pages 0 lines 200 feed off head off sqlblanklines off trimspool on trimout on 12 | 13 | spool eventsname.sed 14 | 15 | select 's/\/'||'event='||replace(name,'/','\/')||'/g' SED from v$event_name order by event# desc; 16 | 17 | spool off 18 | exit 19 | -------------------------------------------------------------------------------- /extract_func_info.sh: -------------------------------------------------------------------------------- 1 | gdb oracle <<<"disas $1 " | awk --non-decimal-data '/(mov|pushq).*\$0x[[:alnum:]]{6,8}(,|$)/{gsub(/[$,]/," ");print "x/1s " $4}' | sort -u | gdb oracle | grep "(gdb)" | grep -v "out of bounds" 2 | -------------------------------------------------------------------------------- /func_offset.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | # 3 | # func_offset.stp 4 | # 5 | # Usage: stap -g -v func_offset.stp oracle_exec_inode probe_function_address s_offset 6 | # 7 | # Author : Hatem Mahmoud 8 | # BLOG : https://mahmoudhatem.wordpress.com 9 | # 10 | # 11 | # Note: this is an experimental script, use at your own risk 12 | 13 | 14 | probe kernel.function("uprobe_register"),kernel.function("uprobe_unregister") 15 | { 16 | if( $inode->i_ino == $1) { 17 | if ($offset == $2 ) { 18 | printf("Patching sepecial offset at %x\n", $offset); 19 | $offset = $offset + $3; 20 | } else { 21 | printf("Patching offset at %x\n", $offset); 22 | $offset = $offset + 2; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /hugepage_usage_ins.sh: -------------------------------------------------------------------------------- 1 | total_shmsize=0 2 | total_hugepagesize=0 3 | 4 | for pid in `ps -ef | grep ora_pmon_|egrep -v "grep|+ASM"| awk '{print $2}'` 5 | do 6 | echo 7 | echo "-----------------------------------------------------------" 8 | echo 9 | ps -ef | grep $pid | grep -v grep 10 | 11 | shmsize=`grep -A 1 'SYSV00000000' /proc/$pid/smaps | grep "^Size:" | awk 'BEGIN{sum=0}{sum+=$2}END{print sum/1024}' | awk -F"." '{print $1}'` 12 | hugepagesize=`grep -B 11 'KernelPageSize: 2048 kB' /proc/$pid/smaps | grep "^Size:" | awk 'BEGIN{sum=0}{sum+=$2}END{print sum/1024}' | awk -F"." '{prin 13 | t $1}'` 14 | 15 | echo "INSTANCE SGA (SMALL/HUGE page)" : $shmsize "MB" 16 | echo "INSTANCE SGA (HUGE PAGE)" $hugepagesize "MB" 17 | 18 | echo "Percent Huge page :" $(( $hugepagesize *100 / $shmsize )) "%" 19 | 20 | 21 | total_shmsize=$(( $shmsize + $total_shmsize )) 22 | total_hugepagesize=$(( $total_hugepagesize + $hugepagesize )) 23 | 24 | done 25 | 26 | echo 27 | echo "-----------------------------------------------------------" 28 | echo "-----------------------------------------------------------" 29 | echo 30 | 31 | echo "SGA TOTAL (SMALL/HUGE page)" : $total_shmsize "MB" 32 | echo "SGA TOTAL (HUGE PAGE)" $total_hugepagesize "MB" 33 | echo "Percent Huge page :" $(( $total_hugepagesize *100 / $total_shmsize )) "%" 34 | -------------------------------------------------------------------------------- /jira_model_classif_inference.py: -------------------------------------------------------------------------------- 1 | # SYNOPSIS 2 | # jira_model_classif_inference.py Code example using the model classifier for Ticket autoassign 3 | # 4 | # EXEMPLE : 5 | # jira_model_classif_inference.py 6 | # 7 | # DESCRIPTION 8 | # 9 | # Autoassign of JIRA ticket using the BUILD Model 10 | # Some part of the code is sourced from https://developers.google.com/machine-learning/guides/text-classification 11 | # 12 | # 13 | # 14 | # HISTORY 15 | # 16 | # 2022-03-28 Hatem mahmoud creation 17 | # 18 | # REVISION 19 | # 20 | # 21 | from jira import JIRA 22 | import time 23 | import datetime as d 24 | import smtplib 25 | from email.mime.text import MIMEText 26 | from email.mime.multipart import MIMEMultipart 27 | from email.mime.base import MIMEBase 28 | from email import encoders 29 | import numpy as np 30 | import matplotlib.pyplot as plt 31 | import tensorflow as tf 32 | from tensorflow.python.keras import models 33 | from tensorflow.python.keras.layers import Dense 34 | from tensorflow.python.keras.layers import Dropout 35 | from sklearn import preprocessing 36 | from collections import Counter 37 | from sklearn.feature_extraction.text import CountVectorizer 38 | from sklearn.feature_extraction.text import TfidfVectorizer 39 | from sklearn.feature_extraction.text import TfidfTransformer 40 | from sklearn.feature_selection import SelectKBest 41 | from sklearn.feature_selection import f_classif 42 | from sklearn.metrics import confusion_matrix,classification_report,ConfusionMatrixDisplay 43 | from sklearn.metrics import accuracy_score 44 | import pickle 45 | from sys import maxsize 46 | from numpy import set_printoptions 47 | 48 | 49 | #Jira user, password and URL 50 | user_name = '****' 51 | password = '*****' 52 | jira_url = '****' 53 | 54 | #Tickets to assign 55 | Issue_id = [] 56 | jquery_test_data = 'status in ("OPEN") and assignee is EMPTY and created >= startOfMonth() order by createdDate asc' 57 | test_data = [] 58 | test_label = [] 59 | 60 | 61 | 62 | print('Program started. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ')') 63 | 64 | # Jira Server Connection 65 | options = {'server': jira_url} 66 | # Authentication 67 | try: 68 | jira = JIRA(options, basic_auth=(f'{user_name}', f'{password}')) 69 | print('Program connected. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ')') 70 | except BaseException as Be: 71 | print(Be) 72 | 73 | 74 | count = 0 75 | while True: 76 | print('Program Testing data. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ') lot : ', count ) 77 | i = 0 78 | if count > 1000 : 79 | break 80 | all_closed_issues_inference = jira.search_issues( 81 | jquery_test_data , startAt=count,maxResults=999) 82 | if len(all_closed_issues_inference) == 0: 83 | break 84 | for i in range(0, len(all_closed_issues_inference)): 85 | Issue_id.append(str(all_closed_issues_inference[i].key)) 86 | test_data.append(.. 87 | count += 999 88 | 89 | print('Number of Testing sample ',len(test_data)) 90 | if len(test_data) == 0: 91 | quit() 92 | 93 | 94 | #Load Encoder 95 | trle = pickle.load(open("LabelEncoder.pkl", "rb")) 96 | model = tf.keras.models.load_model('JIRA_mlp_model.h5') 97 | 98 | # Check model architecture 99 | model.summary() 100 | 101 | 102 | # Vectorize training texts. 103 | loaded_vec = pickle.load(open("feature.pkl", "rb")) 104 | x_test = loaded_vec.transform(test_data) 105 | 106 | # Select top 'k' of the vectorized features. 107 | loaded_sel = pickle.load(open("selector.pkl", "rb")) 108 | x_test = loaded_sel.transform(x_test).todense() 109 | 110 | 111 | set_printoptions(threshold=maxsize) 112 | 113 | mlp_predictions = model.predict(x_test) 114 | y_classes = mlp_predictions.argmax(axis=-1) 115 | 116 | 117 | print('-------------Model prediction-----------') 118 | 119 | for i in range(len(x_test)): 120 | print("Issue=%s , Predicted=%s, prob=%s" % (Issue_id[i], trle.inverse_transform([y_classes[i]]),max(mlp_predictions[i]))) 121 | issues_Jql = jira.issue(Issue_id[i],expand='changelog') 122 | issues_Jql.update({'customfield_10210': {'value':) 123 | issues_Jql.assign_issue(Issue_id[i], None) 124 | 125 | -------------------------------------------------------------------------------- /jira_model_classif_train.py: -------------------------------------------------------------------------------- 1 | # SYNOPSIS 2 | # jira_model_classif_train.py Code example for training a JIRA model classifier 3 | # 4 | # EXEMPLE : 5 | # jira_model_classif_train.py 6 | # 7 | # DESCRIPTION 8 | # 9 | # Training a JIRA model classifier (MLP) 10 | # Some part of the code is sourced from https://developers.google.com/machine-learning/guides/text-classification 11 | # 12 | # 13 | # 14 | # HISTORY 15 | # 16 | # 2022-03-04 HM creation 17 | # 18 | # REVISION 19 | # 20 | # 21 | 22 | from jira import JIRA 23 | import time 24 | import datetime as d 25 | import smtplib 26 | from email.mime.text import MIMEText 27 | from email.mime.multipart import MIMEMultipart 28 | from email.mime.base import MIMEBase 29 | from email import encoders 30 | import numpy as np 31 | import matplotlib.pyplot as plt 32 | import tensorflow as tf 33 | from tensorflow.python.keras import models 34 | from tensorflow.python.keras.layers import Dense 35 | from tensorflow.python.keras.layers import Dropout 36 | from sklearn import preprocessing 37 | from sklearn.feature_extraction.text import CountVectorizer 38 | from sklearn.feature_extraction.text import TfidfVectorizer 39 | from sklearn.feature_selection import SelectKBest 40 | from sklearn import model_selection, naive_bayes, svm 41 | from sklearn.tree import DecisionTreeClassifier 42 | from sklearn.feature_selection import f_classif 43 | from sklearn.metrics import confusion_matrix,classification_report 44 | from collections import Counter 45 | from keras.regularizers import l2 46 | from keras.regularizers import l1 47 | from sklearn.metrics import accuracy_score 48 | from sklearn.utils import class_weight 49 | import pickle 50 | from sys import maxsize 51 | from numpy import set_printoptions 52 | 53 | 54 | #Jira user, password and URL 55 | user_name = '****' 56 | password = '*****' 57 | jira_url = '****' 58 | 59 | 60 | #Training, validation and testing dataset 61 | jquery_train_data = 'status in ("Closed - To Confirm", Closed) and assignee is not EMPTY and created > startOfMonth(-8) and created < startOfMonth(-3) order by createdDate asc' 62 | train_data = [] 63 | train_label = [] 64 | jquery_valid_data = 'status in ("Closed - To Confirm", Closed) and assignee is not EMPTY and created > startOfMonth(-3) and created < startOfMonth(-2) order by createdDate asc' 65 | valid_data = [] 66 | valid_label = [] 67 | jquery_test_data = 'status in ("Closed - To Confirm", Closed) and assignee is not EMPTY and created > startOfMonth(-2) and created < startOfMonth(-1) order by createdDate asc' 68 | test_data = [] 69 | test_label= [] 70 | 71 | 72 | #Record best model accuracy 73 | model_best_accuracy = 0 74 | 75 | 76 | # Vectorization parameters 77 | # Range (inclusive) of n-gram sizes for tokenizing text. 78 | NGRAM_RANGE = (1, 2) 79 | 80 | # Limit on the number of features. We use the top 20K features. 81 | TOP_K = 20000 82 | 83 | # Whether text should be split into word or character n-grams. 84 | # One of 'word', 'char'. 85 | TOKEN_MODE = 'word' 86 | 87 | # Minimum document/corpus frequency below which a token will be discarded. 88 | MIN_DOCUMENT_FREQUENCY = 2 89 | 90 | 91 | def train_ngram_model(train_texts, train_labels, val_texts, val_labels, test_texts, test_labels, 92 | lr=1e-3, 93 | epochs=1000, 94 | batch_size=128, 95 | layers=2, 96 | units=64, 97 | dropout_rate=0.2, 98 | l2_regularization=0.0001): 99 | """Trains n-gram model on the given dataset. 100 | 101 | # Arguments 102 | train_texts, train_labels, val_texts, val_labels, test_texts, test_labels: tuples of training, validation and test texts and labels. 103 | lr: float, learning rate for training model. 104 | epochs: int, number of epochs. 105 | batch_size: int, number of samples per batch. 106 | layers: int, number of `Dense` layers in the model. 107 | units: int, output dimension of Dense layers in the model. 108 | dropout_rate: float: percentage of input to drop at Dropout layers. 109 | l2_regularization: float: Degree of weight decay (L2 weight regularization). 110 | 111 | # Raises 112 | ValueError: If validation data has label values which were not seen 113 | in the training data. 114 | """ 115 | # Get the data. 116 | # train_texts, train_labels, val_texts, val_labels, test_texts, test_labels 117 | 118 | # Verify that validation labels are in the same range as training labels. 119 | num_classes = get_num_classes(train_labels) 120 | unexpected_labels = [v for v in val_labels if v not in range(num_classes)] 121 | if len(unexpected_labels): 122 | raise ValueError('Unexpected label values found in the validation set:' 123 | ' {unexpected_labels}. Please make sure that the ' 124 | 'labels in the validation set are in the same range ' 125 | 'as training labels.'.format( 126 | unexpected_labels=unexpected_labels)) 127 | 128 | # Vectorize texts. 129 | x_train, x_val, x_test = ngram_vectorize( 130 | train_texts, train_labels, val_texts, test_texts) 131 | 132 | # Create model instance. 133 | model = mlp_model(layers=layers, 134 | units=units, 135 | dropout_rate=dropout_rate, 136 | input_shape=x_train.shape[1:], 137 | num_classes=num_classes, 138 | l2_regularization=l2_regularization) 139 | 140 | # Compile model with learning parameters. 141 | if num_classes == 2: 142 | loss = 'binary_crossentropy' 143 | else: 144 | loss = 'sparse_categorical_crossentropy' 145 | optimizer = tf.keras.optimizers.Adam(learning_rate=lr) 146 | model.compile(optimizer= 'adam', loss=loss, metrics=['acc']) 147 | 148 | # Create callback for early stopping on validation loss. If the loss does 149 | # not decrease in two consecutive tries, stop training. 150 | callbacks = [tf.keras.callbacks.EarlyStopping( 151 | monitor='val_loss', patience=2)] 152 | 153 | 154 | #Adjust class Weight 155 | class_weights = class_weight.compute_class_weight(class_weight = 'balanced',classes = np.unique(train_labels),y = train_labels) 156 | class_weights = dict(enumerate(class_weights)) 157 | 158 | # Train and validate model. 159 | history = model.fit( 160 | x_train, 161 | train_labels, 162 | epochs=epochs, 163 | callbacks=callbacks, 164 | #class_weight=class_weights, 165 | validation_data=(x_val, val_labels), 166 | verbose=2, # Logs once per epoch. 167 | batch_size=batch_size) 168 | 169 | # Print results. 170 | history = history.history 171 | print('Validation accuracy: {acc}, loss: {loss}'.format( 172 | acc=history['val_acc'][-1], loss=history['val_loss'][-1])) 173 | 174 | # Evaluate the model 175 | loss, acc_t = model.evaluate(x_test, test_labels, verbose=2) 176 | print("Model test, accuracy: {:5.2f}%".format(100 * acc_t)) 177 | 178 | 179 | 180 | 181 | set_printoptions(threshold=maxsize) 182 | 183 | mlp_predictions = model.predict(x_test) 184 | # creating a confusion matrix 185 | cm_mlp = confusion_matrix( np.array(test_labels), mlp_predictions.argmax(axis=1)) 186 | print('MLP test confusion_matrix') 187 | print(cm_mlp) 188 | print('Classification Report') 189 | print(classification_report(np.array(test_labels), mlp_predictions.argmax(axis=1))) 190 | #print(mlp_predictions) 191 | global model_best_accuracy 192 | if model_best_accuracy < acc_t: 193 | print("Model with better test, accuracy: {:5.2f}%".format(100 * acc_t)) 194 | model_best_accuracy=acc_t 195 | # Save model. 196 | model.save('JIRA_mlp_model.h5') 197 | 198 | #Try other classifier 199 | ## Classifier - Algorithm - NB classifier 200 | #Naive = naive_bayes.MultinomialNB() 201 | #Naive.fit(x_val,val_labels) 202 | ## predict the labels on validation dataset 203 | #predictions_NB = Naive.predict(x_test) 204 | ## Use accuracy_score function to get the accuracy 205 | #print("Naive Bayes Accuracy Score -> ",accuracy_score(predictions_NB, np.array(test_labels))*100) 206 | # 207 | ## Classifier - Algorithm - SVM 208 | ## fit the training dataset on the classifier 209 | #SVM = svm.SVC(kernel='linear') 210 | #SVM.fit(x_train,train_labels) 211 | ## predict the labels on validation dataset 212 | #predictions_SVM = SVM.predict(x_test) 213 | ## Use accuracy_score function to get the accuracy 214 | #print("SVM Accuracy Score -> ",accuracy_score(predictions_SVM, test_labels)*100) 215 | # 216 | ## Classifier - Algorithm - a DescisionTreeClassifier 217 | # 218 | #dtree_model = DecisionTreeClassifier(max_depth = 2).fit( np.array(x_train), np.array( train_labels)) 219 | #dtree_predictions = dtree_model.predict( np.array(x_val)) 220 | # 221 | #score = accuracy_score( np.array(val_labels), np.array(dtree_predictions)) 222 | #print("dtree train, accuracy:",score ) 223 | ## creating a confusion matrix 224 | #cm = confusion_matrix( np.array(val_labels), np.array(dtree_predictions)) 225 | #print('dtree train confusion_matrix') 226 | #print(cm) 227 | 228 | return history['val_acc'][-1], history['val_loss'][-1] 229 | 230 | 231 | def mlp_model(layers, units, dropout_rate, input_shape, num_classes,l2_regularization): 232 | """Creates an instance of a multi-layer perceptron model. 233 | 234 | # Arguments 235 | layers: int, number of `Dense` layers in the model. 236 | units: int, output dimension of the layers. 237 | dropout_rate: float, percentage of input to drop at Dropout layers. 238 | input_shape: tuple, shape of input to the model. 239 | num_classes: int, number of output classes. 240 | l2_regularization:float: Degree of weight decay (L2 weight regularization). 241 | 242 | # Returns 243 | An MLP model instance. 244 | """ 245 | op_units, op_activation = _get_last_layer_units_and_activation(num_classes) 246 | model = models.Sequential() 247 | model.add(Dropout(rate=dropout_rate, input_shape=input_shape)) 248 | 249 | for _ in range(layers-1): 250 | model.add(Dense(units=units, activation='relu' 251 | ,kernel_regularizer=l2(l2_regularization) 252 | )) 253 | model.add(Dropout(rate=dropout_rate)) 254 | 255 | model.add(Dense(units=op_units, activation=op_activation)) 256 | return model 257 | 258 | def _get_last_layer_units_and_activation(num_classes): 259 | """Gets the # units and activation function for the last network layer. 260 | 261 | # Arguments 262 | num_classes: int, number of classes. 263 | 264 | # Returns 265 | units, activation values. 266 | """ 267 | if num_classes == 2: 268 | activation = 'sigmoid' 269 | units = 1 270 | else: 271 | activation = 'softmax' 272 | units = num_classes 273 | return units, activation 274 | 275 | def ngram_vectorize(train_texts, train_labels, val_texts,test_texts): 276 | """Vectorizes texts as n-gram vectors. 277 | 278 | 1 text = 1 tf-idf vector the length of vocabulary of unigrams + bigrams. 279 | 280 | # Arguments 281 | train_texts: list, training text strings. 282 | train_labels: np.ndarray, training labels. 283 | val_texts: list, validation text strings. 284 | test_texts:list, testing text strings. 285 | 286 | # Returns 287 | x_train, x_val, x_test: vectorized training , validation and test texts 288 | """ 289 | # Create keyword arguments to pass to the 'tf-idf' vectorizer. 290 | kwargs = { 291 | 'ngram_range': NGRAM_RANGE, # Use 1-grams + 2-grams. 292 | 'dtype': 'int32', 293 | 'strip_accents': 'unicode', 294 | 'decode_error': 'replace', 295 | 'analyzer': TOKEN_MODE, # Split text into word tokens. 296 | 'min_df': MIN_DOCUMENT_FREQUENCY, 297 | } 298 | vectorizer = TfidfVectorizer(**kwargs) 299 | 300 | # Learn vocabulary from training texts and vectorize training texts. 301 | x_train = vectorizer.fit_transform(train_texts) 302 | 303 | # Vectorize validation texts. 304 | x_val = vectorizer.transform(val_texts) 305 | 306 | # Vectorize test texts. 307 | x_test = vectorizer.transform(test_texts) 308 | 309 | #Save vectorizer 310 | pickle.dump(vectorizer,open("feature.pkl","wb")) 311 | 312 | # Select top 'k' of the vectorized features. 313 | selector = SelectKBest(f_classif, k=min(TOP_K, x_train.shape[1])) 314 | selector.fit(x_train, train_labels) 315 | x_train = selector.transform(x_train).todense() 316 | x_val = selector.transform(x_val).todense() 317 | x_test = selector.transform(x_test).todense() 318 | #Save selector 319 | pickle.dump(selector,open("selector.pkl","wb")) 320 | return x_train, x_val, x_test 321 | 322 | def get_num_classes(labels): 323 | """Gets the total number of classes. 324 | # Arguments 325 | labels: list, label values. 326 | There should be at lease one sample for values in the 327 | range (0, num_classes -1) 328 | # Returns 329 | int, total number of classes. 330 | # Raises 331 | ValueError: if any label value in the range(0, num_classes - 1) 332 | is missing or if number of classes is <= 1. 333 | """ 334 | num_classes = max(labels) + 1 335 | missing_classes = [i for i in range(num_classes) if i not in labels] 336 | if len(missing_classes): 337 | raise ValueError('Missing samples with label value(s) ' 338 | '{missing_classes}. Please make sure you have ' 339 | 'at least one sample for every label value ' 340 | 'in the range(0, {max_class})'.format( 341 | missing_classes=missing_classes, 342 | max_class=num_classes - 1)) 343 | 344 | if num_classes <= 1: 345 | raise ValueError('Invalid number of labels: {num_classes}.' 346 | 'Please make sure there are at least two classes ' 347 | 'of samples'.format(num_classes=num_classes)) 348 | return num_classes 349 | 350 | 351 | def plot_class_distribution(labels): 352 | """Plots the class distribution. 353 | # Arguments 354 | labels: list, label values. 355 | There should be at lease one sample for values in the 356 | range (0, num_classes -1) 357 | """ 358 | num_classes = get_num_classes(labels) 359 | count_map = Counter(labels) 360 | counts = [count_map[i] for i in range(num_classes)] 361 | idx = np.arange(num_classes) 362 | plt.bar(idx, counts, width=0.8, color='b') 363 | plt.xlabel('Class') 364 | plt.ylabel('Number of samples') 365 | plt.title('Class distribution') 366 | plt.xticks(idx, idx) 367 | plt.show() 368 | 369 | 370 | 371 | 372 | print('Program started. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ')') 373 | 374 | # Jira Server Connection 375 | options = {'server': jira_url} 376 | # Authentication 377 | try: 378 | jira = JIRA(options, basic_auth=(f'{user_name}', f'{password}')) 379 | print('Program connected. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ')') 380 | except BaseException as Be: 381 | print(Be) 382 | 383 | 384 | 385 | #Load last saved training data 386 | #train_data = pickle.load(open("train_data.pkl", "rb")) 387 | #train_label = pickle.load(open("train_label.pkl", "rb")) 388 | 389 | count = 0 390 | while True: 391 | print('Program Training data. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ') lot : ', count ) 392 | i = 0 393 | if count > 50000 : 394 | break 395 | all_closed_issues_training = jira.search_issues( 396 | jquery_train_data, startAt=count,maxResults=999 ) 397 | if len(all_closed_issues_training) == 0: 398 | break 399 | for i in range(0, len(all_closed_issues_training)): 400 | train_data.append(... 401 | train_label.append(... 402 | 403 | count += 999 404 | 405 | print('Number of training sample ',len(train_data)) 406 | 407 | pickle.dump(train_data,open("train_data.pkl","wb")) 408 | pickle.dump(train_label,open("train_label.pkl","wb")) 409 | 410 | #Encode training Label 411 | trle = preprocessing.LabelEncoder() 412 | train_label_e=trle.fit_transform(train_label) 413 | print(list(trle.classes_)) 414 | print('Number of training classes : ' , get_num_classes( np.array(train_label_e))) 415 | plot_class_distribution(np.array(train_label_e)) 416 | #print(list(train_label_e)) 417 | #print(trle.inverse_transform([0])) 418 | 419 | #Save Label Encoder 420 | pickle.dump(trle,open("LabelEncoder.pkl","wb")) 421 | 422 | #valid_data = pickle.load(open("valid_data.pkl", "rb")) 423 | #valid_label = pickle.load(open("valid_label.pkl", "rb")) 424 | 425 | count = 0 426 | while True: 427 | print('Program Validation data. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ') lot : ', count ) 428 | i = 0 429 | if count > 2000 : 430 | break 431 | all_closed_issues_validation = jira.search_issues( 432 | jquery_valid_data, startAt=count,maxResults=999 ) 433 | if len(all_closed_issues_validation) == 0: 434 | break 435 | for i in range(0, len(all_closed_issues_validation)): 436 | valid_data.append(... 437 | valid_label.append(... 438 | count += 999 439 | 440 | 441 | 442 | print('Number of validation sample ',len(valid_data)) 443 | 444 | pickle.dump(valid_data,open("valid_data.pkl","wb")) 445 | pickle.dump(valid_label,open("valid_label.pkl","wb")) 446 | 447 | #Encode testing Label 448 | valid_label_e=trle.transform(valid_label) 449 | print('Number of validation classes : ' , get_num_classes( np.array(valid_label_e))) 450 | 451 | 452 | #test_data = pickle.load(open("test_data.pkl", "rb")) 453 | #test_label = pickle.load(open("test_label.pkl", "rb")) 454 | 455 | count = 0 456 | while True: 457 | print('Program Testing data. (' + d.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ') lot : ', count ) 458 | i = 0 459 | if count > 2000 : 460 | break 461 | all_closed_issues_testing = jira.search_issues( 462 | jquery_test_data, startAt=count,maxResults=999 ) 463 | if len(all_closed_issues_testing) == 0: 464 | break 465 | for i in range(0, len(all_closed_issues_testing)): 466 | test_data.append(... 467 | test_label.append(... 468 | count += 999 469 | 470 | 471 | print('Number of testing sample ',len(test_data)) 472 | 473 | pickle.dump(test_data,open("test_data.pkl","wb")) 474 | pickle.dump(test_label,open("test_label.pkl","wb")) 475 | 476 | #Encode testing Label 477 | test_label_e=trle.transform(test_label) 478 | print('Number of testing classes : ' , get_num_classes( np.array(test_label_e))) 479 | 480 | 481 | 482 | 483 | #train_ngram_model(train_data, np.array(train_label_e),valid_data, np.array(valid_label_e),test_data, np.array(test_label_e)) 484 | 485 | #HP Tunning using Grid search 486 | for dropout_rate in [0.2,0.3]: 487 | for batch_size in [8,16,32,64,128]: 488 | for layers in [2,3,4]: 489 | for units in [16,32,64,128]: 490 | for l2_regularization in [0.0001,0.0002]: 491 | for lr in [1e-3]: 492 | print("Testing HP :",dropout_rate,batch_size,layers,units,l2_regularization,lr) 493 | train_ngram_model(train_data, np.array(train_label_e),valid_data, np.array(valid_label_e),test_data, np.array(test_label_e),1e-3, 494 | 1000, 495 | batch_size, 496 | layers, 497 | units, 498 | dropout_rate, 499 | l2_regularization) 500 | 501 | -------------------------------------------------------------------------------- /kernel_io_outlier_simul.stp: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/stap 2 | # 3 | # kernel_io_outlier_simul.stp 4 | # 5 | # This script simulate the view V$KERNEL_IO_OUTLIER on linux system using Systemtap 6 | # Usage: stap -v kernel_io_outlier_simul.stp ORACLE_SID 7 | # 8 | # Author : Hatem Mahmoud 9 | # 10 | # Note: this is experimental code, use at your own risk 11 | # 12 | 13 | global write_start_ts 14 | global bio_start_ts 15 | global wait_start_ts 16 | global wait_end_ts 17 | global write_end_ts 18 | global bsize 19 | global boffset 20 | global bfd 21 | global init 22 | 23 | probe syscall.pwrite { 24 | if ( isinstr(execname(),@1 ) ){ 25 | write_start_ts[pid()] = local_clock_us() 26 | bsize[pid()]=count 27 | boffset[pid()]=offset 28 | init[pid()]=1 29 | } 30 | } 31 | 32 | probe ioblock.request { 33 | if ( init[pid()] && bio_start_ts[pid()] == 0) { 34 | bio_start_ts[pid()] = local_clock_us() 35 | } 36 | } 37 | 38 | probe ioscheduler_trace.elv_issue_request{ 39 | if ( init[pid()] && wait_start_ts[pid()] == 0) { 40 | wait_start_ts[pid()] = local_clock_us() 41 | } 42 | } 43 | 44 | probe ioblock.end { 45 | if ( init[pid()] && wait_start_ts[pid()]) { 46 | wait_end_ts[pid()] = local_clock_us() 47 | bfd[pid()]= devname 48 | } 49 | } 50 | 51 | probe syscall.pwrite.return { 52 | if ( init[pid()]) { 53 | write_end_ts[pid()] = local_clock_us() 54 | 55 | e2e=local_clock_us() - write_start_ts[pid()] 56 | setup=bio_start_ts[pid()] - write_start_ts[pid()] 57 | queue=wait_start_ts[pid()] - bio_start_ts[pid()] 58 | txfr=wait_end_ts[pid()] - wait_start_ts[pid()] 59 | cleanup=local_clock_us() - wait_end_ts[pid()] 60 | 61 | if ( txfr > 500000 ) { 62 | printf("%d %9d %11d %9s %21s %9d %12d %12d %22d %22d %7d \n",gettimeofday_s(),bsize[pid()],boffset[pid()],bfd[pid()],substr(execname(),0,6),e2e,setup,queue,txfr,cleanup,p 63 | id()) 64 | } 65 | 66 | delete write_start_ts[pid()] 67 | delete bio_start_ts[pid()] 68 | delete wait_start_ts[pid()] 69 | delete wait_end_ts[pid()] 70 | delete write_end_ts[pid()] 71 | delete init[pid()] 72 | } 73 | } 74 | 75 | probe begin { 76 | printf(" TIMESTAMP IO_SIZE IO_OFFSET DEVICE_NAME PROCESS_NAME TOTAL_LATENCY SETUP_LATENCY QUEUE_TO_HBA_LATENCY TRANSFER_LATENCY CLEANUP_LATENCY PID\n"); 77 | printf("---------- ---------- ---------- --------------- --------------- ------------- ------------- -------------------- ---------------- --------------- --------\n"); 78 | } 79 | -------------------------------------------------------------------------------- /latch_callgraph.stp: -------------------------------------------------------------------------------- 1 | global padding=-1 2 | 3 | probe process("oracle").function("ksl_get_shared_latch") { 4 | if (pid() == target()) { 5 | padding=padding+1 6 | printf ("%s->Shared Latch acquisition : laddr=%x ,wait=%d ,where=%d,why=%d,mode=%d\n", substr(" ",1,padding),register("rdi"), register("rsi"), register("rcx"), register("rdx"), register("r8") ) 7 | } 8 | } 9 | 10 | 11 | probe process("oracle").function("kslgetl") { 12 | if (pid() == target()) { 13 | padding=padding+1 14 | printf ("%s->Exculsive Latch acquisition : laddr=%x ,wait=%d ,where=%d,why=%d\n", substr(" ",1,padding),register("rdi"), register("rsi"), register("rcx"), register("rdx") ) 15 | } 16 | } 17 | 18 | probe process("oracle").function("kslfre") { 19 | if (pid() == target()) { 20 | printf ("%s<-Latch released : laddr=%x\n", substr(" ",1,padding),register("rdi") ) 21 | padding=padding-1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /latch_callgraph2.stp: -------------------------------------------------------------------------------- 1 | global padding=-1 2 | 3 | 4 | probe process("oracle").function("ksl_get_shared_latch") { 5 | if (pid() == target()) { 6 | padding=padding+1 7 | printf ("%s->Shared Latch acquired : laddr=%x,wait=%d ,where=%d,why=%d,mode=%d \n", substr(" ",1,padding),register("rdi"), register("rsi"), register("rcx"), register("rdx"), register("r8") ) 8 | } 9 | } 10 | 11 | 12 | 13 | probe process("oracle").function("kslgetl") { 14 | if (pid() == target()) { 15 | padding=padding+1 16 | printf ("%s->Exculsive Latch acquired : laddr=%x ,wait=%d ,where=%d,why=%d\n", substr(" ",1,padding),register("rdi"), register("rsi"), register("rcx"), register("rdx") ) 17 | } 18 | } 19 | 20 | probe process("oracle").function("kslfre") { 21 | if (pid() == target()) { 22 | printf ("%s<-Latch released : laddr=%x\n", substr(" ",1,padding),register("rdi") ) 23 | padding=padding-1 24 | } 25 | } 26 | 27 | 28 | //process_address + 1128 29 | probe kernel.data(0xa15264c0).write { 30 | if (pid() == target()) { 31 | 32 | //process_address + 1128 33 | latch_address1=user_uint64(0xa15264c0) 34 | //process_address + 360 35 | latch_address2=user_uint64(0xa15261c0) 36 | 37 | 38 | if (latch_address2 == 0 ) 39 | { 40 | if (latch_address1 == 0) 41 | { 42 | printf("%s<-UltraFast Latch released : func=%s \n", substr(" ",1,padding),usymname(ustack(0))); 43 | padding=padding-1 44 | } 45 | else 46 | { 47 | padding=padding+1 48 | printf("%s->UltraFast Latch acquired : laddr=%x ,func=%s \n", substr(" ",1,padding),latch_address1,usymname(ustack(0))); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /latch_callgraph3.stp: -------------------------------------------------------------------------------- 1 | 2 | global latch_hold 3 | global latch_hold_c,latch_hold_p 4 | global padding=-1 5 | 6 | 7 | //process_address + 568+16*18 (“KSLLALAQ” of x$ksupr fixed table) 8 | probe kernel.data($1).write { 9 | if (target() == pid() ) { 10 | 11 | latch_hold_c=user_int64($1); 12 | 13 | 14 | //Looping throught latch state objects array 15 | for (i=1;i<19;i=i+1) { 16 | if (user_int64($1-16*i) != 0 ) { 17 | latch_hold[user_int64($1-16*i)] = 1 18 | } 19 | } 20 | 21 | if (latch_hold_c != 0 ) { 22 | //user_int64($1+592) is for handling special case of ultra fast latch 23 | if (latch_hold[latch_hold_c] != 1 && user_int64($1+592) != latch_hold_c ) { 24 | padding=padding+1; 25 | printf("%s->Latch acquired in func %s at adr=0x%x laddr=%x %d %d\n", substr(" ",1,padding),probefunc(),latch_hold_c,latch_hold_c,user_int32(latch_hold_c+4),user_int32(latch_hold_c+8)); 26 | } 27 | } else { 28 | if (latch_hold[latch_hold_p] != 1 && user_int64($1+592) != latch_hold_p) { 29 | printf("%s<-Latch released in func %s at adr=0x%x laddr=%x %d %d\n", substr(" ",1,padding),probefunc(),latch_hold_p,latch_hold_p,user_int32(latch_hold_p+4),user_int32(latch_hold_p+8)); 30 | padding=padding-1; 31 | } 32 | } 33 | latch_hold_p=latch_hold_c; 34 | delete latch_hold; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /latch_monitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | 8 | int main(int argc, char **argv ) 9 | { 10 | char *address; 11 | char *latch_state; 12 | char *ultralatch_state; 13 | char buf[17]; 14 | char latch_free[]="0000000000000000"; 15 | void *addr; 16 | int i; 17 | int j; 18 | int add_print=0; 19 | int flg3; 20 | int process_count; 21 | int shmid; 22 | 23 | printf("Enter min process addr : "); 24 | scanf("%p", &address); 25 | printf("Enter nb process : "); 26 | scanf("%d", &process_count); 27 | printf("Enter shmid :"); 28 | scanf("%d", &shmid); 29 | 30 | addr =shmat(shmid,(void *) 0x0000006b000000 ,SHM_RDONLY); 31 | 32 | if(addr == (void *)-1) { 33 | perror("shmop: shmat failed"); 34 | } 35 | 36 | //Loop throught x$ksupr 37 | for(i=0;i/'||'lname='||replace(name,'/','\/')||' \(Level'||LEVEL#||'\)/g' SED from v$latch_children; 6 | select 's/\/'||'lname='||replace(name,'/','\/')||' \(Level'||LEVEL#||'\)/g' SED from v$latch_parent; 7 | 8 | spool off 9 | exit 10 | -------------------------------------------------------------------------------- /line_tracker.stp: -------------------------------------------------------------------------------- 1 | global plsql_run_addr,monitor,b_monitor,last_offset 2 | 3 | #PL/SQL begin execution 4 | probe process("oracle").function("plsql_run").call { 5 | plsql_run_addr = register("rdi"); 6 | monitor = 1; 7 | printf("Line Begin|%d|%x|%x\n",local_clock_us(),0,0); 8 | 9 | } 10 | 11 | #PL/SQL end execution 12 | probe process("oracle").function("plsql_run").return { 13 | monitor = 0; 14 | printf("Line End|%d|%x|%x\n",local_clock_us(),0,0); 15 | 16 | } 17 | 18 | 19 | probe process("oracle").function("p*").call 20 | { 21 | 22 | if ( monitor > 1 ) { 23 | 24 | current_addr = plsql_run_addr+120; 25 | base_addr1 = plsql_run_addr+144; 26 | base_addr2 = user_int64(base_addr1); 27 | base_addr3 = user_int64(base_addr2)+264; 28 | KGLHDADR = user_int64(base_addr2)+104; 29 | 30 | inst_offset = user_int64(current_addr) - user_int64(user_int64(base_addr3)) 31 | printf("Line Tracker|%d|%x|%x\n",local_clock_us(),inst_offset,user_int64(KGLHDADR)); 32 | 33 | } 34 | } 35 | 36 | 37 | #Follow plsql call 38 | probe process("oracle").function("pfrinstr_ENTER").call { 39 | 40 | if (b_monitor == 1) { 41 | monitor = monitor + 1; 42 | b_monitor = 0; 43 | } else { 44 | b_monitor = 2; 45 | } 46 | 47 | } 48 | 49 | 50 | probe process("oracle").function("pfrust").call { 51 | 52 | if ( b_monitor < 2 ) { 53 | monitor = monitor - 1; 54 | current_addr = plsql_run_addr+120; 55 | base_addr1 = plsql_run_addr+144; 56 | base_addr2 = user_int64(base_addr1); 57 | base_addr3 = user_int64(base_addr2)+264; 58 | KGLHDADR = user_int64(base_addr2)+104; 59 | 60 | inst_offset = user_int64(current_addr) - user_int64(user_int64(base_addr3)) 61 | printf("Line Tracker|%d|%x|%x|%d\n",local_clock_us(),inst_offset,user_int64(KGLHDADR),99999) 62 | } else { 63 | b_monitor = 0; 64 | } 65 | 66 | } 67 | 68 | 69 | 70 | probe process("oracle").function("prfinstr_XCAL").call { 71 | b_monitor = 1; 72 | current_addr = plsql_run_addr+120; 73 | base_addr1 = plsql_run_addr+144; 74 | base_addr2 = user_int64(base_addr1); 75 | base_addr3 = user_int64(base_addr2)+264; 76 | KGLHDADR = user_int64(base_addr2)+104; 77 | 78 | inst_offset = user_int64(current_addr) - user_int64(user_int64(base_addr3)) 79 | last_offset = inst_offset; 80 | } 81 | 82 | 83 | probe process("oracle").function("pfrxca").call { 84 | b_monitor = 1; 85 | current_addr = plsql_run_addr+120; 86 | base_addr1 = plsql_run_addr+144; 87 | base_addr2 = user_int64(base_addr1); 88 | base_addr3 = user_int64(base_addr2)+264; 89 | KGLHDADR = user_int64(base_addr2)+104; 90 | 91 | inst_offset = last_offset; 92 | printf("Line Tracker|%d|%x|%x|%d\n",local_clock_us(),inst_offset,user_int64(KGLHDADR),monitor); 93 | } 94 | -------------------------------------------------------------------------------- /load_sql_patch.sql: -------------------------------------------------------------------------------- 1 | SPO load_sql_patch.log; 2 | SET DEF ON TERM OFF ECHO ON FEED OFF VER OFF HEA ON LIN 2000 PAGES 100 LONG 8000000 LONGC 800000 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 NUM 20 SQLP SQL>; 3 | SET SERVEROUT ON SIZE UNL; 4 | REM 5 | REM $Header: load_sql_patch.sql 6 | REM 7 | REM Copyright (c) 2000-2021, Oracle Corporation. All rights reserved. 8 | REM 9 | REM AUTHOR 10 | REM carlos.sierra@oracle.com Modified by Hatem Mahmoud for use with SQL Patches 11 | REM 12 | REM SCRIPT 13 | REM load_sql_patch.sql 14 | REM 15 | REM DESCRIPTION 16 | REM This script loads a plan from a modified SQL into a Custom SQL 17 | REM Patch for the original SQL. 18 | REM If a good performing plan only reproduces with CBO Hints 19 | REM then you can load the plan of the modified version of the 20 | REM SQL into a Custom SQL Patch for the orignal SQL. 21 | REM In other words, the original SQL can use the plan that was 22 | REM generated out of the SQL with hints. 23 | REM 24 | REM PRE-REQUISITES 25 | REM 1. Have in cache or AWR the text for the original SQL. 26 | REM 2. Have in cache or AWR the plan for the modified SQL 27 | REM (usually with hints). 28 | REM 29 | REM PARAMETERS 30 | REM 1. ORIGINAL_SQL_ID (required) 31 | REM 2. MODIFIED_SQL_ID (required) 32 | REM 3. PLAN_HASH_VALUE (required) 33 | REM 34 | REM EXECUTION 35 | REM 1. Connect into SQL*Plus as user with access to data dictionary 36 | REM and privileges to create SQL Patch. Do not use SYS. 37 | REM 2. Execute script load_sql_patch.sql passing first two 38 | REM parameters inline or until requested by script. 39 | REM 3. Provide plan hash value of the modified SQL when asked. 40 | REM 4. Use a DBA user but not SYS. Do not connect as SYS as the staging 41 | REM table cannot be created in SYS schema and you will receive an error: 42 | REM ORA-19381: cannot create staging table in SYS schema 43 | REM 44 | REM EXAMPLE 45 | REM # sqlplus system 46 | REM SQL> START load_sql_patch.sql gnjy0mn4y9pbm b8f3mbkd8bkgh 47 | REM SQL> START load_sql_patch.sql; 48 | REM 49 | REM NOTES 50 | REM 1. This script works on 12c or higher. 51 | REM 52 | SET TERM ON ECHO OFF; 53 | PRO 54 | PRO Parameter 1: 55 | PRO ORIGINAL_SQL_ID (required) 56 | PRO 57 | DEF original_sql_id = '&1'; 58 | PRO 59 | PRO Parameter 2: 60 | PRO MODIFIED_SQL_ID (required) 61 | PRO 62 | DEF modified_sql_id = '&2'; 63 | PRO 64 | WITH 65 | p AS ( 66 | SELECT plan_hash_value 67 | FROM gv$sql_plan 68 | WHERE sql_id = TRIM('&&modified_sql_id.') 69 | AND other_xml IS NOT NULL 70 | ), 71 | m AS ( 72 | SELECT plan_hash_value, 73 | SUM(elapsed_time)/SUM(executions) avg_et_secs 74 | FROM gv$sql 75 | WHERE sql_id = TRIM('&&modified_sql_id.') 76 | AND executions > 0 77 | GROUP BY 78 | plan_hash_value ) 79 | SELECT p.plan_hash_value, 80 | ROUND(m.avg_et_secs/1e6, 3) avg_et_secs 81 | FROM p, m 82 | WHERE p.plan_hash_value = m.plan_hash_value(+) 83 | ORDER BY 84 | avg_et_secs NULLS LAST; 85 | PRO 86 | PRO Parameter 3: 87 | PRO PLAN_HASH_VALUE (required) 88 | PRO 89 | DEF plan_hash_value = '&3'; 90 | PRO 91 | PRO Values passed to load_sql_patch: 92 | PRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93 | PRO ORIGINAL_SQL_ID: "&&original_sql_id." 94 | PRO MODIFIED_SQL_ID: "&&modified_sql_id." 95 | PRO PLAN_HASH_VALUE: "&&plan_hash_value." 96 | PRO 97 | --WHENEVER SQLERROR EXIT SQL.SQLCODE; 98 | SET TERM OFF ECHO ON; 99 | 100 | -- trim parameters 101 | COL original_sql_id NEW_V original_sql_id FOR A30; 102 | COL modified_sql_id NEW_V modified_sql_id FOR A30; 103 | COL plan_hash_value NEW_V plan_hash_value FOR A30; 104 | SELECT TRIM('&&original_sql_id.') original_sql_id, TRIM('&&modified_sql_id.') modified_sql_id, TRIM('&&plan_hash_value.') plan_hash_value FROM DUAL; 105 | 106 | -- open log file 107 | SPO load_sql_patch_&&original_sql_id..log; 108 | GET load_sql_patch.log; 109 | . 110 | 111 | -- get user 112 | COL connected_user NEW_V connected_user FOR A30; 113 | SELECT USER connected_user FROM DUAL; 114 | 115 | VAR sql_text CLOB; 116 | VAR other_xml CLOB; 117 | VAR signature NUMBER; 118 | VAR name VARCHAR2(30); 119 | 120 | EXEC :sql_text := NULL; 121 | EXEC :other_xml := NULL; 122 | EXEC :signature := NULL; 123 | EXEC :name := NULL; 124 | 125 | -- get sql_text from memory 126 | DECLARE 127 | l_sql_text VARCHAR2(32767); 128 | BEGIN -- 10g see bug 5017909 129 | FOR i IN (SELECT DISTINCT piece, sql_text 130 | FROM gv$sqltext_with_newlines 131 | WHERE sql_id = TRIM('&&original_sql_id.') 132 | ORDER BY 1, 2) 133 | LOOP 134 | IF :sql_text IS NULL THEN 135 | DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE); 136 | DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE); 137 | END IF; 138 | l_sql_text := REPLACE(i.sql_text, CHR(00), ' '); 139 | DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text), l_sql_text); 140 | END LOOP; 141 | IF :sql_text IS NOT NULL THEN 142 | DBMS_LOB.CLOSE(:sql_text); 143 | END IF; 144 | EXCEPTION 145 | WHEN OTHERS THEN 146 | DBMS_OUTPUT.PUT_LINE('getting original sql_text from memory: '||SQLERRM); 147 | :sql_text := NULL; 148 | END; 149 | / 150 | 151 | -- sql_text as found 152 | SELECT :sql_text FROM DUAL; 153 | 154 | -- check is sql_text for original sql is available 155 | SET TERM ON; 156 | BEGIN 157 | IF :sql_text IS NULL THEN 158 | RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for original SQL_ID &&original_sql_id. was not found in memory (gv$sqltext_with_newlines).'); 159 | END IF; 160 | END; 161 | / 162 | SET TERM OFF; 163 | 164 | -- get other_xml from memory 165 | BEGIN 166 | FOR i IN (SELECT other_xml 167 | FROM gv$sql_plan 168 | WHERE sql_id = TRIM('&&modified_sql_id.') 169 | AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.')) 170 | AND other_xml IS NOT NULL 171 | ORDER BY 172 | child_number, id) 173 | LOOP 174 | :other_xml := i.other_xml; 175 | EXIT; -- 1st 176 | END LOOP; 177 | EXCEPTION 178 | WHEN OTHERS THEN 179 | DBMS_OUTPUT.PUT_LINE('getting modified other_xml from memory: '||SQLERRM); 180 | :other_xml := NULL; 181 | END; 182 | / 183 | 184 | -- other_xml as found 185 | SELECT :other_xml FROM DUAL; 186 | 187 | -- validate other_xml 188 | SET TERM ON; 189 | BEGIN 190 | IF :other_xml IS NULL THEN 191 | RAISE_APPLICATION_ERROR(-20101, 'PLAN for modified SQL_ID &&modified_sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan).'); 192 | END IF; 193 | END; 194 | / 195 | 196 | SET ECHO OFF; 197 | DECLARE 198 | h SYS.SQLPROF_ATTR := SYS.SQLPROF_ATTR (); 199 | idx INTEGER := 0; 200 | l_pos NUMBER; 201 | l_hint VARCHAR2(32767); 202 | description VARCHAR2(500); 203 | output varchar2(100); 204 | 205 | PROCEDURE add_hint (p_hint IN VARCHAR2) 206 | IS 207 | BEGIN 208 | idx := idx + 1; 209 | DBMS_OUTPUT.PUT_LINE(LPAD(idx, 4, '0')||' '||p_hint); 210 | h.EXTEND; 211 | h(idx) := p_hint; 212 | END add_hint; 213 | 214 | BEGIN 215 | add_hint('BEGIN_OUTLINE_DATA'); 216 | FOR i IN (SELECT /*+ opt_param('parallel_execution_enabled', 'false') */ 217 | SUBSTR(EXTRACTVALUE(VALUE(d), '/hint'), 1, 4000) hint 218 | FROM TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(:other_xml), '/*/outline_data/hint'))) d) 219 | LOOP 220 | l_hint := i.hint; 221 | WHILE NVL(LENGTH(l_hint), 0) > 0 222 | LOOP 223 | IF LENGTH(l_hint) <= 500 THEN 224 | add_hint(l_hint); 225 | l_hint := NULL; 226 | ELSE 227 | l_pos := INSTR(SUBSTR(l_hint, 1, 500), ' ', -1); 228 | add_hint(SUBSTR(l_hint, 1, l_pos)); 229 | l_hint := ' '||SUBSTR(l_hint, l_pos); 230 | END IF; 231 | END LOOP; 232 | END LOOP; 233 | add_hint('END_OUTLINE_DATA'); 234 | 235 | :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(:sql_text); 236 | :name := UPPER(TRIM('&&original_sql_id.'))||'_'||TRIM('&&plan_hash_value.'); 237 | description := UPPER('original:'||TRIM('&&original_sql_id.')||' modified:'||TRIM('&&modified_sql_id.')||' phv:'||TRIM('&&plan_hash_value.')||' signature:'||:signature||' created by load_sql_patch.sql'); 238 | 239 | -- create custom sql patch for original sql using plan from modified sql 240 | 241 | output := SYS.DBMS_SQLTUNE_INTERNAL.I_CREATE_SQL_PROFILE( 242 | SQL_TEXT => :sql_text, 243 | PROFILE_XML => SYS.DBMS_SMB_INTERNAL.VARR_TO_HINTS_XML(h), 244 | NAME => :name, 245 | DESCRIPTION => description, 246 | CATEGORY => 'DEFAULT', 247 | CREATOR => 'SYS', 248 | VALIDATE => TRUE, 249 | TYPE => 'PATCH', 250 | FORCE_MATCH => TRUE, /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ 251 | IS_PATCH => TRUE ); 252 | dbms_output.put_line(output); 253 | END; 254 | / 255 | 256 | -- patch_name 257 | COL patch_name NEW_V patch_name FOR A30; 258 | SELECT :name patch_name FROM DUAL; 259 | 260 | -- display details of new sql_patch 261 | SET ECHO ON; 262 | REM 263 | REM SQL Patch 264 | REM ~~~~~~~~~~~ 265 | REM ~~~~~~~~~~~ 266 | REM 267 | SELECT signature, name, category, status 268 | FROM dba_sql_patches WHERE name = :name; 269 | SELECT description 270 | FROM dba_sql_patches WHERE name = :name; 271 | -------------------------------------------------------------------------------- /mini_db_firewall.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | # 3 | # Tested with ORACLE 11.2.0.4 on OEL6 with kernel UEK4 4 | # Systemtap version used 3.0 5 | # 6 | # This script contains excerpt of code developed by : 7 | # Luca Canali : http://externaltable.blogspot.com/2016/03/systemtap-guru-mode-and-oracle-sql.html 8 | global listener_child_pid,oracle_process_pid,check_pid,statement_track,fd_socket 9 | 10 | probe begin { 11 | printf("-----------------------------\n"); 12 | printf("Waiting for new connection\n"); 13 | 14 | } 15 | 16 | function block_parse(pointersql:long) %{ 17 | char *sqltext; 18 | sqltext = (char *) STAP_ARG_pointersql; 19 | /* Modify the SQL text with an end of line: this will throw ORA-00900: invalid SQL statement */ 20 | sqltext[0] = 0; 21 | %} 22 | 23 | 24 | probe kernel.function("inet_csk_accept").return { 25 | sock = $return 26 | if (target() == pid() && sock != 0) { 27 | if (inet_get_ip_source(sock) == @1) { 28 | printf("----------------------------- \n"); 29 | printf("User connected from %s on %s\n",inet_get_ip_source(sock),ctime()); 30 | check_pid = 1; 31 | } 32 | } 33 | } 34 | 35 | 36 | probe syscall.accept.return { 37 | if (target() == pid() && check_pid == 1) { 38 | printf("Allocated file discriptor : %s\n",retstr); 39 | fd_socket = retstr; 40 | } 41 | } 42 | 43 | 44 | probe nd_syscall.clone.return { 45 | if (check_pid == 1 && target() == pid() ) { 46 | printf("Tracking child listener with pid : %s\n",retstr); 47 | listener_child_pid = retstr 48 | check_pid = 0; 49 | } 50 | 51 | 52 | if (strtol(listener_child_pid,10) == pid()) { 53 | printf("Assigned oracle process with pid : %s\n",retstr); 54 | oracle_process_pid = retstr; 55 | listener_child_pid = "-1"; 56 | } 57 | } 58 | 59 | 60 | probe process("oracle").function("kksParseCursor") { 61 | if ( statement_track == 1 && strtol(oracle_process_pid,10) == pid()) { 62 | 63 | sqltext = user_string2(register("rbx"),"error") 64 | 65 | if (isinstr(sqltext, "create") || isinstr(sqltext, "drop")) { 66 | printf("Bloked statement : %s \n",sqltext) 67 | block_parse(register("rbx")) 68 | } else if (isinstr(sqltext, "error") == 0 ){ 69 | printf("Parsed statement : %s \n", sqltext) 70 | } 71 | } 72 | } 73 | 74 | 75 | probe process("oracle").function("opiinfv") { 76 | 77 | if (pid() == strtol(oracle_process_pid,10) ) 78 | { 79 | connect_info = user_string2(pointer_arg(2),"ERROR"); 80 | printf("Connection info : \n"); 81 | printf("%s\n",connect_info ) 82 | printf("-----------------------------\n"); 83 | if (isinstr( connect_info,@2) == 1 ) 84 | { 85 | printf("Traking statement parsing\n"); 86 | printf("-----------------------------\n"); 87 | statement_track= 1; 88 | } else { 89 | printf("Traking statement parsing not enabled (Different service_name specified)\n"); 90 | printf("-----------------------------\n"); 91 | printf("Waiting for new connection\n"); 92 | statement_track = 0; 93 | } 94 | 95 | } 96 | } 97 | 98 | 99 | 100 | probe nd_syscall.write { 101 | if ( fd == strtol(fd_socket,10) && pid() == strtol(oracle_process_pid,10) ) { 102 | 103 | #For some reason i was not able to get the full string using user_string_n(pointer_arg(2),ulong_arg(3)) so i used this very dirty trick (it will not work for all the cases and can be enhanced) 104 | for (i=0;i 11 | # BLOG : https://mahmoudhatem.wordpress.com 12 | # 13 | # Tested in oracle 12.2.0.1 14 | # Note: this is an experimental script, use at your own risk 15 | 16 | echo ---------------------------------- 17 | echo collecting $3 errorstacks samples ! 18 | echo ---------------------------------- 19 | 20 | trace_file_name=`sqlplus / as sysdba <&1 | grep trace | cut -d' ' -f2 21 | oradebug setospid $1 22 | oradebug pdump interval=$2 ndumps=$3 errorstack 1 23 | oradebug tracefile_name 24 | exit; 25 | EOF` 26 | echo ------------------------ 27 | echo Tracefile to be parsed ! 28 | echo $trace_file_name 29 | echo ------------------------ 30 | 31 | >plsql_memory_leak.txt 32 | 33 | egrep "package|procedure|anonymous block|call kghalf| $4|SQL Call Stack" $trace_file_name > parsed_trace.txt 34 | 35 | plsql_string="" 36 | block=0 37 | 38 | while read p; do 39 | 40 | if [ "$p" == "----- PL/SQL Call Stack -----" ] 41 | then 42 | block=1 43 | plsql_string="" 44 | elif [ ! -z "`echo $p | grep call`" ] 45 | then 46 | block=2 47 | else 48 | 49 | if [ $block == 1 ] 50 | then 51 | 52 | plsql_string=`echo $p "->" $plsql_string` 53 | 54 | elif [ $block == 2 ] && [ ! -z "`echo $p | grep $4`" ] 55 | then 56 | 57 | echo $plsql_string >> plsql_memory_leak.txt 58 | block=0 59 | 60 | fi 61 | 62 | fi 63 | 64 | 65 | done < parsed_trace.txt 66 | 67 | 68 | cat plsql_memory_leak.txt | sort | uniq -c 69 | -------------------------------------------------------------------------------- /plsql_obj.sql: -------------------------------------------------------------------------------- 1 | set echo off pages 0 lines 200 feed off head off sqlblanklines off trimspool on trimout on 2 | 3 | spool plsql_obj.sed 4 | 5 | select 's/OBJ='||OBJECT_ID||' SOBJ='||SUBPROGRAM_ID||'/'||OBJECT_NAME||'.'||PROCEDURE_NAME||'/g' SED from dba_procedures; 6 | 7 | spool off 8 | exit 9 | -------------------------------------------------------------------------------- /plsql_profiler.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # plsql_profiler.sh 4 | # 5 | # This script is a geeky PL/SQL profiler 6 | # Usage: ./plsql_profiler.sh "PID" 7 | # 8 | # Author : Hatem Mahmoud 9 | # BLOG : https://mahmoudhatem.wordpress.com 10 | # 11 | # Tested in oracle 12.2.0.1 12 | # Note: this is an experimental script, use at your own risk 13 | 14 | 15 | PROFILE_PID=$1 16 | > stap_stat 17 | stap -v -x $PROFILE_PID line_tracker.stp -o line_tracker.txt 2> stap_stat & 18 | until grep -q starting stap_stat; do sleep 0.01; done 19 | perf record -g -T -o perf.data -p $PROFILE_PID & 20 | read -p "profiling started, press enter to stop" a 21 | kill -s SIGTERM %1 22 | kill -s SIGINT %2 23 | 24 | perf script -i perf.data > perf.data.script01 25 | 26 | cat perf.data.script01 | while read PROFILE_LINE; do 27 | info_line=`echo $PROFILE_LINE | awk -F' ' '{print $5}'` 28 | if [ "$info_line" == "cpu-clock:" ] 29 | then 30 | echo $PROFILE_LINE 31 | echo " 7fff8131fed4 |"`echo $PROFILE_LINE | awk -F' ' '{print $3}' | tr -d -c 0-9`"| (time)" 32 | else 33 | echo $PROFILE_LINE 34 | fi 35 | done > perf.data.script02 36 | 37 | 38 | cat perf.data.script02 | /home/oracle/scripts/FlameGraph-master/stackcollapse-perf.pl > perf.data.collapse01 39 | >cache_resolver 40 | echo 0 > current_depth 41 | cat line_tracker.txt | xargs -i ./sql_resolver2.sh {} > line_tracker2.txt 42 | cat line_tracker2.txt >> perf.data.collapse01 43 | cat perf.data.collapse01 | sort -t'|' -k2 -n > perf.data.collapse02 44 | 45 | last_object="null" 46 | monitor=0 47 | >perf.data.collapse03 48 | cat perf.data.collapse02 | while read PROFILE_LINE; do 49 | info_line=`echo $PROFILE_LINE | awk -F'|' '{print $1}'` 50 | 51 | if [ "$info_line" == "Line End" ] 52 | then 53 | monitor=0 54 | fi 55 | 56 | if [ $monitor == 1 ] 57 | then 58 | 59 | if [ "$info_line" == "Line Tracker" ] 60 | then 61 | last_object=`echo $PROFILE_LINE | awk -F'|' '{print $3}'` 62 | else 63 | echo $last_object";"`echo $PROFILE_LINE | awk -F'|' '{print $1}'` >> perf.data.collapse03 64 | fi 65 | 66 | fi 67 | 68 | if [ "$info_line" == "Line Begin" ] 69 | then 70 | monitor=1 71 | fi 72 | 73 | done 74 | 75 | cat perf.data.collapse03 | tr ' ' '_' | sort | uniq -c |awk '{print $2" "$1}' > out.perf-folded 76 | /home/oracle/scripts/FlameGraph-master/flamegraph.pl out.perf-folded > plsql_profile.svg 77 | 78 | 79 | -------------------------------------------------------------------------------- /plsql_tracer.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | # 3 | # plsql_tracer.stp 4 | # 5 | # This script is a geeky PL/SQL tracer 6 | # Usage: stap -v plsql_profiler.stp -x 14971 | xargs -i ./sql_resolver.sh {} 7 | # 8 | # Author : Hatem Mahmoud 9 | # BLOG : https://mahmoudhatem.wordpress.com 10 | # 11 | # Tested in oracle 12.2.0.1 12 | # Note: this is an experimental script, use at your own risk 13 | 14 | 15 | global plsql_run_addr,monitor,b_monitor 16 | 17 | 18 | #PL/SQL begin execution 19 | probe process("oracle").function("plsql_run").call { 20 | plsql_run_addr = register("rdi"); 21 | monitor = 1; 22 | } 23 | 24 | #PL/SQL end execution 25 | probe process("oracle").function("plsql_run").return { 26 | monitor = 0; 27 | } 28 | 29 | 30 | 31 | #Tracing PL/SQL functions 32 | probe process("oracle").function("p*") 33 | { 34 | 35 | if ( monitor > 1 ) { 36 | 37 | current_addr = plsql_run_addr+120; 38 | base_addr1 = plsql_run_addr+144; 39 | base_addr2 = user_int64(base_addr1); 40 | base_addr3 = user_int64(base_addr2)+264; 41 | KGLHDADR = user_int64(base_addr2)+104; 42 | 43 | inst_offset = user_int64(current_addr) - user_int64(user_int64(base_addr3)) 44 | 45 | printf("%s:%x:%x:%d\n",probefunc(),inst_offset,user_int64(KGLHDADR),monitor); 46 | 47 | } 48 | 49 | } 50 | 51 | 52 | 53 | #Follow plsql call 54 | probe process("oracle").function("pfrinstr_ENTER").call { 55 | 56 | if (b_monitor == 1) { 57 | monitor = monitor + 1; 58 | b_monitor = 0; 59 | } else { 60 | b_monitor = 2; 61 | } 62 | 63 | } 64 | 65 | 66 | probe process("oracle").function("pfrust").call { 67 | 68 | if ( b_monitor < 2 ) { 69 | monitor = monitor - 1; 70 | } else { 71 | b_monitor = 0; 72 | } 73 | 74 | } 75 | 76 | 77 | 78 | probe process("oracle").function("pfrxca").call { 79 | b_monitor = 1; 80 | } 81 | -------------------------------------------------------------------------------- /schedtimes_wsi.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | 3 | ############################################################ 4 | # Schedtimes.stp 5 | # 6 | # Copyright (C) 2009, 2014 Red Hat, Inc. 7 | # 8 | # This program is free software you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License version 2 as 10 | # published by the Free Software Foundation. 11 | 12 | # Authors: Jason Baron 13 | # Josh Stone 14 | # profiles threads and displays their run times, queued times, 15 | # wait times, including i/o wait times. 16 | # Has two modes. When no arguments are given it profiles all 17 | # threads. Alternatively, you can pass -c "program name" 18 | # 19 | # 06/02/2017 added oracle session information by Hatem Mahmoud 20 | ############################################################ 21 | 22 | 23 | 24 | global KSUSENUM = 5920 25 | global KSUSESQH = 6084 26 | global KSUSECLI = 6488 27 | 28 | 29 | global ksupga_address=202316608 30 | global ksupga_offset=24 31 | 32 | 33 | //constants 34 | global DEAD=-1, RUNNING=1, QUEUED=2, SLEEPING=3 35 | 36 | global run_time, queued_time, sleep_time, iowait_time 37 | global pid_state, pid_names,pid_sid,pid_hash,pid_cli_info 38 | 39 | 40 | // For new enough kernels, roughly 2.6.32+, the @defined(@task->in_iowait) 41 | // tests will succeed and reduce these macros to nothing, including these 42 | // pid-iowait arrays. For older kernels, the rq fallback will remain. 43 | global pid_in_iowait 44 | global pid_iowait_count 45 | 46 | @define in_iowait(task) %( 47 | @choose_defined(@task->in_iowait, 48 | (pid_in_iowait[@task->pid] ? pid_in_iowait[@task->pid]-- : 0)) 49 | %) 50 | 51 | @define clear_iowait(rq, task) %( 52 | if (!@defined(@task->in_iowait)) 53 | pid_iowait_count[@task->pid] = @nr_iowait(@rq) 54 | %) 55 | 56 | @define set_iowait(rq, task) %( 57 | if (!@defined(@task->in_iowait)) 58 | pid_in_iowait[@task->pid] = (@nr_iowait(@rq) > pid_iowait_count[@task->pid]) 59 | %) 60 | 61 | @define nr_iowait(rq) %( 62 | atomic_read(&@cast(@rq, "rq")->nr_iowait) 63 | %) 64 | 65 | 66 | global previous_timestamp 67 | 68 | function timestamp() 69 | { 70 | return cpu_clock_us(0) 71 | } 72 | 73 | function update_times(pid, now) 74 | { 75 | delta = now - previous_timestamp[pid] 76 | previous_timestamp[pid] = now 77 | 78 | if ((state = pid_state[pid]) > 0) { 79 | if (state == SLEEPING) 80 | sleep_time[pid] += delta 81 | else if (state == QUEUED) 82 | queued_time[pid] += delta 83 | else if (state == RUNNING) 84 | run_time[pid] += delta 85 | } 86 | 87 | return delta 88 | } 89 | 90 | 91 | function task_targeted(task) 92 | { 93 | pid = task_pid(task) 94 | if (pid && (!target() || target_set_pid(pid))) { 95 | pid_names[task_tid(task)] = task_execname(task) 96 | if (( isinstr(task_execname(task) , "ora_" ) == 1 || isinstr(task_execname(task) , "oracle" ) == 1 ) && user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM) > 0 ) { 97 | pid_sid[task_tid(task)] = user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM); 98 | pid_hash[task_tid(task)] = user_uint32(user_uint64(ksupga_address+ksupga_offset)+KSUSESQH); 99 | pid_cli_info[task_tid(task)] = user_string2(user_uint64(ksupga_address+ksupga_offset)+KSUSECLI,"error"); 100 | } 101 | return 1 102 | } 103 | return 0 104 | } 105 | 106 | // Update the task name after exec 107 | probe kernel.trace("sched_process_exec")!, 108 | kprocess.exec_complete 109 | { 110 | if (tid() in pid_names) 111 | pid_names[tid()] = execname() 112 | } 113 | 114 | 115 | probe kernel.trace("sched_switch") 116 | { 117 | // Task $prev is scheduled off this cpu 118 | if (task_targeted($prev)) { 119 | pid = $prev->pid 120 | state = $prev->state 121 | update_times(pid, timestamp()) 122 | 123 | if (state > 0) { 124 | @set_iowait($rq, $prev) 125 | pid_state[pid] = SLEEPING 126 | } else if (state == 0) { 127 | pid_state[pid] = QUEUED 128 | } else { 129 | pid_state[pid] = DEAD 130 | } 131 | } 132 | 133 | // Task $next is scheduled onto this cpu 134 | if (task_targeted($next)) { 135 | pid = $next->pid 136 | update_times(pid, timestamp()) 137 | 138 | @clear_iowait($rq, $next) 139 | pid_state[pid] = RUNNING 140 | } 141 | } 142 | 143 | probe kernel.trace("sched_wakeup") 144 | { 145 | // Task $p is awakened 146 | if (@choose_defined($success, 1) && task_targeted($p)) { 147 | pid = $p->pid 148 | delta = update_times(pid, timestamp()) 149 | if (pid_state[pid] == SLEEPING && @in_iowait($p)) { 150 | iowait_time[pid] += delta 151 | } 152 | pid_state[pid] = QUEUED 153 | } 154 | } 155 | 156 | // Give task $p a final accounting 157 | probe kernel.trace("sched_process_exit") 158 | { 159 | if (task_targeted($p)) { 160 | pid = $p->pid 161 | update_times(pid, timestamp()) 162 | pid_state[pid] = DEAD 163 | } 164 | } 165 | 166 | probe end 167 | { 168 | t = timestamp() 169 | printf ("\n%16s: %6s %10s %10s %10s %10s %10s %10s %10s %10s\n\n", 170 | "execname", "pid", "run(us)", "sleep(us)", "iowait(us)", 171 | "queued(us)", "total(us)", "[ sid", "sql_hash"," client_info ]") 172 | 173 | foreach (pid+ in pid_state) { 174 | update_times(pid, t) 175 | } 176 | foreach ([pid] in run_time- limit 10) { 177 | 178 | if(pid_sid[pid]) { 179 | printf("%16s: %6d %10d %10d %10d %10d %10d %10d %12d %10s\n", pid_names[pid], pid, 180 | run_time[pid], sleep_time[pid], iowait_time[pid], queued_time[pid], 181 | (run_time[pid] + sleep_time[pid] + queued_time[pid]),pid_sid[pid],pid_hash[pid],pid_cli_info[pid] ) 182 | } else { 183 | printf("%16s: %6d %10d %10d %10d %10d %10d\n", pid_names[pid], pid, 184 | run_time[pid], sleep_time[pid], iowait_time[pid], queued_time[pid], 185 | (run_time[pid] + sleep_time[pid] + queued_time[pid])) 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /socktop_wsi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Socktop systemtap script 4 | # Copyright (C) 2006 IBM Corp. 5 | # 6 | # This file is part of systemtap, and is free software. You can 7 | # redistribute it and/or modify it under the terms of the GNU General 8 | # Public License (GPL); either version 2, or (at your option) any 9 | # later version. 10 | 11 | ### 12 | ### socktop - Combination shell/systemtap script to track reads and writes 13 | ### on sockets by process. Can be filtered by process IDs and 14 | ### names, protocols, protocol families, users and socket type. 15 | ### 16 | ### 06/02/2017 added oracle session information by Hatem Mahmoud 17 | 18 | 19 | ITER_COUNT=-1 # number of iterations (no iteration limit default) 20 | MOD_GEN=""; # Generate a instrumentation module option 21 | 22 | # Filter options 23 | F_PROTSTR=""; F_PROT=0 # Filter by protocol 24 | F_FAMSTR=""; F_FAM=0 # Filter by protocol family 25 | F_TYPESTR=""; F_TYPE=0 # Filter by socket type 26 | F_PIDSTR=""; F_PID=0 # Filter by process ID 27 | F_NAMESTR=""; F_NAME=0 # Filter by process name 28 | F_UIDSTR=""; F_UID=0 # Filter by user 29 | FILTER=0 # Any filters specified? 30 | 31 | # Print options 32 | P_INTERVAL=5 # default interval between output 33 | P_DEVICES=0 # default is don't display network device traffic 34 | P_NUMTOP=10 # default number of processes and network devices to print 35 | 36 | DELIM="," 37 | 38 | function usage { 39 | echo "USAGE: socktop [-d] [-i interval] [-N num] [-P protocol]... [-f family]..." 40 | echo " [-t stype]... [-n pname]... [-p pid]... [-u username]... [-h]" 41 | echo " -d # print network device traffic (default: off)" 42 | echo " -i interval # interval in seconds between printing (default: $P_INTERVAL)" 43 | echo " -N num # number of top processes and devices to print (default: $P_NUMTOP)" 44 | echo " -f family # this protocol family only (default: all)" 45 | echo " -P protocol # this protocol only (default: all)" 46 | echo " -t stype # this socket type only (default: all)" 47 | echo " -n pname # this process name only (default: all)" 48 | echo " -p pid # this process ID only (default: all)" 49 | echo " -u username # this user only (default: all)" 50 | echo " -c count # number of iteration" 51 | echo " -D # dry run (generate instrumentation but do not run)" 52 | echo " -h # print this help text" 53 | echo "" 54 | echo "Protocol Families:" 55 | echo " LOCAL, INET, INET6, IPX, NETLINK, X25, AX25, ATMPVC, APPLETALK, PACKET" 56 | echo "" 57 | echo "Protocols:" 58 | echo " TCP, UDP, SCTP, IP, FC, ... (see /etc/protocols for complete list)" 59 | echo "" 60 | echo "Socket Types:" 61 | echo " STREAM, DGRAM, RAW, RDM, SEQPACKET, DCCP, PACKET" 62 | } 63 | 64 | # Process options 65 | while getopts df:i:n:N:P:p:t:u:c:Dh option; do 66 | case $option in 67 | d) P_DEVICES=1 ;; 68 | i) P_INTERVAL=$OPTARG ;; 69 | N) P_NUMTOP=$OPTARG ;; 70 | f) let "F_FAM++" 71 | F_FAMSTR=$OPTARG$DELIM$F_FAMSTR ;; 72 | n) let "F_NAME++" 73 | F_NAMESTR=$OPTARG$DELIM$F_NAMESTR ;; 74 | p) let "F_PID++" 75 | F_PIDSTR=$OPTARG$DELIM$F_PIDSTR ;; 76 | P) let "F_PROT++" 77 | F_PROTSTR=$OPTARG$DELIM$F_PROTSTR ;; 78 | t) let "F_TYPE++" 79 | F_TYPESTR=$OPTARG$DELIM$F_TYPESTR ;; 80 | u) uid=`awk -F: '$1 == name {print $3}' name=$OPTARG /etc/passwd` 81 | if [[ $uid != "" ]]; then 82 | let "F_UID++" 83 | F_UIDSTR=$uid$DELIM$F_UIDSTR 84 | else 85 | echo "ERROR: Unknown user:" $OPTARG 86 | let "ERROR++" 87 | fi ;; 88 | c) ITER_COUNT=$OPTARG ;; 89 | D) MOD_GEN="-p4" ;; 90 | h|?|*) usage 91 | exit 1 ;; 92 | esac 93 | done 94 | 95 | if [[ $ERROR > 0 ]]; then 96 | exit 1 97 | fi 98 | 99 | if [[ $F_FAM > 0 || $F_NAME > 0 || $F_PID > 0 || 100 | $F_PROT > 0 || $F_TYPE > 0 || $F_UID > 0 ]]; then 101 | FILTER=1 102 | fi 103 | 104 | # 105 | # Pass a timezone adjustment value to the stap script 106 | # 107 | TZ=`date "+%z"` 108 | TZ_SIGN=`echo $TZ | cut -c1` 109 | TZ_HOURS=`echo $TZ | cut -c2-3` 110 | TZ_MINS=`echo $TZ | cut -c4-5` 111 | TZ_ADJUST=$TZ_SIGN$((10#$TZ_HOURS*60*60+10#$TZ_MINS*60)) 112 | 113 | # 114 | # Start the systemtap script 115 | # 116 | stap $MOD_GEN -w -e ' 117 | global iter 118 | global execname, user, if_tx, if_rx, if_dev 119 | global sk_tx, sk_rx, sk_pid 120 | global f_name_str, f_pid_str, f_prot_str, f_fam_str, f_type_str, f_uid_str 121 | global f_name, f_pid, f_prot, f_fam, f_type, f_uid 122 | 123 | 124 | global pid_sid,pid_hash,pid_cli_info 125 | 126 | global KSUSENUM = 5920 127 | global KSUSESQH = 6084 128 | global KSUSECLI = 6488 129 | 130 | 131 | global ksupga_address=202316608 132 | global ksupga_offset=24 133 | 134 | probe never { 135 | #workaround to avoid outputing filtering strings 136 | log(f_name_str); 137 | log(f_pid_str); 138 | log(f_prot_str); 139 | log(f_fam_str); 140 | log(f_type_str); 141 | log(f_uid_str); 142 | 143 | #workaround to make sure that systemtap gets correct types for arrays 144 | if_rx["junk"] <<< 0 145 | if_tx["junk"] <<< 0 146 | if_dev["junk"] ++ 147 | delete if_rx 148 | delete if_tx 149 | delete if_dev 150 | } 151 | 152 | probe begin 153 | { 154 | # set number of iterations 155 | iter = '$ITER_COUNT' 156 | 157 | # If no filters specified, skip filter processing 158 | if ('$FILTER' == 0) next 159 | 160 | f_name_str = "'$F_NAMESTR'" 161 | f_pid_str = "'$F_PIDSTR'" 162 | f_prot_str = "'$F_PROTSTR'" 163 | f_fam_str = "'$F_FAMSTR'" 164 | f_type_str = "'$F_TYPESTR'" 165 | f_uid_str = "'$F_UIDSTR'" 166 | 167 | delim = "'$DELIM'" 168 | error = 0 169 | 170 | # Protocols 171 | if ('$F_PROT') { 172 | prot = tokenize(f_prot_str, delim) 173 | while (prot != "") { 174 | p = sock_prot_str2num(prot) 175 | if (p < 0) { 176 | printf("ERROR: Unknown protocol: %s\n", prot) 177 | error++ 178 | } else 179 | f_prot[p] = 1 180 | prot = tokenize("", delim) 181 | } 182 | } 183 | 184 | # Protocol families 185 | if ('$F_FAM') { 186 | fam = tokenize(f_fam_str, delim) 187 | while (fam != "") { 188 | f = sock_fam_str2num(fam) 189 | if (f < 0) { 190 | printf("ERROR: Unknown protocol family: %s\n", fam) 191 | error++ 192 | } else 193 | f_fam[f] = 1 194 | fam = tokenize("", delim) 195 | } 196 | } 197 | 198 | # Process names 199 | if ('$F_NAME') { 200 | pname = tokenize(f_name_str, delim) 201 | while (pname != "") { 202 | f_name[pname] = 1 203 | pname = tokenize("", delim) 204 | } 205 | } 206 | 207 | # Process IDs 208 | if ('$F_PID') { 209 | pid = tokenize(f_pid_str, delim) 210 | while (pid != "") { 211 | f_pid[strtol(pid, 10)] = 1 212 | pid = tokenize("", delim) 213 | } 214 | } 215 | 216 | # Socket types 217 | if ('$F_TYPE') { 218 | stype = tokenize(f_type_str, delim) 219 | while (stype != "") { 220 | t = sock_type_str2num(stype) 221 | if (t < 0) { 222 | printf("ERROR: Unknown socket type: %s\n", stype) 223 | error++ 224 | } else 225 | f_type[t] = 1 226 | stype = tokenize("", delim) 227 | } 228 | } 229 | 230 | # User IDs 231 | if ('$F_UID') { 232 | uid = tokenize(f_uid_str, delim) 233 | while (uid != "") { 234 | f_uid[strtol(uid, 10)] = 1 235 | uid = tokenize("", delim) 236 | } 237 | } 238 | 239 | if (error) exit() 240 | } 241 | 242 | probe netdev.transmit 243 | { 244 | if ('$P_DEVICES') { 245 | if_tx[dev_name] <<< length 246 | if_dev[dev_name] ++ 247 | } 248 | } 249 | 250 | probe netdev.receive 251 | { 252 | if ('$P_DEVICES') { 253 | if_rx[dev_name] <<< length 254 | if_dev[dev_name] ++ 255 | } 256 | } 257 | 258 | probe socket.send 259 | { 260 | if (!success) next 261 | 262 | # Check filters 263 | if ('$FILTER') { 264 | if ('$F_PROT' && !(protocol in f_prot)) next 265 | if ('$F_FAM' && !(family in f_fam)) next 266 | if ('$F_PID' && !(pid() in f_pid)) next 267 | if ('$F_NAME' && !(execname() in f_name)) next 268 | if ('$F_UID' && !(uid() in f_uid)) next 269 | if ('$F_TYPE' && !(type in f_type)) next 270 | } 271 | 272 | execname[pid()] = execname() 273 | user[pid()] = uid() 274 | sk_tx[pid(), protocol, family] <<< size 275 | sk_pid[pid(), protocol, family] += size 276 | 277 | if (( isinstr(execname() , "ora_" ) == 1 || isinstr(execname() , "oracle" ) == 1 ) && user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM) > 0 ) { 278 | pid_sid[pid()] = user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM); 279 | pid_hash[pid()] = user_uint32(user_uint64(ksupga_address+ksupga_offset)+KSUSESQH); 280 | pid_cli_info[pid()] = user_string2(user_uint64(ksupga_address+ksupga_offset)+KSUSECLI,"error"); 281 | } 282 | } 283 | 284 | probe socket.receive 285 | { 286 | if (!success) next 287 | 288 | # Check filters 289 | if ('$FILTER') { 290 | if ('$F_PROT' && !(protocol in f_prot)) next 291 | if ('$F_FAM' && !(family in f_fam)) next 292 | if ('$F_PID' && !(pid() in f_pid)) next 293 | if ('$F_NAME' && !(execname() in f_name)) next 294 | if ('$F_UID' && !(uid() in f_uid)) next 295 | if ('$F_TYPE' && !(type in f_type)) next 296 | } 297 | 298 | execname[pid()] = execname() 299 | user[pid()] = uid() 300 | sk_rx[pid(), protocol, family] <<< size 301 | sk_pid[pid(), protocol, family] += size 302 | 303 | if (( isinstr(execname() , "ora_" ) == 1 || isinstr(execname() , "oracle" ) == 1 ) && user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM) > 0 ) { 304 | pid_sid[pid()] = user_uint16(user_uint64(ksupga_address+ksupga_offset)+KSUSENUM); 305 | pid_hash[pid()] = user_uint32(user_uint64(ksupga_address+ksupga_offset)+KSUSESQH); 306 | pid_cli_info[pid()] = user_string2(user_uint64(ksupga_address+ksupga_offset)+KSUSECLI,"error"); 307 | } 308 | } 309 | 310 | function print_activity() 311 | { 312 | # Print top processes 313 | max = '$P_NUMTOP' 314 | time = gettimeofday_s() + '$TZ_ADJUST' 315 | 316 | printf("======================= %s ========================\n", ctime(time)) 317 | printf("------------------------------- PROCESSES -------------------------------\n") 318 | printf("%-5s %-5s %7s %7s %7s %7s %-4s %-8s %-15s %-8s %-15s %-15s\n", 319 | "PID", "UID", "#SEND", "#RECV", "SEND_KB", 320 | "RECV_KB", "PROT", "FAMILY", "COMMAND","SID","SQL_HASH","CLIENT_INFO") 321 | foreach ([pid, prot, fam] in sk_pid- limit max) { 322 | n_sk_tx = @count(sk_tx[pid, prot, fam]) 323 | n_sk_rx = @count(sk_rx[pid, prot, fam]) 324 | if (pid_sid[pid]) { 325 | printf("%-5d %-5d %7d %7d %7d %7d %-4s %-8s %-15s %-8d %-15d %-15s\n", 326 | pid, user[pid], n_sk_tx, n_sk_rx, 327 | n_sk_tx ? @sum(sk_tx[pid, prot, fam])/1024 : 0, 328 | n_sk_rx ? @sum(sk_rx[pid, prot, fam])/1024 : 0, 329 | sock_prot_num2str(prot), sock_fam_num2str(fam), 330 | execname[pid],pid_sid[pid], pid_hash[pid],pid_cli_info[pid]) 331 | } else { 332 | printf("%-5d %-5d %7d %7d %7d %7d %-4s %-8s %-15s\n", 333 | pid, user[pid], n_sk_tx, n_sk_rx, 334 | n_sk_tx ? @sum(sk_tx[pid, prot, fam])/1024 : 0, 335 | n_sk_rx ? @sum(sk_rx[pid, prot, fam])/1024 : 0, 336 | sock_prot_num2str(prot), sock_fam_num2str(fam), 337 | execname[pid]) 338 | } 339 | } 340 | 341 | # Print top network devices 342 | if ('$P_DEVICES') { 343 | max = '$P_NUMTOP' 344 | printf("-------------------------------- DEVICES --------------------------------\n") 345 | printf("%-7s %13s %13s %15s %15s\n", 346 | "DEV", "#XMIT", "#RECV", "XMIT_KB", "RECV_KB") 347 | foreach ([dev] in if_dev- limit max) { 348 | n_if_tx = @count(if_tx[dev]) 349 | n_if_rx = @count(if_rx[dev]) 350 | printf("%-7s %13d %13d %15d %15d\n", dev, n_if_tx, n_if_rx, 351 | n_if_tx ? @sum(if_tx[dev])/1024 : 0, 352 | n_if_rx ? @sum(if_rx[dev])/1024 : 0) 353 | } 354 | } 355 | 356 | printf("=========================================================================\n\n") 357 | 358 | delete execname 359 | delete user 360 | delete sk_tx 361 | delete sk_rx 362 | delete sk_pid 363 | delete if_tx 364 | delete if_rx 365 | delete if_dev 366 | delete pid_sid 367 | delete pid_hash 368 | delete pid_cli_info 369 | } 370 | 371 | 372 | probe timer.s('$P_INTERVAL') 373 | { 374 | print_activity(); 375 | --iter; 376 | if (iter == 0) exit(); 377 | } 378 | ' 379 | saved_status=$? 380 | 381 | # Cleanup 382 | test -n "$MOD_GEN" && rm -f ${MOD_NAME}.ko 383 | 384 | # Exit with the status of 'stap', not the cleanup commands. 385 | exit $saved_status 386 | -------------------------------------------------------------------------------- /sql_resolver.sh: -------------------------------------------------------------------------------- 1 | func_var=`echo $1 | cut -d: -f1 ` 2 | offset_var=0x`echo $1 | cut -d: -f2` 3 | kglhd_var=0x`echo $1 | cut -d: -f3` 4 | padding=`echo $1 | cut -d: -f4` 5 | 6 | # ARGUMENT 1 and 3 of funtion pfrln0lookup have to be investigated in more detail for now i just put any address that s mapped to VAS of the target process 7 | line_var=`sqlplus / as sysdba <&1 | grep -i function | cut -d' ' -f4 8 | oradebug setmypid 9 | oradebug call pfrln0lookup 0x7ffff3c6bc38 $kglhd_var 0x7ffff3c6bc38 $offset_var 10 | exit; 11 | EOF` 12 | 13 | 14 | obj_var=`sqlplus / as sysdba <&1 | grep -i obj | tail -1 15 | SELECT 'Object : '||KGLNAOWN||'.'||KGLNAOBJ as name FROM "X\\$KGLOB" where to_number(KGLHDADR,'XXXXXXXXXXXXXXXX') = to_number(substr('$kglhd_var', instr(lower('$kglhd_var'), 'x')+1) ,'XXXXXXXXXXXXXXXX') ; 16 | exit; 17 | EOF` 18 | 19 | printf "%-`echo $padding`s" 20 | echo func : $func_var / line number : `echo $((16#$line_var))` / $obj_var 21 | -------------------------------------------------------------------------------- /sql_resolver2.sh: -------------------------------------------------------------------------------- 1 | var=`echo $1 | cut -d"|" -f4` 2 | state=`echo $1 | cut -d"|" -f1 ` 3 | offset_var=0x`echo $1 | cut -d"|" -f3` 4 | kglhd_var=0x`echo $1 | cut -d"|" -f4` 5 | time=`echo $1 | cut -d"|" -f2` 6 | depth=`echo $1 | cut -d"|" -f5` 7 | p_obj_var="" 8 | cur_depth=`cat current_depth` 9 | 10 | 11 | if [ -z $depth ] 12 | then 13 | depth=0 14 | fi 15 | 16 | if [ $var != 0 ] 17 | then 18 | 19 | cache_test=`grep "$kglhd_var $offset_var" cache_resolver` 20 | 21 | if [ -z "$cache_test" ] 22 | then 23 | 24 | # ARGUMENT 1 and 3 of funtion pfrln0lookup have to be investigated in more detail for now i just put any address that s mapped to VAS of the target process 25 | line_var=`sqlplus / as sysdba <&1 | grep -i function | cut -d' ' -f4 26 | oradebug setmypid 27 | oradebug call pfrln0lookup 0x7ffff3c6bc38 $kglhd_var 0x7ffff3c6bc38 $offset_var 28 | exit; 29 | EOF` 30 | 31 | 32 | obj_var=`sqlplus / as sysdba <&1 | grep "O:" | tail -1 | tr -d ';' 33 | SELECT 'O:'||KGLNAOWN||'.'||KGLNAOBJ as name FROM "X\\$KGLOB" where to_number(KGLHDADR,'XXXXXXXXXXXXXXXX') = to_number(substr('$kglhd_var', instr(lower('$kglhd_var'), 'x')+1) ,'XXXXXXXXXXXXXXXX') ; 34 | exit; 35 | EOF` 36 | 37 | if [ $cur_depth -gt 0 ] 38 | then 39 | for (( c=1; c<=$cur_depth; c++ )) 40 | do 41 | p_obj_var="$p_obj_var"`cat current_depth_s.$c`";" 42 | done 43 | fi 44 | 45 | if [ $depth -eq 99999 ] 46 | then 47 | echo $(($cur_depth - 1 )) > current_depth 48 | 49 | elif [ $depth -gt 1 ] 50 | then 51 | 52 | echo $obj_var`echo "("$((16#$line_var))`")" > current_depth_s.`echo $(($cur_depth + 1 ))` 53 | 54 | echo $(($cur_depth + 1 )) > current_depth 55 | 56 | 57 | fi 58 | 59 | if [ $cur_depth -gt 0 ] 60 | then 61 | echo "Line Tracker|"$time"|"$p_obj_var""$obj_var"("`echo $((16#$line_var))`")" 62 | else 63 | echo "Line Tracker|"$time"|"$obj_var"("`echo $((16#$line_var))`")" 64 | fi 65 | 66 | echo $kglhd_var $offset_var "/"$obj_var"("`echo $((16#$line_var))`")" >> cache_resolver 67 | 68 | else 69 | 70 | 71 | if [ $cur_depth -gt 0 ] 72 | then 73 | for (( c=1; c<=$cur_depth; c++ )) 74 | do 75 | p_obj_var="$p_obj_var"`cat current_depth_s.$c`";" 76 | done 77 | fi 78 | 79 | if [ $depth = 99999 ] 80 | then 81 | echo $(($cur_depth - 1 )) > current_depth 82 | 83 | elif [ $depth -gt 1 ] 84 | then 85 | 86 | echo `echo $cache_test | cut -d"/" -f2` > current_depth_s.`echo $(($cur_depth + 1 ))` 87 | 88 | echo $(($cur_depth + 1 )) > current_depth 89 | 90 | 91 | fi 92 | 93 | if [ $cur_depth -gt 0 ] 94 | then 95 | echo "Line Tracker|"$time"|"$p_obj_var`echo $cache_test | cut -d"/" -f2` 96 | else 97 | echo "Line Tracker|"$time"|"`echo $cache_test | cut -d"/" -f2` 98 | fi 99 | 100 | fi 101 | 102 | elif [ "$state" != "Line Tracker" ] 103 | then 104 | 105 | echo $state"|"$time"|0|0" 106 | 107 | fi 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /stapora.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | # 3 | # stapora.stp 4 | # 5 | # This script monitor the cpu and wait event of an oracle session 6 | # Usage: stap -v stapora.stp --all-modules -x "spid" "refresh_time(sec)" "wait_event_snap_time(msec)" 7 | # 8 | # Add the following line to translate wait event# to event_name (code developed by Luca Canali ): | sed -f eventsname.sed 9 | # To generate "eventsname.sed" run http://canali.web.cern.ch/canali/res/All_Files/stap_scripts/eventsname.sql 10 | # 11 | # 12 | # This script contains excerpt of code developed by : 13 | # Jason Baron and Josh Stone : https://sourceware.org/systemtap/examples/process/schedtimes.stp 14 | # Luca Canali : http://externaltable.blogspot.com/2014/09/systemtap-into-oracle-for-fun-and-profit.html 15 | # 16 | # Author : Hatem Mahmoud 17 | # BLOG : https://mahmoudhatem.wordpress.com 18 | # 19 | # Version stapora 1.0 BETA 20 | # Note: this is an experimental script, use at your own risk 21 | # 22 | # Functionality : 23 | # -Top wait events 24 | # -Wait events histograms 25 | # -Time spent on the run queue 26 | # -IO wait time 27 | # -Top kernel function 28 | # -Top user function 29 | # -Consistent Read by object 30 | # -Consistent Read elapsed time and cpu time 31 | # -Number of context switches 32 | 33 | 34 | 35 | global DEAD=-1, RUNNING=1, QUEUED=2, SLEEPING=3 36 | global kernel_func_call,user_func_call, pcount,sch_switch 37 | global run_time, queued_time, sleep_time, iowait_time 38 | global pid_state 39 | global sys_time ,user_time 40 | global previous_timestamp,prev_sys_time,prev_user_time 41 | global obj_cr,previous_cr_timestamp,dur_cr,in_cr_function,dur_cr_not_cpu,previous_cr_not_cpu_timestamp 42 | global pid_in_iowait 43 | global pid_iowait_count 44 | global session_addr = 0 45 | global session_id 46 | global session_waits 47 | global total_samples 48 | global event_num 49 | global eventlatency[2000] 50 | 51 | 52 | 53 | /* 54 | * Replace by the output of the folowing query to capture the precise offset 55 | * set linesize 190 pagesize 0; 56 | * select 'global ' || c.kqfconam ||' = ' || c.kqfcooff from x$kqfco c, x$kqfta t 57 | * where t.indx = c.kqfcotab 58 | * and t.kqftanam='X$KSUSECST' 59 | * and c.kqfconam in ('KSUSSTIM','KSUSENUM','KSUSSOPC') 60 | * order by c.kqfcooff; 61 | */ 62 | 63 | global KSUSSOPC = 5826 64 | global KSUSSTIM = 5856 65 | global KSUSENUM = 5920 66 | 67 | /* 68 | * You have to use the following query to determine interesting where location to probe for and replace them in 69 | * "( s64_arg(4) == 95 )": 70 | * SELECT indx 71 | * FROM x$ksllw 72 | * WHERE KSLLWLBL = 'session ptr' 73 | * AND KSLLWNAM like '%set busy%' 74 | * AND indx IN (SELECT indx 75 | * FROM x$kslwsc 76 | * WHERE KSLLASNAM = 'session idle bit'); 77 | */ 78 | 79 | probe process("oracle").function("ksl_get_shared_latch") { 80 | if (pid() == target() && session_addr == 0 && ( s64_arg(4) == 95 ) ) { 81 | session_addr = s64_arg(3) 82 | printf("Session initialized %d\n",pointer_arg(3)) 83 | } 84 | } 85 | 86 | 87 | @define in_iowait(task) %( 88 | @choose_defined(@task->in_iowait, 89 | (pid_in_iowait ? pid_in_iowait-- : 0)) 90 | %) 91 | 92 | @define clear_iowait(rq, task) %( 93 | if (!@defined(@task->in_iowait)) 94 | pid_iowait_count = @nr_iowait(@rq) 95 | %) 96 | 97 | @define set_iowait(rq, task) %( 98 | if (!@defined(@task->in_iowait)) 99 | pid_in_iowait = (@nr_iowait(@rq) > pid_iowait_count) 100 | %) 101 | 102 | @define nr_iowait(rq) %( 103 | atomic_read(&@cast(@rq, "rq")->nr_iowait) 104 | %) 105 | 106 | 107 | function timestamp() 108 | { 109 | return gettimeofday_us() 110 | } 111 | 112 | probe process("oracle").function("kcbgtcr") 113 | { 114 | if (pid() == target()) { 115 | in_cr_function=1 116 | obj_cr[user_int32(u64_arg(1)+8)/1] <<< 1 117 | previous_cr_timestamp = timestamp() 118 | 119 | } 120 | } 121 | 122 | 123 | %(kernel_v>="3.10" %? 124 | probe process("oracle").function("kcbgtcr").return 125 | { 126 | if (pid() == target()) { 127 | in_cr_function=0 128 | dur_cr <<< timestamp() - previous_cr_timestamp 129 | } 130 | } 131 | %) 132 | 133 | function update_times(now) 134 | { 135 | delta = now - previous_timestamp 136 | previous_timestamp = now 137 | 138 | if ((state = pid_state) > 0) { 139 | if (state == SLEEPING) 140 | sleep_time += delta 141 | else if (state == QUEUED) 142 | queued_time += delta 143 | else if (state == RUNNING) 144 | run_time += delta 145 | } 146 | 147 | return delta 148 | } 149 | 150 | probe timer.profile { 151 | if (target() == pid()) 152 | { 153 | pcount <<< 1 154 | if ( user_mode() == 1) 155 | { 156 | user_func_call[usymname(ustack(0))] <<< 1 157 | } 158 | else 159 | { 160 | kernel_func_call[symname(stack(0))] <<< 1 161 | } 162 | } 163 | } 164 | 165 | probe timer.ms($2) { 166 | 167 | # Profiling wait events 168 | if ( session_addr > 0 ) 169 | { 170 | if (pid_state == RUNNING) //If session is in the runqueue then it'is the same wait event 171 | { 172 | sess_id = user_uint16(session_addr + KSUSENUM) 173 | wait_time = user_uint32(session_addr + KSUSSTIM) 174 | event_num = user_uint32(session_addr + KSUSSOPC) 175 | //If succefuly captured wait event number 176 | if (event_num != 0 ) 177 | { 178 | total_samples <<< 1 179 | 180 | session_id = sess_id 181 | if (wait_time == 0 ) 182 | { 183 | session_waits[event_num] <<< 1 184 | } 185 | else 186 | { 187 | session_waits[-1] <<< 1 188 | } 189 | } 190 | } 191 | else 192 | { 193 | session_waits[event_num] <<< 1 194 | total_samples <<< 1 195 | } 196 | } 197 | 198 | } 199 | 200 | probe process("oracle").function("kskthewt") { 201 | # Wait events histogram 202 | if ( session_addr > 0 ) 203 | { 204 | 205 | ksuseopc = user_uint32(session_addr + KSUSSOPC) 206 | ksusetim = user_uint32(session_addr + KSUSSTIM) 207 | eventlatency[ksuseopc] <<< ksusetim 208 | 209 | } 210 | } 211 | 212 | probe scheduler.ctxswitch 213 | { 214 | // Task $prev is scheduled off this cpu 215 | if ($prev->pid == target()) { 216 | 217 | if (in_cr_function == 1) 218 | { 219 | previous_cr_not_cpu_timestamp=timestamp() 220 | } 221 | //check the last wait event before going to the runqueue 222 | if ( session_addr > 0 ) 223 | { 224 | event_num = user_uint32(session_addr + KSUSSOPC) 225 | } 226 | 227 | sch_switch <<< cpu() 228 | 229 | state = $prev->state 230 | update_times(timestamp()) 231 | 232 | if(@defined($prev->utime)) { 233 | 234 | //Calculate user_time and cpu_time delta using cpu clock tick 235 | user_time <<< ($prev->utime - prev_user_time) 236 | prev_user_time=$prev->utime 237 | sys_time <<< ($prev->stime - prev_sys_time) 238 | prev_sys_time=$prev->stime 239 | } 240 | 241 | if (state > 0) { 242 | @set_iowait($rq, $prev) 243 | pid_state = SLEEPING 244 | } else if (state == 0) { 245 | pid_state = QUEUED 246 | } else { 247 | pid_state = DEAD 248 | } 249 | } 250 | 251 | // Task $next is scheduled onto this cpu 252 | if ($next->pid == target() ) { 253 | 254 | if (in_cr_function == 1) 255 | { 256 | dur_cr_not_cpu = (timestamp() - previous_cr_not_cpu_timestamp ) + dur_cr_not_cpu 257 | } 258 | 259 | sch_switch <<< cpu() 260 | 261 | update_times(timestamp()) 262 | @clear_iowait($rq, $next) 263 | pid_state = RUNNING 264 | } 265 | } 266 | 267 | probe scheduler.wakeup 268 | { 269 | // Task $p is awakened 270 | if ($p->pid == target()) { 271 | delta = update_times(timestamp()) 272 | if (pid_state == SLEEPING && @in_iowait($p)) { 273 | iowait_time += delta 274 | } 275 | pid_state = QUEUED 276 | } 277 | } 278 | 279 | 280 | probe timer.s($1) 281 | { 282 | printf ("\n====================================================================================\n") 283 | printf ("================================= StapOra V1.0 BETA ================================") 284 | printf ("\n====================================================================================\n") 285 | printf ("\n%6s : %16s %16s %20s %16s %16s %10s %10s \n\n", 286 | "pid", "run(us)", "sleep(us)", "iowait(us)", 287 | "queued(us)", "total(us)","user_time(%)","sys_time(%)") 288 | update_times(timestamp()) 289 | 290 | 291 | ratio_sys=10000 * @sum(sys_time) / ( @sum(user_time) + @sum(sys_time) +1 ) 292 | ratio_user=10000 * @sum(user_time) / ( @sum(user_time) + @sum(sys_time) +1 ) 293 | ratio_run_time=10000 * run_time /(run_time + sleep_time + queued_time +1) 294 | ratio_sleep_time=10000 * sleep_time /(run_time + sleep_time + queued_time +1) 295 | ratio_iowait_time=10000 * iowait_time/(run_time + sleep_time + queued_time +1) 296 | ratio_queued_time=10000 * queued_time /(run_time + sleep_time + queued_time +1) 297 | 298 | printf("%6d : %10d(%2d.%02d %s) %10d(%2d.%02d %s) %5d(%2d.%02d %s) %10d(%2d.%02d %s) %10d %8d.%02d %8d.%02d \n",target(), 299 | run_time,ratio_run_time/100,ratio_run_time%100,"%",sleep_time,ratio_sleep_time/100,ratio_sleep_time%100,"%", iowait_time,ratio_iowait_time/100,ratio_iowait_time%100,"%",queued_time, 300 | ratio_queued_time/100,ratio_queued_time%100,"%", (run_time + sleep_time + queued_time),ratio_user/100,ratio_user%100,ratio_sys/100,ratio_sys%100) 301 | 302 | 303 | 304 | printf ("\n---------------------------------------------------------\n") 305 | printf ("------- Oracle wait events/CPU (CPU WAIT)----------------\n") 306 | printf ("---------------------------------------------------------\n") 307 | if ( session_addr > 0 ) 308 | { 309 | printf("Total samples : %d\n",@count(total_samples)) 310 | foreach ([w] in session_waits- limit 5) { 311 | event_ratio = 10000 * @count(session_waits[w]) / @count(total_samples) 312 | if ( w == -1 ) { 313 | printf ("%2d.%02d %s samples CPU/CPU WAIT \n",event_ratio/100,event_ratio%100,"%") 314 | } else { 315 | printf ("%2d.%02d %s samples event#=%ld \n",event_ratio/100,event_ratio%100,"%",w) 316 | } 317 | } 318 | delete session_waits 319 | delete total_samples 320 | } 321 | else 322 | { 323 | printf("No wait events captured (Session not initialized yet)\n"); 324 | } 325 | printf ("\n---------------------------------------------------------\n") 326 | printf ("------- Oracle wait events histograms (microsec)-----------\n") 327 | printf ("---------------------------------------------------------\n") 328 | 329 | foreach ([event] in eventlatency) { 330 | printf("Latency histogram for event#=%d\n",event) 331 | print(@hist_log(eventlatency[event])) 332 | } 333 | 334 | 335 | printf ("\n--- %d samples recorded:\n", @count(pcount)) 336 | 337 | printf ("---------------------------------------------------------\n") 338 | printf ("------- Top 5 Kernel space Functions --------------------\n") 339 | printf ("---------------------------------------------------------\n") 340 | foreach ([p] in kernel_func_call- limit 5) { 341 | printf ("%d hits : %s \n\n", @count(kernel_func_call[p]),p) 342 | } 343 | 344 | printf ("---------------------------------------------------------\n") 345 | printf ("------- Top 5 user space Functions ----------------------\n") 346 | printf ("---------------------------------------------------------\n") 347 | foreach ([p] in user_func_call- limit 5) { 348 | printf ("%d hits : %s \n\n", @count(user_func_call[p]), p) 349 | } 350 | printf ("---------------------------------------------------------\n") 351 | printf ("------- Scheduler Switches per CPU ----------------------\n") 352 | printf ("---------------------------------------------------------\n") 353 | if( @count(sch_switch) > 0 ) { 354 | print(@hist_linear(sch_switch, 0, 10, 1)) 355 | } 356 | 357 | 358 | printf ("\n---------------------------------------------------------\n") 359 | 360 | cr_ratio_run_time=10000 * (@sum(dur_cr)-dur_cr_not_cpu) /(run_time + 1 ) 361 | cr_ratio_elapsed_time=10000 * @sum(dur_cr) /(run_time + sleep_time + queued_time +1) 362 | 363 | printf("Total cr elapsed time : %6d (%2d.%02d %s from Total elapsed time) \n",@sum(dur_cr),cr_ratio_elapsed_time/100,cr_ratio_elapsed_time%100,"%") 364 | printf("Total cr cpu time : %6d (%2d.%02d %s from Total cpu time) \n",(@sum(dur_cr)-dur_cr_not_cpu),cr_ratio_run_time/100,cr_ratio_run_time%100,"%") 365 | 366 | printf ("---------------------------------------------------------\n") 367 | printf ("------- Object number and cr I/O count ------------------\n") 368 | printf ("---------------------------------------------------------\n") 369 | 370 | foreach ([m] in obj_cr+ ) { 371 | printf ("cr=%d obj_n=%d \n", @count(obj_cr[m]), m) 372 | } 373 | 374 | printf ("---------------------------------------------------------\n") 375 | printf ("------- CR I/O duration hist(us) ------------------------\n") 376 | printf ("---------------------------------------------------------\n") 377 | %(kernel_v>="3.10" %? 378 | if( @count(dur_cr) > 0 ) { 379 | print(@hist_log(dur_cr)) 380 | } 381 | %: 382 | printf ("------- You need at least kernel version >= 3.10 --------\n") 383 | %) 384 | 385 | delete kernel_func_call 386 | delete user_func_call 387 | delete pcount 388 | delete sch_switch 389 | delete run_time 390 | delete queued_time 391 | delete sleep_time 392 | delete iowait_time 393 | delete sys_time 394 | delete user_time 395 | delete obj_cr 396 | delete dur_cr 397 | delete dur_cr_not_cpu 398 | delete eventlatency 399 | 400 | } 401 | -------------------------------------------------------------------------------- /trace_mem_alloc.stp: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env stap 2 | # 3 | # trace_mem_alloc.stp 4 | # 5 | # From memory request to PL/SQL source line 6 | # Usage: stap -v trace_mem_alloc.stp -x 4597 '"pmuccst: adt/record"' 5 | xargs -i ./trace_mem_alloc_resov.sh {} 7 | # 8 | # Author : Hatem Mahmoud 9 | # BLOG : https://mahmoudhatem.wordpress.com 10 | # 11 | # Based on Stefan Koehler dtrace script : http://www.soocs.de/public/scripts/dtrace_kghal_pga_code 12 | # 13 | # Tested in oracle 12.2.0.1 14 | # Note: this is an experimental script, use at your own risk 15 | 16 | 17 | global plsql_run_addr,monitor,inst_offset,KGLHDADR_1 18 | global allocation_tracker 19 | 20 | 21 | #PL/SQL begin execution 22 | probe process("oracle").function("plsql_run").call { 23 | plsql_run_addr = register("rdi"); 24 | monitor = 1; 25 | } 26 | 27 | #PL/SQL end execution 28 | probe process("oracle").function("plsql_run").return { 29 | monitor = 0; 30 | } 31 | 32 | 33 | #Tracing PL/SQL functions 34 | probe process("oracle").function("p*") 35 | { 36 | 37 | if ( monitor == 1 ) { 38 | 39 | current_addr = plsql_run_addr+120; 40 | base_addr1 = plsql_run_addr+144; 41 | base_addr2 = user_int64(base_addr1); 42 | base_addr3 = user_int64(base_addr2)+264; 43 | KGLHDADR = user_int64(base_addr2)+104; 44 | 45 | inst_offset = user_int64(current_addr) - user_int64(user_int64(base_addr3)) 46 | KGLHDADR_1 = user_int64(KGLHDADR); 47 | 48 | } 49 | 50 | } 51 | 52 | 53 | probe process("oracle").function("kghalf").call,process("oracle").function("kghalp").call 54 | { 55 | 56 | if ( monitor == 1 && isinstr(user_string(pointer_arg(6)), $1)==1 ) { 57 | allocation_tracker[KGLHDADR_1,inst_offset] <<< 1 58 | } 59 | } 60 | 61 | 62 | probe process("oracle").function("kghalo").call 63 | { 64 | if ( monitor == 1 && isinstr(user_string(pointer_arg(9)), $1)==1 ) { 65 | allocation_tracker[KGLHDADR_1,inst_offset] <<< 1 66 | } 67 | } 68 | 69 | 70 | 71 | probe timer.s($2) { 72 | 73 | printf(":--------------------------------------------------------:\n"); 74 | printf(":PL/SQL line tracker for memory allocation reason : %s\n",$1); 75 | printf(":--------------------------------------------------------:\n"); 76 | foreach ([a,b] in allocation_tracker+ ) { 77 | printf ("%d:%x:%x \n", @count(allocation_tracker[a,b]), a,b); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /trace_mem_alloc_resov.sh: -------------------------------------------------------------------------------- 1 | count=`echo $1 | cut -d: -f1 ` 2 | offset_var=0x`echo $1 | cut -d: -f3` 3 | kglhd_var=0x`echo $1 | cut -d: -f2` 4 | 5 | if [ "$count" == "" ] 6 | then 7 | echo $1 8 | exit; 9 | fi 10 | 11 | # ARGUMENT 1 and 3 of funtion pfrln0lookup have to be investigated in more detail for now i just put any address that s mapped to VAS of the target process 12 | 13 | line_var=`sqlplus / as sysdba <&1 | grep -i function | cut -d' ' -f4 14 | oradebug setmypid 15 | oradebug call pfrln0lookup $kglhd_var $kglhd_var $kglhd_var $offset_var 16 | exit; 17 | EOF` 18 | obj_var=`sqlplus / as sysdba <&1 | grep -i obj | tail -1 19 | SELECT 'Object : '||KGLNAOWN||'.'||KGLNAOBJ as name FROM "X\\$KGLOB" where to_number(KGLHDADR,'XXXXXXXXXXXXXXXX') = to_number(substr('$kglhd_var', instr(lower('$kglhd_var'), 'x')+1) ,'XXXXXXXXXXXXXXXX') ; 20 | exit; 21 | EOF` 22 | echo $obj_var / line number : `echo $((16#$line_var))` / count : $count 23 | -------------------------------------------------------------------------------- /trace_plsql_func_args.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # trace_plsql_func_args.sh 4 | # 5 | # This script trace PL/SQL calls with arguments 6 | # Usage: ./trace_plsql_func_args.sh PID DELAY 7 | # 8 | # Author : Hatem Mahmoud 9 | # BLOG : https://mahmoudhatem.wordpress.com 10 | # 11 | # Tested in oracle 12.2.0.1 12 | # Note: this is an experimental script, use at your own risk 13 | 14 | 15 | #Cleaning up 16 | perf probe --del probe_oracle:pfrinstr_MOVAN 2> /dev/null 17 | perf probe --del probe_oracle:pfrinstr_MOVAN_2 2> /dev/null 18 | perf probe --del probe_oracle:pfrinstr_MOVAN_3 2> /dev/null 19 | perf probe --del probe_oracle:pfrinstr_MOVA 2> /dev/null 20 | perf probe --del probe_oracle:pevm_ENTER 2> /dev/null 21 | perf probe --del probe_oracle:pevm_ENTER_1 2> /dev/null 22 | 23 | 24 | #TRACING ONE ARGUMENT 25 | perf probe -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pfrinstr_MOVA+38 '+0(+0(+0(%cx)))' '+0(+0(+0(%cx)))':"string" 2> /dev/null 26 | 27 | #TRACING MULTI ARGUMENTS 28 | 29 | perf probe -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pfrinstr_MOVAN+60 '+0(+0(+0(%r10)))' '+0(+0(+0(%r10)))':"string" 2> /dev/null 30 | perf probe -f -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pfrinstr_MOVAN+77 '+0(+0(+0(%r9)))' '+0(+0(+0(%r9)))':"string" 2> /dev/null 31 | perf probe -f -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pfrinstr_MOVAN+112 '+0(+0(+0(%cx)))' '+0(+0(+0(%cx)))':"string" 2> /dev/null 32 | 33 | #TRACING function call 34 | 35 | perf probe -f -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pevm_ENTER+365 SOBJ=%dx:"s32" 2> /dev/null 36 | perf probe -f -x /app/oracle/product/12.2.0/dbhome_1/bin/oracle pevm_ENTER+396 OBJ=%r9:"s32" 2> /dev/null 37 | 38 | 39 | echo "------------------------------------------" 40 | echo "Tracing has just begin for $2 seconds" 41 | echo "------------------------------------------" 42 | 43 | 44 | perf record -e probe_oracle:pfrinstr_MOVA -e probe_oracle:pfrinstr_MOVAN -e probe_oracle:pfrinstr_MOVAN_2 -e probe_oracle:pfrinstr_MOVAN_3 -e probe_oracle:pevm_ENTER -e probe_oracle:pevm_ENTER_1 -p $1 sleep 45 | $2 46 | 47 | 48 | #Cleaning up 49 | perf probe --del probe_oracle:pfrinstr_MOVAN 2> /dev/null 50 | perf probe --del probe_oracle:pfrinstr_MOVAN_2 2> /dev/null 51 | perf probe --del probe_oracle:pfrinstr_MOVAN_3 2> /dev/null 52 | perf probe --del probe_oracle:pfrinstr_MOVA 2> /dev/null 53 | perf probe --del probe_oracle:pevm_ENTER 2> /dev/null 54 | perf probe --del probe_oracle:pevm_ENTER_1 2> /dev/null 55 | 56 | 57 | perf script > out_to_parse 58 | 59 | arg="" 60 | func="" 61 | arg_s="" 62 | 63 | while read p; do 64 | 65 | probe=`echo $p | cut -d' ' -f5` 66 | 67 | if [ "$probe" == "probe_oracle:pevm_ENTER:" ] 68 | then 69 | func=`echo $p | cut -d' ' -f7` 70 | elif [ "$probe" == "probe_oracle:pevm_ENTER_1:" ] 71 | then 72 | func=`echo $p | cut -d' ' -f7`" "$func 73 | if [ "$func" != "OBJ=0 SOBJ=1" ] 74 | then 75 | echo "$func" "(" "$arg" ") to_string -> (" "$arg_s" ")" |sed -f plsql_obj.sed 76 | fi 77 | func="" 78 | arg="" 79 | arg_s="" 80 | else 81 | arg=$arg","`echo $p | cut -d' ' -f7 | cut -d'=' -f2` 82 | arg_s=$arg_s","`echo $p | cut -d' ' -f8 | cut -d'=' -f2` 83 | 84 | 85 | fi 86 | 87 | done < out_to_parse 88 | -------------------------------------------------------------------------------- /where_why_decode.sql: -------------------------------------------------------------------------------- 1 | set echo off pages 0 lines 200 feed off head off sqlblanklines off trimspool on trimout on 2 | 3 | spool where_why_decode.sed 4 | 5 | select 's/\/'||'where='||replace(KSLLWNAM,'/','\/')||' \(why='||replace(KSLLWLBL,'/','\/')||'\)/g' SED from x$ksllw ; 6 | 7 | spool off 8 | exit 9 | -------------------------------------------------------------------------------- /write_consistency.stp: -------------------------------------------------------------------------------- 1 | probe process("oracle").function("kcbgtcr") { 2 | if ( user_int32(u64_arg(1)+8) == $1 ) { 3 | printf("Cr: block#=%d \n",user_int32(u64_arg(1)+4) & 0x003FFFFF) 4 | } 5 | } 6 | 7 | 8 | 9 | probe process("oracle").function("kcbgcur") { 10 | if ( user_int32(u64_arg(1)+8) == $1 ) { 11 | printf("Cur: block#=%d \n",user_int32(u64_arg(1)+4) & 0x003FFFFF) 12 | } 13 | } 14 | 15 | 16 | probe process("oracle").function("dmlTrace") { 17 | printf("Write consistency issue detected\n"); 18 | } 19 | 20 | 21 | 22 | probe process("oracle").function("kturRbkToSvpt") { 23 | printf("Issue rollback to savepoint \n"); 24 | } 25 | 26 | 27 | probe syscall.write { 28 | if (pid() == target() && isinstr(argstr,"phase") ) { 29 | printf(" %s \n", argstr) 30 | } 31 | --------------------------------------------------------------------------------