#!/usr/sbin/dtrace -qs /* * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved. * * locktimesid.d - Display lock wait times grouped by filename. * * This script graphs the time spent waiting for DB page locks. * * The optional integer maxcount parameter directs the script to exit once that * many page lock waits have been measured. * * usage: locktimes.d { -p | -c " [suspend = timestamp; } /* lock-resume(DBT *lockobj, int lock_mode) */ bdb$target:::lock-resume /self->suspend > 0/ { this->duration = timestamp - self->suspend; self->suspend = 0; this->dbt = copyin(arg0, sizeof(DBT)); this->ilock = copyin(this->dbt->data, sizeof(DB_ILOCK)); this->filename = filenames[this->ilock->fileid.id1, this->ilock->fileid.id2, this->ilock->fileid.id3, this->ilock->fileid.id4, this->ilock->fileid.id5]; @locktimes[this->filename, this->ilock->pgno, modes[arg1]] = quantize(this->duration); lockcount++; } bdb$target:::lock-resume /lockcount == maxcount/ { exit(0); } /* db-open(char *file, char *db, uint32_t flags, uint8_t fileid[20]) * * Watch db-open probes in order to get the fileid -> file name mapping. */ bdb$target:::db-open /arg0 != 0/ { this->filename = copyinstr(arg0); this->fileid = (FILEID *) copyin(arg3, 20); filenames[this->fileid->id1, this->fileid->id2, this->fileid->id3, this->fileid->id4, this->fileid->id5] = this->filename; } /* db-cursor(char *file, char *db, unsigned txnid, unsigned flags, uint8_t fileid[20]) * * Watch cursor creation probes in order to get the fileid -> file name mapping. */ bdb$target:::db-cursor /arg0 != 0/ { this->filename = (string) copyinstr(arg0); this->fileid = (FILEID *) copyin(arg4, 20); filenames[this->fileid->id1, this->fileid->id2, this->fileid->id3, this->fileid->id4, this->fileid->id5] = this->filename; } dtrace:::END { printa("Wait time for file %s page %u %s locks in nanoseconds %@a\n", @locktimes); }