Merge lp:~percona-toolkit-dev/percona-toolkit/fix-summay-size-bug-993436 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 247
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-summay-size-bug-993436
Merge into: lp:percona-toolkit/2.1
Diff against target: 280 lines (+77/-61)
8 files modified
bin/pt-mysql-summary (+14/-17)
bin/pt-summary (+14/-17)
lib/bash/report_formatting.sh (+22/-17)
t/lib/bash/report_formatting.sh (+11/-7)
t/lib/bash/report_system_info.sh (+13/-1)
t/pt-summary/samples/Linux/output_002.txt (+1/-1)
t/pt-summary/samples/Linux/output_003.txt (+1/-1)
util/test-bash-functions (+1/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-summay-size-bug-993436
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+104989@code.launchpad.net
To post a comment you must log in.
249. By Daniel Nichter

Update authors for pt-*-summary.

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-mysql-summary'
2--- bin/pt-mysql-summary 2012-04-03 19:42:45 +0000
3+++ bin/pt-mysql-summary 2012-05-07 23:02:25 +0000
4@@ -576,22 +576,19 @@
5 local div="${3:-1024}"
6
7 echo "$num" | awk -v prec="$prec" -v div="$div" '
8- {
9- size = 4;
10- val = $1;
11-
12- unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
13-
14- while ( int(val) && !(val % 1024) ) {
15- val /= 1024;
16- }
17-
18- while ( val > 1000 ) {
19- val /= div;
20- }
21-
22- printf "%.*f%s", prec, val, unit;
23- }
24+ {
25+ num = $1;
26+ unit = num >= 1125899906842624 ? "P" \
27+ : num >= 1099511627776 ? "T" \
28+ : num >= 1073741824 ? "G" \
29+ : num >= 1048576 ? "M" \
30+ : num >= 1024 ? "k" \
31+ : "";
32+ while ( num >= div ) {
33+ num /= div;
34+ }
35+ printf "%.*f%s", prec, num, unit;
36+ }
37 '
38 }
39
40@@ -2854,7 +2851,7 @@
41
42 =head1 AUTHORS
43
44-Baron Schwartz, Brian Fraser, and Daniel Nichter.
45+Baron Schwartz, Brian Fraser, and Daniel Nichter
46
47 =head1 ABOUT PERCONA TOOLKIT
48
49
50=== modified file 'bin/pt-summary'
51--- bin/pt-summary 2012-04-03 19:42:45 +0000
52+++ bin/pt-summary 2012-05-07 23:02:25 +0000
53@@ -713,22 +713,19 @@
54 local div="${3:-1024}"
55
56 echo "$num" | awk -v prec="$prec" -v div="$div" '
57- {
58- size = 4;
59- val = $1;
60-
61- unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
62-
63- while ( int(val) && !(val % 1024) ) {
64- val /= 1024;
65- }
66-
67- while ( val > 1000 ) {
68- val /= div;
69- }
70-
71- printf "%.*f%s", prec, val, unit;
72- }
73+ {
74+ num = $1;
75+ unit = num >= 1125899906842624 ? "P" \
76+ : num >= 1099511627776 ? "T" \
77+ : num >= 1073741824 ? "G" \
78+ : num >= 1048576 ? "M" \
79+ : num >= 1024 ? "k" \
80+ : "";
81+ while ( num >= div ) {
82+ num /= div;
83+ }
84+ printf "%.*f%s", prec, num, unit;
85+ }
86 '
87 }
88
89@@ -2527,7 +2524,7 @@
90
91 =head1 AUTHORS
92
93-Baron Schwartz and Kevin van Zonneveld (http://kevin.vanzonneveld.net)
94+Baron Schwartz, Kevin van Zonneveld, and Brian Fraser
95
96 =head1 ABOUT PERCONA TOOLKIT
97
98
99=== modified file 'lib/bash/report_formatting.sh'
100--- lib/bash/report_formatting.sh 2012-04-03 14:07:30 +0000
101+++ lib/bash/report_formatting.sh 2012-05-07 23:02:25 +0000
102@@ -82,29 +82,34 @@
103
104 # Sub: shorten
105 # Shorten a value in bytes to another representation.
106-#
107 shorten() {
108 local num="$1"
109 local prec="${2:-2}"
110 local div="${3:-1024}"
111
112+ # By default Mebibytes (MiB), Gigibytes (GiB), etc. are used because
113+ # that's what MySQL uses. This may create odd output for values like
114+ # 1500M * 2 (bug 937793) because the base unit is MiB but the code
115+ # see 1,572,864,000 * 2 = 3,145,728,000 which is > 1 GiB so it uses
116+ # GiB as the unit, resulting in 2.9G instead of 3.0G that the user
117+ # might expect to see. There's no easy way to determine that
118+ # 3,145,728,000 was actually a multiple of MiB and not some weird GiB
119+ # value to begin with like 3.145G. The Perl lib Transformers::shorten()
120+ # uses MiB, GiB, etc. too.
121 echo "$num" | awk -v prec="$prec" -v div="$div" '
122- {
123- size = 4;
124- val = $1;
125-
126- unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
127-
128- while ( int(val) && !(val % 1024) ) {
129- val /= 1024;
130- }
131-
132- while ( val > 1000 ) {
133- val /= div;
134- }
135-
136- printf "%.*f%s", prec, val, unit;
137- }
138+ {
139+ num = $1;
140+ unit = num >= 1125899906842624 ? "P" \
141+ : num >= 1099511627776 ? "T" \
142+ : num >= 1073741824 ? "G" \
143+ : num >= 1048576 ? "M" \
144+ : num >= 1024 ? "k" \
145+ : "";
146+ while ( num >= div ) {
147+ num /= div;
148+ }
149+ printf "%.*f%s", prec, num, unit;
150+ }
151 '
152 }
153
154
155=== modified file 't/lib/bash/report_formatting.sh'
156--- t/lib/bash/report_formatting.sh 2012-04-02 22:25:17 +0000
157+++ t/lib/bash/report_formatting.sh 2012-05-07 23:02:25 +0000
158@@ -1,6 +1,6 @@
159 #!/usr/bin/env bash
160
161-plan 19
162+plan 20
163
164 . "$LIB_DIR/report_formatting.sh"
165
166@@ -12,12 +12,12 @@
167 is \
168 "$(shorten 3145728000 1)" \
169 "2.9G" \
170- "10485760, 1 precision, default divisor => 2.9G"
171+ "3145728000, 1 precision, default divisor => 2.9G"
172
173 is \
174 "$(shorten 3145728000 1 1000)" \
175- "3.0G" \
176- "Opt-in to the 2.1 behavior works"
177+ "3.1G" \
178+ "3145728000, 1 precision, divisor 1000 => 3.1G"
179
180 is \
181 "$(shorten 0 0)" \
182@@ -31,8 +31,8 @@
183
184 is \
185 "$(shorten 1572864000 1 1000)" \
186- "1.5G" \
187- "1572864000, 1 precision, divisor 1000 => 1.5G"
188+ "1.6G" \
189+ "1572864000, 1 precision, divisor 1000 => 1.6G"
190
191 is \
192 "$(shorten 364 0)" \
193@@ -59,6 +59,10 @@
194 "6.5T" \
195 "6492100000006, 1 precision, divisor 1000 => 6.5T"
196
197+is "$(shorten 1059586048 1)" \
198+ "1010.5M" \
199+ "1059586048 => 1010.5M (bug 993436)"
200+
201 # section
202
203 is \
204@@ -74,7 +78,7 @@
205 is \
206 "$(section "A_B_C")" \
207 "# A#B#C#######################################################" \
208- "..but it does replace everything after and including the first underscore with #s"
209+ "replace extra underscores with #s"
210
211 # name_val
212
213
214=== modified file 't/lib/bash/report_system_info.sh'
215--- t/lib/bash/report_system_info.sh 2012-04-03 18:16:58 +0000
216+++ t/lib/bash/report_system_info.sh 2012-05-07 23:02:25 +0000
217@@ -1,6 +1,6 @@
218 #!/usr/bin/env bash
219
220-plan 48
221+plan 49
222
223 . "$LIB_DIR/alt_cmds.sh"
224 . "$LIB_DIR/log_warn_die.sh"
225@@ -827,6 +827,18 @@
226 parse_free_minus_b "$TMPDIR/in" > "$TMPDIR/got"
227 no_diff "$TMPDIR/got" "$TMPDIR/expected" "parse_free_minus_b"
228
229+# Bug 993436: Memory: Total reports M when it should say G
230+cat <<EOF > "$TMPDIR/expected"
231+ Total | 1010.5M
232+ Free | 784.4M
233+ Used | physical = 226.1M, swap allocated = 2.0G, swap used = 0.0, virtual = 226.1M
234+ Buffers | 48.8M
235+ Caches | 122.2M
236+ Dirty | 152 kB
237+EOF
238+parse_free_minus_b "$T_DIR/pt-summary/samples/Linux/002/memory" > "$TMPDIR/got"
239+no_diff "$TMPDIR/got" "$TMPDIR/expected" "parse_free_minus_b (bug 993436)"
240+
241 # parse_filesystems
242
243 cat <<EOF > $TMPDIR/expected
244
245=== modified file 't/pt-summary/samples/Linux/output_002.txt'
246--- t/pt-summary/samples/Linux/output_002.txt 2012-04-02 16:36:17 +0000
247+++ t/pt-summary/samples/Linux/output_002.txt 2012-05-07 23:02:25 +0000
248@@ -14,7 +14,7 @@
249 Models | 1xQEMU Virtual CPU version 0.14.1
250 Caches | 1x4096 KB
251 # Memory #####################################################
252- Total | 1.0M
253+ Total | 1010.5M
254 Free | 784.4M
255 Used | physical = 226.1M, swap allocated = 2.0G, swap used = 0.0, virtual = 226.1M
256 Buffers | 48.8M
257
258=== modified file 't/pt-summary/samples/Linux/output_003.txt'
259--- t/pt-summary/samples/Linux/output_003.txt 2012-04-02 16:36:17 +0000
260+++ t/pt-summary/samples/Linux/output_003.txt 2012-05-07 23:02:25 +0000
261@@ -14,7 +14,7 @@
262 Models | 1xQEMU Virtual CPU version 0.14.1
263 Caches | 1x4096 KB
264 # Memory #####################################################
265- Total | 1.0M
266+ Total | 1010.5M
267 Free | 784.7M
268 Used | physical = 225.8M, swap allocated = 2.0G, swap used = 0.0, virtual = 225.8M
269 Buffers | 48.8M
270
271=== modified file 'util/test-bash-functions'
272--- util/test-bash-functions 2012-03-29 22:21:32 +0000
273+++ util/test-bash-functions 2012-05-07 23:02:25 +0000
274@@ -32,6 +32,7 @@
275
276 BIN_DIR="$BRANCH/bin";
277 LIB_DIR="$BRANCH/lib/bash";
278+T_DIR="$BRANCH/t";
279 T_LIB_DIR="$BRANCH/t/lib";
280 SANDBOX_VERSION="$($BRANCH/sandbox/test-env version)"
281

Subscribers

People subscribed via source and target branches