Bumping manifests a=b2g-bump
[gecko.git] / tools / trace-malloc / histogram-pretty.sh
blob36e90151033b574da3015d1e56beccb71e099dcf
1 #!/bin/sh
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # histogram-pretty.sh [-c <count>] [-w <width>] <file>
9 # Pretty-print the histogram in file <file>, displaying at most
10 # <count> rows.
12 # How many rows are we gonna show?
13 COUNT=20
14 WIDTH=22
16 # Read arguments
17 while [ $# -gt 0 ]; do
18 case "$1" in
19 -c) COUNT=$2
20 shift 2
22 -w) WIDTH=$2
23 shift 2
25 *) break
27 esac
28 done
30 FILE=$1
32 # The first `awk' script computes a `TOTAL' row. Then, we sort by the
33 # larges delta in bytes.
34 awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp/$$.sorted
36 sort -nr +2 ${FILE} >> /tmp/$$.sorted
38 # Pretty-print, including percentages
39 cat <<EOF > /tmp/$$.awk
40 BEGIN {
41 printf "%-${WIDTH}s Count Bytes %Total %Cov\n", "Type";
43 \$1 == "TOTAL" {
44 tbytes = \$3;
46 NR <= $COUNT {
47 if (\$1 != "TOTAL") {
48 covered += \$3;
50 printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes;
52 NR > $COUNT {
53 oobjs += \$2; obytes += \$3; covered += \$3;
55 END {
56 printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes;
58 EOF
60 # Now pretty print the file, and spit it out on stdout.
61 awk -f /tmp/$$.awk /tmp/$$.sorted
63 rm -f /tmp/$$.awk /tmp/$$.sorted