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

Proposed by Daniel Nichter
Status: Superseded
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-summay-size-bug-993436
Merge into: lp:percona-toolkit/2.1
Diff against target: 262 lines (+75/-59)
8 files modified
bin/pt-mysql-summary (+13/-16)
bin/pt-summary (+13/-16)
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 Needs Fixing
Review via email: mp+104955@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Needs Fixing
248. By Daniel Nichter

Code comment why MiB, GiB, etc. are used in shorten() and update that func in pt-summary and pt-mysql-summary.

249. By Daniel Nichter

Update authors for pt-*-summary.

Unmerged revisions

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

Subscribers

People subscribed via source and target branches