root/trunk/tools/pgslowq

Revision 23, 1.5 kB (checked in by robert, 10 years ago)

make this work in miliseconds, which is more inline with other pg tools (and still pretty darn precise for our needs)

  • Property svn:executable set to *
Line 
1 #!/bin/sh
2 QUANT_END=
3 LOG=
4 ZONE=
5 DESTRUCTOR=
6 STRSIZE=4096
7
8 args=`getopt qs:t:wz: $*`
9 if [ $? != 0 ] || [ $# -eq 0 ] 
10 then
11   echo "$0 [-q] [-t #us] [-s len] [-w] [-z zone]"
12   echo
13   echo "        -q              quantize query runtimes."
14   echo "        -t              show queries over the specified # miliseconds."
15   echo "        -s #            show len bytes of the query (default: 4096)."
16   echo "        -w              run destructively to work around DTrace bugs."
17   echo "        -z zone         restrict to postgres running zone."
18   exit 2
19 fi
20
21 set -- $args
22 for i
23 do
24   case "$i"
25   in
26     -q)
27       QUANT_END='END { printa(@q); }'
28       shift;;
29     -s)
30       STRSIZE="$2"
31       shift;;
32     -t)
33       US=$2; shift;
34       LOG='postgres*:::statement-start
35            /self->starttime && timestamp > self->starttime &&
36             (timestamp - self->starttime) > (('"$US"') * 1000000)/
37            {
38              printf("%s/%d (%dms)\n%s\n============================\n",
39                     zonename, pid, (timestamp - self->starttime)/1000000,
40                     self->sql);
41            }'
42       shift;;
43     -w)
44       DESTRUCTOR="-w"
45       shift;;
46     -z)
47       ZONE="/zonename==\"$2\"/"; shift;
48       shift;;
49   esac
50 done
51
52 dtrace $DESTRUCTOR -q -n '
53 #pragma D option strsize='"$STRSIZE"'
54 self int starttime;
55 self string sql;
56 '"$LOG"'
57 postgres*:::statement-start
58 /self->starttime && timestamp > self->starttime/
59 {
60   @q[zonename] = quantize((timestamp - self->starttime)/1000000);
61 }
62 postgres*:::statement-start
63 '"$ZONE"'
64 {
65   self->sql = copyinstr(arg0);
66   self->starttime = (strstr(self->sql, "<IDLE>") == NULL) ? timestamp : 0;
67 }
68 '"$QUANT_END"
69
Note: See TracBrowser for help on using the browser.