2026-03-12 20:23:15
This commit is contained in:
69
tpt/dtrace/dstackprof.sh
Normal file
69
tpt/dtrace/dstackprof.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/ksh
|
||||
#
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
#################################################################################
|
||||
#
|
||||
# File name: dstackprof.sh v1.02 29-Aug-2008
|
||||
# Purpose: Samples target process stack using DTrace, strips the PC function
|
||||
# offsets from output and re-aggregates
|
||||
#
|
||||
# Author: Tanel Poder
|
||||
# Copyright: (c) http://www.tanelpoder.com
|
||||
#
|
||||
# Usage: dstackprof.sh <PID> [SECONDS] [STACKS] [FRAMES]
|
||||
#
|
||||
#
|
||||
# Other:
|
||||
#
|
||||
#
|
||||
#
|
||||
#################################################################################
|
||||
|
||||
DEFAULT_SECONDS=5
|
||||
DEFAULT_FRAMES=100
|
||||
DEFAULT_STACKS=20
|
||||
|
||||
FREQUENCY=1001
|
||||
|
||||
[ $# -lt 1 ] && echo " Usage: $0 <PID> [SECONDS] [STACKS] [FRAMES]\n" && exit 1
|
||||
[ -z $2 ] && SECONDS=$DEFAULT_SECONDS || SECONDS=$2
|
||||
[ -z $3 ] && STACKS=$DEFAULT_STACKS || STACKS=$3
|
||||
[ -z $4 ] && FRAMES=$DEFAULT_FRAMES || FRAMES=$4
|
||||
PROCESS=$1
|
||||
|
||||
echo
|
||||
echo "DStackProf v1.02 by Tanel Poder ( http://www.tanelpoder.com )"
|
||||
echo "Sampling pid $PROCESS for $SECONDS seconds with stack depth of $FRAMES frames..."
|
||||
echo
|
||||
|
||||
dtrace -q -p $PROCESS -n '
|
||||
profile-'$FREQUENCY'
|
||||
/pid == $target/ {
|
||||
@u[ustack('$FRAMES')] = count();
|
||||
@k[stack('$FRAMES')] = count();
|
||||
}
|
||||
tick-1sec
|
||||
/i++ >= '$SECONDS'/ {
|
||||
exit(0);
|
||||
}
|
||||
END {
|
||||
printa(@u);
|
||||
printa(@k);
|
||||
}
|
||||
' | sed 's/^ *//;/^$/d;s/+.*$//;s/^oracle`//g' | \
|
||||
awk '/^$/{ printf "\n" }/^[0-9]*$/{ printf ";%s\n", $1 }/[a-z]/{ printf "%s<", $1 }END{ printf "\n" }' | \
|
||||
sed '/^;/d' | \
|
||||
sort | \
|
||||
awk -F";" '
|
||||
/NR==1/{ sum=0; total=0; oldstack=$1 }
|
||||
{
|
||||
if (oldstack==$1) {sum+=$2;total+=$2}
|
||||
else {printf "%d samples with stack below<__________________<%s\n", sum, oldstack; oldstack=$1; sum=$2; total+=$2}
|
||||
}
|
||||
END {printf "%d samples with stack below<__________________<%s\n%d Total samples captured\n", sum, oldstack, total}
|
||||
' | \
|
||||
sort -bn | \
|
||||
tail -$((STACKS+1)) | \
|
||||
tr '<' '\n'
|
||||
|
||||
96
tpt/dtrace/enq_trace.sh
Normal file
96
tpt/dtrace/enq_trace.sh
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/bin/ksh
|
||||
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
#--------------------------------------------------------------------------------
|
||||
#--
|
||||
#-- File name: enq_trace.sh
|
||||
#-- Purpose: Trace specific enqueue lock gets and process activity during
|
||||
#-- lock holding to find out why exactly was a lock taken and why
|
||||
#-- hasn't it been released fast enough. This script should be used
|
||||
#-- only when conventional troubleshooting mechanisms
|
||||
#-- (v$ views, ASH, hanganalyze, systemstate dumps) do not give
|
||||
#-- enough relevant details about the hang
|
||||
#--
|
||||
#-- Author: Tanel Poder
|
||||
#-- Copyright: (c) http://www.tanelpoder.com
|
||||
#--
|
||||
#-- Other: EXPERIMENTAL! This script needs reviewinng and adjustment,
|
||||
#-- case by case. It's meant for diagnosing very specific hangs
|
||||
#-- and you need to know what you're doing before running it in
|
||||
#-- production
|
||||
#--
|
||||
#--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Set the lock type# we want to trace (should be 22 for CF enqueue on 11.1.0.7 and 18 on 10.2.0.3)
|
||||
LOCK_TYPE=18
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# -- You can verify what's the correct lock type# for CF enqueue
|
||||
# -- using this query (run as SYS). Set the LOCK_TYPE variable
|
||||
# -- above to match the result of the query
|
||||
# ---------------------------------------------------------------
|
||||
# select
|
||||
# i
|
||||
# from
|
||||
# (
|
||||
# select
|
||||
# rest.indx i,
|
||||
# rest.resname type
|
||||
# from X$KSIRESTYP rest, X$KSQEQTYP eqt
|
||||
# where (rest.inst_id = eqt.inst_id)
|
||||
# and (rest.indx = eqt.indx)
|
||||
# and (rest.indx > 0)
|
||||
# )
|
||||
# where
|
||||
# type = 'CF'
|
||||
# /
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
PID=$1
|
||||
echo Tracing PID $PID `ps -ocomm -p $PID | grep -v COMMAND`
|
||||
|
||||
dtrace $LOCK_TYPE -p $PID -qn '
|
||||
/* ring buffer policy probably not needed due low trace volume so its commented out
|
||||
#pragma D option bufpolicy=ring
|
||||
#pragma D option bufsize=256k
|
||||
*/
|
||||
|
||||
pid$target:oracle:ksqgtlctx:entry
|
||||
/arg4 == $1/
|
||||
{
|
||||
gettime=timestamp;
|
||||
enqHolder = pid;
|
||||
enqAddress = arg0;
|
||||
printf("%d [%Y] getting enqueue: pid=%d proc=%s enqAddress=0x%x locktype#=%d get_stack={", gettime, walltimestamp, pid, curpsinfo->pr_psargs, enqAddress, arg4);
|
||||
ustack(50);
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
pid$target:oracle:ksqrcl:entry
|
||||
/arg0 == enqAddress/ {
|
||||
printf("%d [%Y] releasing enqueue: pid=%d proc=%s enqAddress=0x%x usec_held=%d\n", timestamp, walltimestamp, pid, curpsinfo->pr_psargs, arg0, (timestamp-gettime)/1000);
|
||||
enqAddress = 0;
|
||||
}
|
||||
|
||||
pid$target:oracle:kslwtb_tm:entry
|
||||
/enqAddress && enqHolder == pid/ {
|
||||
currentWait = arg0;
|
||||
}
|
||||
|
||||
pid$target:oracle:kslwte_tm:return
|
||||
/enqAddress && enqHolder == pid/ {
|
||||
currentWait = 0;
|
||||
}
|
||||
|
||||
tick-1sec
|
||||
/enqAddress/
|
||||
{
|
||||
printf("%d [%Y] still holding enqueue: pid=%d proc=%s enqAddress=0x%x current_wait=%d current_stack={", timestamp, walltimestamp, pid, curpsinfo->pr_psargs, enqAddress, currentWait);
|
||||
stack(50);
|
||||
ustack(50);
|
||||
printf("}\n");
|
||||
}
|
||||
'
|
||||
|
||||
31
tpt/dtrace/qd
Normal file
31
tpt/dtrace/qd
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/ksh
|
||||
|
||||
# "Quick Dtrace" script by Tanel Poder (http://www.tanelpoder.com)
|
||||
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
PROCESS=$1
|
||||
shift
|
||||
|
||||
for F in $* ; do
|
||||
|
||||
FUNCLIST_ENTRY=${FUNCLIST_ENTRY}",pid\$target::$F:entry"
|
||||
FUNCLIST_RETURN=${FUNCLIST_RETURN}",pid\$target::$F:return"
|
||||
|
||||
done
|
||||
|
||||
FUNCLIST_ENTRY=`echo "$FUNCLIST_ENTRY" | sed 's/^,//'`
|
||||
FUNCLIST_RETURN=`echo "$FUNCLIST_RETURN" | sed 's/^,//'`
|
||||
|
||||
echo $FUNCLIST_ENTRY
|
||||
echo $FUNCLIST_RETURN
|
||||
|
||||
#dtrace -p $PROCESS -Fn $FUNCLIST"{ trace(probefunc); trace(arg0); trace(arg1); trace(arg2); trace(arg3); }"
|
||||
#dtrace -p $PROCESS -Fn $FUNCLIST'{ printf("%16x %16x %16x %16x %16x %16x", arg0, arg1, arg2, arg3, arg4, arg5); }'
|
||||
#dtrace -p $PROCESS -Fn $FUNCLIST'{ printf("%s %16x %16x %16x %16x %16x", copyinstr(arg0), arg1, arg2, arg3, arg4, arg5); }'
|
||||
|
||||
dtrace -Zp $PROCESS -Fn \
|
||||
$FUNCLIST_ENTRY'{ printf("%16x ", arg0 ); }'\
|
||||
$FUNCLIST_RETURN'{ printf("%16x", arg1); }'
|
||||
|
||||
|
||||
31
tpt/dtrace/qda
Normal file
31
tpt/dtrace/qda
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/ksh
|
||||
|
||||
# "Quick Dtrace" script by Tanel Poder (http://www.tanelpoder.com)
|
||||
# (qda prints first 6 function arguments for function calls)
|
||||
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
#$FUNCLIST_ENTRY'{ printf("%16x %16x %16x %16x %16x %16x", arg0, arg1, arg2, arg3, arg4, arg5); }'\
|
||||
|
||||
PROCESS=$1
|
||||
shift
|
||||
|
||||
for F in $* ; do
|
||||
|
||||
FUNCLIST_ENTRY=${FUNCLIST_ENTRY}",pid\$target::$F:entry"
|
||||
FUNCLIST_RETURN=${FUNCLIST_RETURN}",pid\$target::$F:return"
|
||||
|
||||
done
|
||||
|
||||
FUNCLIST_ENTRY=`echo "$FUNCLIST_ENTRY" | sed 's/^,//'`
|
||||
FUNCLIST_RETURN=`echo "$FUNCLIST_RETURN" | sed 's/^,//'`
|
||||
|
||||
echo $FUNCLIST
|
||||
|
||||
#$FUNCLIST_ENTRY'{ printf("%16x %16x %16x %16x %16x %16x", arg0, arg1, arg2, arg3, arg4, arg5); }'
|
||||
|
||||
dtrace -p $PROCESS -Fn \
|
||||
$FUNCLIST_ENTRY'{ printf("%x %x %x %x %x %x", arg0, arg1, arg2, arg3, arg4, arg5); }'\
|
||||
$FUNCLIST_RETURN'{ printf("%x", arg1); }'
|
||||
|
||||
68
tpt/dtrace/qer_trace.sh
Normal file
68
tpt/dtrace/qer_trace.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
# Name: qer_trace.sh - Query Execution Row-source Trace script
|
||||
# Version: 0.2
|
||||
# Author: Tanel Poder (http://blog.tanelpoder.com)
|
||||
#
|
||||
# Notes: Comment out the kcbgtcr:entry and kcbgtcr:return functions if you
|
||||
# want to reduce the amount of output this script generates or see the
|
||||
# output being indented more and more to the right without returning
|
||||
# (dtrace doesn't recognize the return call in some cases)
|
||||
|
||||
dtrace -Fp $1 -n '
|
||||
|
||||
pid$target:oracle:opifch*:entry
|
||||
{}
|
||||
|
||||
pid$target:oracle:opifch*:return
|
||||
{ printf("= %x", arg1) }
|
||||
|
||||
struct qer_rws {
|
||||
uint16_t rws_id;
|
||||
uint16_t rws_parent;
|
||||
};
|
||||
|
||||
struct qer_rws op;
|
||||
|
||||
pid$target:oracle:qer*Fetch*:entry
|
||||
/*, pid$target:oracle:kpofcr:entry
|
||||
, pid$target:oracle:rwsfcd:entry */
|
||||
{
|
||||
op.rws_parent = *(uint32_t *)copyin(arg0,2);
|
||||
op.rws_id = *(uint32_t *)copyin(arg0+2,2);
|
||||
printf("op=%d par=%d rows=%d", op.rws_id, op.rws_parent, arg4)
|
||||
|
||||
}
|
||||
|
||||
pid$target:oracle:qer*Fetch*:return
|
||||
/*, pid$target:oracle:kpofcr:return
|
||||
, pid$target:oracle:rwsfcd:return */
|
||||
{ printf("= %d", arg1) }
|
||||
|
||||
|
||||
struct kcb_dba_t {
|
||||
uint32_t ts;
|
||||
uint16_t rfile;
|
||||
uint32_t block;
|
||||
};
|
||||
|
||||
struct kcb_dba_t dba;
|
||||
|
||||
pid$target:oracle:kcbgtcr:entry
|
||||
{
|
||||
|
||||
dba.ts = *(uint32_t *) copyin(arg0,4);
|
||||
dba.rfile = *(uint32_t *) copyin(arg0+4,4) >> 22 & 0x000003FF ;
|
||||
dba.block = *(uint32_t *) copyin(arg0+4,4) & 0x003FFFFF ;
|
||||
|
||||
printf("ts=%d rfile=%x block=%d %x x$kcbwh.indx=%x", dba.ts, dba.rfile, dba.block, arg1,arg2);
|
||||
|
||||
}
|
||||
|
||||
pid$target:oracle:kcbgtcr:return
|
||||
{ printf("= %x %x", arg0, arg1) }
|
||||
|
||||
'
|
||||
19
tpt/dtrace/trace_kghal.sh
Normal file
19
tpt/dtrace/trace_kghal.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/bin/ksh
|
||||
|
||||
# Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
# Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
dtrace -F -q -p $1 -n '
|
||||
pid$target::kghalf:entry,pid$target::kghalp:entry {
|
||||
from_heap=arg1; comment_ptr=arg5;
|
||||
printf("(%s(%x), \"%s\")\n", copyinstr(from_heap+76),from_heap,copyinstr(comment_ptr));
|
||||
}
|
||||
pid$target::kghalo:entry {
|
||||
from_heap=arg1; comment_ptr=arg8;
|
||||
printf("(%s(%x), \"%s\")\n", copyinstr(from_heap+76),from_heap,copyinstr(comment_ptr));
|
||||
}
|
||||
|
||||
|
||||
pid$target::kghalf:return,pid$target::kghalp:return,pid$target::kghalo:return {
|
||||
printf("= %x\n", arg1);
|
||||
}
|
||||
'
|
||||
Reference in New Issue
Block a user