Lines 1-13
Link Here
|
1 |
--- ./mytop.orig 2007-02-17 12:57:46.000000000 +0800 |
1 |
--- ./mytop.orig 2007-02-17 12:57:46.000000000 +0800 |
2 |
+++ ./mytop 2013-01-21 17:49:21.000000000 +0800 |
2 |
+++ ./mytop 2013-01-21 18:42:17.000000000 +0800 |
3 |
@@ -1,5 +1,6 @@ |
3 |
@@ -1,5 +1,7 @@ |
4 |
#!/usr/bin/perl -w |
4 |
#!/usr/bin/perl -w |
5 |
# |
5 |
# |
6 |
+# |
6 |
+# |
|
|
7 |
+# |
7 |
# $Id: mytop,v 1.53 2003/09/18 17:58:36 jzawodn Exp $ |
8 |
# $Id: mytop,v 1.53 2003/09/18 17:58:36 jzawodn Exp $ |
8 |
|
9 |
|
9 |
=pod |
10 |
=pod |
10 |
@@ -153,7 +154,7 @@ |
11 |
@@ -153,7 +155,7 @@ |
11 |
"idle|i" => \$config{idle}, |
12 |
"idle|i" => \$config{idle}, |
12 |
"resolve|r" => \$config{resolve}, |
13 |
"resolve|r" => \$config{resolve}, |
13 |
"prompt!" => \$config{prompt}, |
14 |
"prompt!" => \$config{prompt}, |
Lines 16-22
Link Here
|
16 |
"mode|m=s" => \$config{mode}, |
17 |
"mode|m=s" => \$config{mode}, |
17 |
"sort=s" => \$config{sort}, |
18 |
"sort=s" => \$config{sort}, |
18 |
); |
19 |
); |
19 |
@@ -193,6 +194,7 @@ |
20 |
@@ -193,6 +195,7 @@ |
20 |
*BLUE = sub { }; |
21 |
*BLUE = sub { }; |
21 |
*WHITE = sub { }; |
22 |
*WHITE = sub { }; |
22 |
*BOLD = sub { }; |
23 |
*BOLD = sub { }; |
Lines 24-30
Link Here
|
24 |
} |
25 |
} |
25 |
|
26 |
|
26 |
my $RESET = RESET() || ''; |
27 |
my $RESET = RESET() || ''; |
27 |
@@ -202,6 +204,7 @@ |
28 |
@@ -202,6 +205,7 @@ |
28 |
my $BLUE = BLUE() || ''; |
29 |
my $BLUE = BLUE() || ''; |
29 |
my $WHITE = WHITE() || ''; |
30 |
my $WHITE = WHITE() || ''; |
30 |
my $BOLD = BOLD() || ''; |
31 |
my $BOLD = BOLD() || ''; |
Lines 32-38
Link Here
|
32 |
|
33 |
|
33 |
## Connect |
34 |
## Connect |
34 |
|
35 |
|
35 |
@@ -369,6 +372,10 @@ |
36 |
@@ -369,6 +373,10 @@ |
36 |
require Data::Dumper; |
37 |
require Data::Dumper; |
37 |
print Data::Dumper::Dumper([\%config]); |
38 |
print Data::Dumper::Dumper([\%config]); |
38 |
ReadKey(0); |
39 |
ReadKey(0); |
Lines 43-49
Link Here
|
43 |
} |
44 |
} |
44 |
|
45 |
|
45 |
## m - mode swtich to qps |
46 |
## m - mode swtich to qps |
46 |
@@ -377,7 +384,7 @@ |
47 |
@@ -377,7 +385,7 @@ |
47 |
{ |
48 |
{ |
48 |
$config{mode} = 'qps'; |
49 |
$config{mode} = 'qps'; |
49 |
Clear() unless $config{batchmode}; |
50 |
Clear() unless $config{batchmode}; |
Lines 52-58
Link Here
|
52 |
next; |
53 |
next; |
53 |
} |
54 |
} |
54 |
|
55 |
|
55 |
@@ -710,7 +717,7 @@ |
56 |
@@ -710,7 +718,7 @@ |
56 |
## |
57 |
## |
57 |
if ($config{header}) |
58 |
if ($config{header}) |
58 |
{ |
59 |
{ |
Lines 61-67
Link Here
|
61 |
|
62 |
|
62 |
## if the server died or we lost connectivity |
63 |
## if the server died or we lost connectivity |
63 |
if (not @recs) |
64 |
if (not @recs) |
64 |
@@ -800,8 +807,15 @@ |
65 |
@@ -800,8 +808,15 @@ |
65 |
|
66 |
|
66 |
## Queries per second... |
67 |
## Queries per second... |
67 |
|
68 |
|
Lines 79-85
Link Here
|
79 |
|
80 |
|
80 |
my @t = localtime(time); |
81 |
my @t = localtime(time); |
81 |
|
82 |
|
82 |
@@ -819,26 +833,26 @@ |
83 |
@@ -819,26 +834,26 @@ |
83 |
$lines_left--; |
84 |
$lines_left--; |
84 |
|
85 |
|
85 |
|
86 |
|
Lines 116-122
Link Here
|
116 |
( # slow now (qps) |
117 |
( # slow now (qps) |
117 |
($STATUS{Slow_queries} ) ? |
118 |
($STATUS{Slow_queries} ) ? |
118 |
( $STATUS{Slow_queries} - $OLD_STATUS{Slow_queries} ) / $t_delta : |
119 |
( $STATUS{Slow_queries} - $OLD_STATUS{Slow_queries} ) / $t_delta : |
119 |
@@ -889,8 +903,42 @@ |
120 |
@@ -889,8 +904,42 @@ |
120 |
make_short(($STATUS{Bytes_received} - $OLD_STATUS{Bytes_received}) / $t_delta ), |
121 |
make_short(($STATUS{Bytes_received} - $OLD_STATUS{Bytes_received}) / $t_delta ), |
121 |
make_short(($STATUS{Bytes_sent} - $OLD_STATUS{Bytes_sent}) / $t_delta )) |
122 |
make_short(($STATUS{Bytes_sent} - $OLD_STATUS{Bytes_sent}) / $t_delta )) |
122 |
if ($t_delta); |
123 |
if ($t_delta); |
Lines 160-189
Link Here
|
160 |
$lines_left--; |
161 |
$lines_left--; |
161 |
} |
162 |
} |
162 |
|
163 |
|
163 |
@@ -905,19 +953,19 @@ |
164 |
@@ -904,21 +953,6 @@ |
|
|
165 |
## Threads |
164 |
## |
166 |
## |
165 |
|
167 |
|
166 |
#my $sz = $width - 52; |
168 |
- #my $sz = $width - 52; |
167 |
- my @sz = (8, 9, 15, 10, 9, 6); |
169 |
- my @sz = (8, 9, 15, 10, 9, 6); |
168 |
+ my @sz = (9, 9, 15, 10, 9, 6); |
170 |
- my $used = scalar(@sz) + Sum(@sz); |
169 |
my $used = scalar(@sz) + Sum(@sz); |
171 |
- my $free = $width - $used; |
170 |
my $free = $width - $used; |
172 |
- |
|
|
173 |
- print BOLD(); |
174 |
- |
175 |
- printf "%8s %9s %15s %10s %9s %6s %-${free}s\n", |
176 |
- 'Id','User','Host/IP','DB','Time', 'Cmd', 'Query or State'; |
177 |
- |
178 |
- print RESET(); |
179 |
- |
180 |
- ## Id User Host DB |
181 |
- printf "%8s %9s %15s %10s %9s %6s %-${free}s\n", |
182 |
- '--','----','-------','--','----', '---', '----------'; |
171 |
|
183 |
|
172 |
print BOLD(); |
184 |
$lines_left -= 2; |
173 |
|
185 |
|
174 |
- printf "%8s %9s %15s %10s %9s %6s %-${free}s\n", |
186 |
@@ -926,10 +960,16 @@ |
175 |
+ printf "%9s %9s %15s %10s %9s %6s %-${free}s\n", |
|
|
176 |
'Id','User','Host/IP','DB','Time', 'Cmd', 'Query or State'; |
177 |
|
187 |
|
178 |
print RESET(); |
188 |
my @data = Hashes($proc_cmd); |
179 |
|
189 |
|
180 |
## Id User Host DB |
190 |
+ my $max_id = 0; |
181 |
- printf "%8s %9s %15s %10s %9s %6s %-${free}s\n", |
191 |
+ |
182 |
+ printf "%9s %9s %15s %10s %9s %6s %-${free}s\n", |
192 |
foreach my $thread (@data) |
183 |
'--','----','-------','--','----', '---', '----------'; |
193 |
{ |
|
|
194 |
last if not $lines_left; |
184 |
|
195 |
|
185 |
$lines_left -= 2; |
196 |
+ if ($max_id < $thread->{Id}) { |
186 |
@@ -952,8 +1000,11 @@ |
197 |
+ $max_id = $thread->{Id}; |
|
|
198 |
+ } |
199 |
+ |
200 |
## Drop Domain Name, unless it looks like an IP address. If |
201 |
## it's an IP, we'll strip the port number because it's rarely |
202 |
## interesting. |
203 |
@@ -952,8 +992,11 @@ |
187 |
{ |
204 |
{ |
188 |
$thread->{Host} =~ s/:\d+$//; |
205 |
$thread->{Host} =~ s/:\d+$//; |
189 |
my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET); |
206 |
my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET); |
Lines 197-212
Link Here
|
197 |
} |
214 |
} |
198 |
|
215 |
|
199 |
## Fix possible undefs |
216 |
## Fix possible undefs |
200 |
@@ -1044,7 +1095,7 @@ |
217 |
@@ -990,6 +1033,22 @@ |
|
|
218 |
|
219 |
} |
220 |
|
221 |
+ my $max_id_size = length $max_id; |
222 |
+ my @sz = ($max_id_size, 9, 15, 10, 9, 6); |
223 |
+ my $used = scalar(@sz) + Sum(@sz); |
224 |
+ my $free = $width - $used; |
225 |
+ |
226 |
+ print BOLD(); |
227 |
+ |
228 |
+ printf "%${max_id_size}s %9s %15s %10s %9s %6s %-${free}s\n", |
229 |
+ 'Id','User','Host/IP','DB','Time', 'Cmd', 'Query or State'; |
230 |
+ |
231 |
+ print RESET(); |
232 |
+ |
233 |
+ ## Id User Host DB |
234 |
+ printf "%${max_id_size}s %9s %15s %10s %9s %6s %-${free}s\n", |
235 |
+ '--','----','-------','--','----', '---', '----------'; |
236 |
+ |
237 |
## Sort by idle time (closest thing to CPU usage I can think of). |
238 |
|
239 |
my @sorted; |
240 |
@@ -1044,7 +1103,7 @@ |
201 |
print GREEN() if $thread->{Command} eq 'Connect'; |
241 |
print GREEN() if $thread->{Command} eq 'Connect'; |
202 |
} |
242 |
} |
203 |
|
243 |
|
204 |
- printf "%8d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s\n", |
244 |
- printf "%8d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s\n", |
205 |
+ printf "%9d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s\n", |
245 |
+ printf "%${max_id_size}d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s\n", |
206 |
$thread->{Id}, $thread->{User}, $thread->{Host}, $thread->{db}, |
246 |
$thread->{Id}, $thread->{User}, $thread->{Host}, $thread->{db}, |
207 |
$thread->{Time}, $thread->{Command}, $smInfo; |
247 |
$thread->{Time}, $thread->{Command}, $smInfo; |
208 |
|
248 |
|
209 |
@@ -1099,8 +1150,8 @@ |
249 |
@@ -1099,8 +1158,8 @@ |
210 |
my @data = Hashes("SHOW INNODB STATUS"); |
250 |
my @data = Hashes("SHOW INNODB STATUS"); |
211 |
|
251 |
|
212 |
open P, "|$config{pager}" or die "$!"; |
252 |
open P, "|$config{pager}" or die "$!"; |