1 #!/usr/sbin/dtrace -qs 2 /* 3 * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. 4 * 5 * See the file LICENSE for license information. 6 * 7 * apitimes.d - Summarize time spent in DB API functions 8 * 9 * This script graphs the time spent in the main API calls, grouped by thread. 10 * 11 * The optional integer maxcount parameter directs the script to exit after 12 * that many functions have been accumulated. 13 * 14 * usage: apitimes.d { -p <pid> | -c "<program> [<args]" } [maxcount] 15 */ 16 #pragma D option quiet 17 #pragma D option defaultargs 18 19 self unsigned long long start; 20 21 dtrace:::BEGIN 22 { 23 maxcount = $1 > 0 ? $1 : -1; 24 functioncount = 0; 25 printf("DB API times of process %d grouped by function; ", $target); 26 printf("interrupt to display summary\n"); 27 } 28 29 pid$target::db*_create:entry, 30 pid$target::__*_pp:entry 31 { 32 self->start = timestamp; 33 } 34 35 pid$target::db*_create:return, 36 pid$target::__*_pp:return 37 /self->start != 0/ 38 { 39 @calltimes[tid, probefunc] = quantize(timestamp - self->start); 40 self->start = 0; 41 functioncount++; 42 } 43 44 pid$target::db*_create:return, 45 pid$target::__*_pp:return 46 /functioncount == maxcount/ 47 { 48 exit(0); 49 } 50 51 dtrace:::END 52 { 53 printf("\n"); 54 printa("Times that thread %x spent in %s in nanoseconds %@a", @calltimes); 55 } 56