/* * sql_oracle_client.d * * This DTrace script extracts embedded SQL statements from 32-bit Oracle * client applications. It uses the PID provider to grab the "sqlcxt" * call which is part of Oracle's libclntsh.so. This call takes several * arguments, one of which is a pointer to a "sqlexd" structure, which has * an element that is a "char *" to the SQL statement. The script displays * the SQL statements as they are executed, as well as aggregates on the * count of each statement and the time-to-complete distribution. * * To run this, use the -32 argument since it's a 32-bit app: * * # dtrace -32 -q -s sql_oracle_client.d pid-of-oracle-client */ static struct sqlexd { unsigned int sqlvsn; unsigned int arrsiz; unsigned int iters; unsigned int offset; unsigned short selerr; unsigned short sqlety; unsigned int occurs; short *cud; unsigned char *sqlest; char *stmt; void *sqladtp; void *sqltdsp; void **sqphsv; unsigned int *sqphsl; int *sqphss; void **sqpind; int *sqpins; unsigned int *sqparm; unsigned int **sqparc; unsigned short *sqpadto; unsigned short *sqptdso; void *sqhstv[4]; unsigned int sqhstl[4]; int sqhsts[4]; void *sqindv[4]; int sqinds[4]; unsigned int sqharm[4]; unsigned int *sqharc[4]; unsigned short sqadto[4]; unsigned short sqtdso[4]; }; pid$1::sqlcxt:entry { this->s = (struct sqlexd *) copyin(arg2,sizeof(struct sqlexd)); self->query = copyinstr((uintptr_t)this->s->stmt); printf("%s: %s\n",execname, self->query); self->ts = timestamp; } pid$1::sqlcxt:return /self->ts/ { @c[self->query] = count(); @time[self->query] = quantize((timestamp - self->ts)/1000); self->ts = 0; self->query = 0; } END { printf("\nQuery counts:\n"); printa(@c); printf("\nQuery times(us):\n"); printa(@time); } /* **************************************************************************** * This script is submitted to BigAdmin by a user of the BigAdmin community. * Sun Microsystems, Inc. is not responsible for the * contents or the code enclosed. * * * Copyright Sun Microsystems, Inc. ALL RIGHTS RESERVED * Use of this software is authorized pursuant to the * terms of the license found at * http://www.sun.com/bigadmin/common/berkeley_license.jsp * ****************************************************************************/