diff --git a/tools/trace-malloc/histogram-pretty.sh b/tools/trace-malloc/histogram-pretty.sh index 2b44f9348ace..765aa00f2b5f 100755 --- a/tools/trace-malloc/histogram-pretty.sh +++ b/tools/trace-malloc/histogram-pretty.sh @@ -27,13 +27,14 @@ # # Usage: # -# histogram-pretty.sh [-c ] +# histogram-pretty.sh [-c ] [-w ] # # Pretty-print the histogram in file , displaying at most # rows. # How many rows are we gonna show? COUNT=20 +WIDTH=22 # Read arguments while [ $# -gt 0 ]; do @@ -41,6 +42,9 @@ while [ $# -gt 0 ]; do -c) COUNT=$2 shift 2 ;; + -w) WIDTH=$2 + shift 2 + ;; *) break ;; esac @@ -57,19 +61,22 @@ sort -nr +2 ${FILE} >> /tmp/$$.sorted # Pretty-print, including percentages cat < /tmp/$$.awk BEGIN { - print "Type Count Bytes %Total"; + printf "%-${WIDTH}s Count Bytes %Total %Cov\n", "Type"; } \$1 == "TOTAL" { tbytes = \$3; } NR <= $COUNT { - printf "%-22s %6d %8d %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes; + if (\$1 != "TOTAL") { + covered += \$3; + } + printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes; } NR > $COUNT { - oobjs += \$2; obytes += \$3; + oobjs += \$2; obytes += \$3; covered += \$3; } END { - printf "%-22s %6d %8d %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes; + printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes; } EOF