Merge lp:~percona-toolkit-dev/percona-toolkit/fix-937793 into lp:percona-toolkit/2.0

Proposed by Brian Fraser
Status: Rejected
Rejected by: Daniel Nichter
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-937793
Merge into: lp:percona-toolkit/2.0
Diff against target: 267 lines (+165/-25)
4 files modified
bin/pt-mysql-summary (+46/-24)
lib/bash/report_formatting.sh (+54/-0)
t/lib/bash/report_formatting.sh (+64/-0)
t/pt-mysql-summary/format_innodb_status.sh (+1/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-937793
Reviewer Review Type Date Requested Status
Daniel Nichter Disapprove
Review via email: mp+96357@code.launchpad.net

Description of the change

One somewhat weird thing you might notie is using . instead of source in the test file.
Apparently source is a bashism? It didn't work at all in my NetBSD box.
Besides that, I think it has everything in there.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

There are three problems. First and foremost, it doesn't fix the bug:

       Log File Size | 2 * 1,46G = 2,9G

Did you test it manually with innodb_log_file_size=1500M?

Second, please name tests, e.g. (last arg):

is \
   "$(shorten 10485760 1)" \
   "10.0M" \
   "10485760 = 10.0M"

The Bash test stuff currently allows you not to name tests, but I should really remove that "feature".

Fourth, echo "$num $prec $div" | awk ... is a useless use of echo; see awk -v var=val.

Finally, I haven't documented this yet, but use:

report_formatting.t@ -> ../../../util/test-bash-functions

I.e. just symlink <bash test>.t in t/lib/bash/ to ../../../util/test-bash-functions and this script will do the proper magic so perl <bash test>.t runs <bash test>.sh.

review: Needs Fixing
199. By Brian Fraser <email address hidden>

Fixes as per Daniel's review.

The previous commit made the change to shorten() opt-in, but never
changed the code in pt-mysql-summary to actually enable the new
behavior.

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

This branch was never actually merged, and after further though, I'm fixing this problem while also fixing bug 993436.

review: Disapprove

Unmerged revisions

199. By Brian Fraser <email address hidden>

Fixes as per Daniel's review.

The previous commit made the change to shorten() opt-in, but never
changed the code in pt-mysql-summary to actually enable the new
behavior.

198. By Brian Fraser <email address hidden>

Backported fix for https://bugs.launchpad.net/percona-toolkit/+bug/937793

This commit adds a report_formatting bash lib. Currently it only has
one function, shorten(), but in future versions of the toolkit it
will contain shared functions between pt-summary and pt-mysql-summary.

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-02-03 23:25:29 +0000
3+++ bin/pt-mysql-summary 2012-03-07 19:46:18 +0000
4@@ -22,18 +22,19 @@
5 # See https://launchpad.net/percona-toolkit for more information.
6 # ###########################################################################
7
8+
9 TMPDIR=""
10
11 mk_tmpdir() {
12- local dir=${1:-""}
13+ local dir="${1:-""}"
14
15 if [ -n "$dir" ]; then
16 if [ ! -d "$dir" ]; then
17- mkdir $dir || die "Cannot make tmpdir $dir"
18+ mkdir "$dir" || die "Cannot make tmpdir $dir"
19 fi
20 TMPDIR="$dir"
21 else
22- local tool=`basename $0`
23+ local tool="${0##*/}"
24 local pid="$$"
25 TMPDIR=`mktemp -d /tmp/${tool}.${pid}.XXXXX` \
26 || die "Cannot make secure tmpdir"
27@@ -42,7 +43,7 @@
28
29 rm_tmpdir() {
30 if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
31- rm -rf $TMPDIR
32+ rm -rf "$TMPDIR"
33 fi
34 TMPDIR=""
35 }
36@@ -51,6 +52,45 @@
37 # End tmpdir package
38 # ###########################################################################
39
40+# ###########################################################################
41+# report_formatting package
42+# This package is a copy without comments from the original. The original
43+# with comments and its test file can be found in the Bazaar repository at,
44+# lib/bash/report_formatting.sh
45+# t/lib/bash/report_formatting.sh
46+# See https://launchpad.net/percona-toolkit for more information.
47+# ###########################################################################
48+
49+
50+shorten() {
51+ local num="$1"
52+ local prec="${2:-2}"
53+ local div="${3:-1024}"
54+
55+ echo "$num" | awk -v prec="$prec" -v div="$div" '
56+ {
57+ size = 4;
58+ val = $1;
59+
60+ unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
61+
62+ while ( int(val) && !(val % 1024) ) {
63+ val /= 1024;
64+ }
65+
66+ while ( val > 1000 ) {
67+ val /= div;
68+ }
69+
70+ printf "%.*f%s", prec, val, unit;
71+ }
72+ '
73+}
74+
75+# ###########################################################################
76+# End report_formatting package
77+# ###########################################################################
78+
79 # ########################################################################
80 # Some global setup is necessary for cross-platform compatibility, even
81 # when sourcing this script for testing purposes.
82@@ -132,24 +172,6 @@
83 printf "%20s | %s\n" "$1" "$2"
84 }
85
86-# Converts a value to units of power of 2. Optional precision is $2.
87-shorten() {
88- unit=k
89- size=1024
90- if [ $1 -ge 1099511627776 ] ; then
91- size=1099511627776
92- unit=T
93- elif [ $1 -ge 1073741824 ] ; then
94- size=1073741824
95- unit=G
96- elif [ $1 -ge 1048576 ] ; then
97- size=1048576
98- unit=M
99- fi
100- result=$(echo "$1 $size ${2:-0}" | $AP_AWK '{printf "%." $3 "f", $1 / $2}')
101- echo "${result}${unit}"
102-}
103-
104 # Collapse a file into an aggregated list; file must be created with 'sort |
105 # uniq -c'. This function is copy-pasted from 'summary' so see there for full
106 # docs and tests.
107@@ -576,7 +598,7 @@
108 # Summarizes various things about InnoDB status that are not easy to see by eye.
109 format_innodb_status () {
110 local file=$1
111- name_val "Checkpoint Age" $(shorten $(find_checkpoint_age "${file}"))
112+ name_val "Checkpoint Age" $(shorten $(find_checkpoint_age "${file}") 0)
113 name_val "InnoDB Queue" "$(awk '/queries inside/{print}' "${file}")"
114 name_val "Oldest Transaction" "$(find_max_trx_time "${file}") Seconds";
115 name_val "History List Len" $(awk '/History list length/{print $4}' "${file}")
116@@ -1202,7 +1224,7 @@
117 lg_size="$(get_var innodb_log_file_size)"
118 lg_fils="$(get_var innodb_log_files_in_group)"
119 lg_totl="$((${lg_size} * ${lg_fils}))"
120- name_val "Log File Size" "${lg_fils} * $(shorten ${lg_size}) = $(shorten ${lg_totl} 1)"
121+ name_val "Log File Size" "${lg_fils} * $(shorten ${lg_size} 1 1000) = $(shorten ${lg_totl} 1 1000)"
122 name_val "Log Buffer Size" $(shorten $(get_var innodb_log_buffer_size))
123 name_val "Flush Method" $(get_var innodb_flush_method)
124 name_val "Flush Log At Commit" $(get_var innodb_flush_log_at_trx_commit)
125
126=== added file 'lib/bash/report_formatting.sh'
127--- lib/bash/report_formatting.sh 1970-01-01 00:00:00 +0000
128+++ lib/bash/report_formatting.sh 2012-03-07 19:46:18 +0000
129@@ -0,0 +1,54 @@
130+# This program is copyright 2011 Percona Inc.
131+# Feedback and improvements are welcome.
132+#
133+# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
134+# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
135+# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
136+#
137+# This program is free software; you can redistribute it and/or modify it under
138+# the terms of the GNU General Public License as published by the Free Software
139+# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
140+# systems, you can issue `man perlgpl' or `man perlartistic' to read these
141+# licenses.
142+#
143+# You should have received a copy of the GNU General Public License along with
144+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
145+# Place, Suite 330, Boston, MA 02111-1307 USA.
146+# ###########################################################################
147+# report_formatting package
148+# ###########################################################################
149+
150+# Package: report_formatting
151+# (partially backported from 2.1)
152+
153+# Sub: shorten
154+# Shorten a value in bytes to another representation.
155+#
156+shorten() {
157+ local num="$1"
158+ local prec="${2:-2}"
159+ local div="${3:-1024}"
160+
161+ echo "$num" | awk -v prec="$prec" -v div="$div" '
162+ {
163+ size = 4;
164+ val = $1;
165+
166+ unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
167+
168+ while ( int(val) && !(val % 1024) ) {
169+ val /= 1024;
170+ }
171+
172+ while ( val > 1000 ) {
173+ val /= div;
174+ }
175+
176+ printf "%.*f%s", prec, val, unit;
177+ }
178+ '
179+}
180+
181+# ###########################################################################
182+# End report_formatting package
183+# ###########################################################################
184
185=== added file 't/lib/bash/report_formatting.sh'
186--- t/lib/bash/report_formatting.sh 1970-01-01 00:00:00 +0000
187+++ t/lib/bash/report_formatting.sh 2012-03-07 19:46:18 +0000
188@@ -0,0 +1,64 @@
189+#!/usr/bin/env bash
190+
191+plan 11
192+
193+. "$LIB_DIR/report_formatting.sh"
194+
195+is \
196+ "$(shorten 10485760 1)" \
197+ "10.0M" \
198+ "10485760, 1 precision, default divisor => 10.0M"
199+
200+is \
201+ "$(shorten 3145728000 1)" \
202+ "2.9G" \
203+ "10485760, 1 precision, default divisor => 2.9G"
204+
205+is \
206+ "$(shorten 3145728000 1 1000)" \
207+ "3.0G" \
208+ "Opt-in to the 2.1 behavior works"
209+
210+is \
211+ "$(shorten 0 0)" \
212+ "0" \
213+ "0, 0 precision, default divisor => 0"
214+
215+is \
216+ "$(shorten 1572864000 1)" \
217+ "1.5G" \
218+ "1572864000, 1 precision, default divisor => 1.5G"
219+
220+is \
221+ "$(shorten 1572864000 1 1000)" \
222+ "1.5G" \
223+ "1572864000, 1 precision, divisor 1000 => 1.5G"
224+
225+is \
226+ "$(shorten 364 0)" \
227+ "364" \
228+ "364, 0 precision, default divisor => 364"
229+
230+is \
231+ "$(shorten 364 1)" \
232+ "364.0" \
233+ "364, 1 precision, default divisor => 364"
234+
235+is \
236+ "$(shorten 649216 1)" \
237+ "634.0k" \
238+ "649216, 1 precision, default divisor => 634.0k"
239+
240+is \
241+ "$(shorten 6492100000006 1)" \
242+ "5.9T" \
243+ "6492100000006, 1 precision, default divisor => 5.9T"
244+
245+is \
246+ "$(shorten 6492100000006 1 1000)" \
247+ "6.5T" \
248+ "6492100000006, 1 precision, divisor 1000 => 6.5T"
249+
250+# ###########################################################################
251+# Done
252+# ###########################################################################
253
254=== added symlink 't/lib/bash/report_formatting.t'
255=== target is u'../../../util/test-bash-functions'
256=== modified file 't/pt-mysql-summary/format_innodb_status.sh'
257--- t/pt-mysql-summary/format_innodb_status.sh 2012-02-02 17:03:48 +0000
258+++ t/pt-mysql-summary/format_innodb_status.sh 2012-03-07 19:46:18 +0000
259@@ -98,7 +98,7 @@
260 TEST_NAME="innodb-status.003.txt"
261 # ############################################################################
262 cat <<'EOF' > $TMPDIR/expected
263- Checkpoint Age | 0k
264+ Checkpoint Age | 0
265 InnoDB Queue | 0 queries inside InnoDB, 0 queries in queue
266 Oldest Transaction | 35 Seconds
267 History List Len | 11

Subscribers

People subscribed via source and target branches