Add pretty print for one histogram file.

This commit is contained in:
waterson%netscape.com 2000-12-13 00:42:29 +00:00
Родитель 2d0db1fbe8
Коммит 93b11ee0da
2 изменённых файлов: 94 добавлений и 8 удалений

Просмотреть файл

@ -54,16 +54,23 @@ INCR=$2
sort $BASE > /tmp/$$.left
sort $INCR > /tmp/$$.right
# Do the join. The first `awk' script computes the difference between
# the base and the incremental files. The second `awk' script computes
# a `TOTAL' row. Then, we sort by the larges delta in bytes.
join /tmp/$$.left /tmp/$$.right |\
awk '{ print $1, $2, $3, $4, $5, $4 - $2, $5 - $3; }' |\
awk '{ tobj1 += $2; tbytes1 += $3; tobj2 += $4; tbytes2 += $5; tdobj += $6; tdbytes += $7; print $0; } END { print "TOTAL", tobj1, tbytes1, tobj2, tbytes2, tdobj, tdbytes; }' |\
sort -nr +6 > /tmp/$$.sorted
# Do the join. The `awk' script computes the difference between
# the base and the incremental files.
join /tmp/$$.left /tmp/$$.right \
| awk '{ print $1, $2, $3, $4, $5, $4 - $2, $5 - $3; }' \
> /tmp/$$.joined
rm -f /tmp/$$.left /tmp/$$.right
# Now compute a `TOTAL' row.
awk '{ tobj1 += $2; tbytes1 += $3; tobj2 += $4; tbytes2 += $5; tdobj += $6; tdbytes += $7; } END { print "TOTAL", tobj1, tbytes1, tobj2, tbytes2, tdobj, tdbytes; }' /tmp/$$.joined \
> /tmp/$$.sorted
# Then, we sort by the largest delta in bytes.
sort -nr +6 /tmp/$$.joined >> /tmp/$$.sorted
rm -f /tmp/$$.joined
# Pretty-print, including percentages
cat <<EOF > /tmp/$$.awk
BEGIN {
@ -89,4 +96,4 @@ EOF
# Now pretty print the file, and spit it out on stdout.
awk -f /tmp/$$.awk /tmp/$$.sorted
rm -f /tmp/$$.awk
rm -f /tmp/$$.awk /tmp/$$.sorted

Просмотреть файл

@ -0,0 +1,79 @@
#!/bin/sh
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is historgram-diff.sh, released Dec 8, 2000.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Chris Waterson <waterson@netscape.com>
#
# This shell script takes two `object histograms' produced using
# `histogram.pl' and prints the delta, sorted such that the objects
# that increased the most in raw memory usage are displayed at the
# top.
#
# Usage:
#
# histogram-pretty.sh [-c <count>] <file>
#
# Pretty-print the histogram in file <file>, displaying at most
# <count> rows.
# How many rows are we gonna show?
COUNT=20
# Read arguments
while [ $# -gt 0 ]; do
case "$1" in
-c) COUNT=$2
shift 2
;;
*) break
;;
esac
done
FILE=$1
# The first `awk' script computes a `TOTAL' row. Then, we sort by the
# larges delta in bytes.
awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp/$$.sorted
sort -nr +2 ${FILE} >> /tmp/$$.sorted
# Pretty-print, including percentages
cat <<EOF > /tmp/$$.awk
BEGIN {
print "Type Count Bytes %Total";
}
\$1 == "TOTAL" {
tbytes = \$3;
}
NR <= $COUNT {
printf "%-22s %6d %8d %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes;
}
NR > $COUNT {
oobjs += \$2; obytes += \$3;
}
END {
printf "%-22s %6d %8d %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes;
}
EOF
# Now pretty print the file, and spit it out on stdout.
awk -f /tmp/$$.awk /tmp/$$.sorted
rm -f /tmp/$$.awk /tmp/$$.sorted