1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/trace-malloc/histogram-pretty.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +# histogram-pretty.sh [-c <count>] [-w <width>] <file> 1.11 +# 1.12 +# Pretty-print the histogram in file <file>, displaying at most 1.13 +# <count> rows. 1.14 + 1.15 +# How many rows are we gonna show? 1.16 +COUNT=20 1.17 +WIDTH=22 1.18 + 1.19 +# Read arguments 1.20 +while [ $# -gt 0 ]; do 1.21 + case "$1" in 1.22 + -c) COUNT=$2 1.23 + shift 2 1.24 + ;; 1.25 + -w) WIDTH=$2 1.26 + shift 2 1.27 + ;; 1.28 + *) break 1.29 + ;; 1.30 + esac 1.31 +done 1.32 + 1.33 +FILE=$1 1.34 + 1.35 +# The first `awk' script computes a `TOTAL' row. Then, we sort by the 1.36 +# larges delta in bytes. 1.37 +awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp/$$.sorted 1.38 + 1.39 +sort -nr +2 ${FILE} >> /tmp/$$.sorted 1.40 + 1.41 +# Pretty-print, including percentages 1.42 +cat <<EOF > /tmp/$$.awk 1.43 +BEGIN { 1.44 + printf "%-${WIDTH}s Count Bytes %Total %Cov\n", "Type"; 1.45 + } 1.46 +\$1 == "TOTAL" { 1.47 + tbytes = \$3; 1.48 + } 1.49 +NR <= $COUNT { 1.50 + if (\$1 != "TOTAL") { 1.51 + covered += \$3; 1.52 + } 1.53 + printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes; 1.54 + } 1.55 +NR > $COUNT { 1.56 + oobjs += \$2; obytes += \$3; covered += \$3; 1.57 + } 1.58 +END { 1.59 + printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes; 1.60 + } 1.61 +EOF 1.62 + 1.63 +# Now pretty print the file, and spit it out on stdout. 1.64 +awk -f /tmp/$$.awk /tmp/$$.sorted 1.65 + 1.66 +rm -f /tmp/$$.awk /tmp/$$.sorted