MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
query-network-time.d
1 #!/usr/sbin/dtrace -s
2 #
3 # Copyright (c) 2009 Sun Microsystems, Inc.
4 # Use is subject to license terms.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #
19 # Show the time taken to execute a query, include the bytes and time taken
20 # to transfer the information over the network to/from the client
21 
22 #pragma D option quiet
23 #pragma D option dynvarsize=4m
24 
25 dtrace:::BEGIN
26 {
27  printf("%-2s %-30s %-10s %9s %18s %-s \n",
28  "St", "Who", "DB", "ConnID", "Dur microsec", "Query");
29 }
30 
31 mysql*:::query-start
32 {
33  self->query = copyinstr(arg0);
34  self->who = strjoin(copyinstr(arg3),strjoin("@",copyinstr(arg4)));
35  self->db = copyinstr(arg2);
36  self->connid = arg1;
37  self->querystart = timestamp;
38  self->netwrite = 0;
39  self->netwritecum = 0;
40  self->netwritebase = 0;
41  self->netread = 0;
42  self->netreadcum = 0;
43  self->netreadbase = 0;
44 }
45 
46 mysql*:::net-write-start
47 {
48  self->netwrite += arg0;
49  self->netwritebase = timestamp;
50 }
51 
52 mysql*:::net-write-done
53 {
54  self->netwritecum += (timestamp - self->netwritebase);
55  self->netwritebase = 0;
56 }
57 
58 mysql*:::net-read-start
59 {
60  self->netreadbase = timestamp;
61 }
62 
63 mysql*:::net-read-done
64 {
65  self->netread += arg1;
66  self->netreadcum += (timestamp - self->netreadbase);
67  self->netreadbase = 0;
68 }
69 
70 mysql*:::query-done
71 {
72  this->elapsed = (timestamp - self->querystart) /1000000;
73  printf("%2d %-30s %-10s %9d %18d %s\n",
74  arg0, self->who, self->db,
75  self->connid, this->elapsed, self->query);
76  printf("Net read: %d bytes (%d ms) write: %d bytes (%d ms)\n",
77  self->netread, (self->netreadcum/1000000),
78  self->netwrite, (self->netwritecum/1000000));
79 }