Rather than using echo to output logging messages, this patch adds a loglevel-like interface to print errors and trace messages.
Signed-off-by: Mel Gorman <m...@csn.ul.ie> --- tlbmiss_cost.sh | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tlbmiss_cost.sh b/tlbmiss_cost.sh index af3daa6..0a71ccd 100755 --- a/tlbmiss_cost.sh +++ b/tlbmiss_cost.sh @@ -16,6 +16,32 @@ # and then placed in the same directory as this script # Note: Do not use any optimisation to avoid skewing the results +# trace == 3 +# info == 2 (default, should remain quiet in practicet) +# error == 1 +VERBOSE=2 + +# Print verbose message to stderr if --verbose is specified +print_trace() +{ + if [ $VERBOSE -ge 3 ]; then + echo "TRACE: $@" 1>&2 + fi +} + +print_error() +{ + if [ $VERBOSE -ge 1 ]; then + echo "ERROR: $@" 1>&2 + fi +} + +die() +{ + print_error $@ + exit -1 +} + calibrator_calc() { if [ "$CALIBRATOR" = "" ]; then @@ -26,8 +52,7 @@ calibrator_calc() fi if [[ ! -x $CALIBRATOR ]]; then - echo "Unable to locate calibrator." - exit -1 + die "Unable to locate calibrator." fi CPUMHZ=`which cpumhz 2>/dev/null` @@ -36,8 +61,7 @@ calibrator_calc() fi if [[ ! -x $CPUMHZ ]]; then - echo "Unable to locate cpumhz." - exit -1 + die "Unable to locate cpumhz." fi MHZ=`$CPUMHZ` @@ -51,12 +75,10 @@ calibrator_calc() FAILED_MEASURE=0 if [ "$TMPFILE" = "" ]; then - echo ERROR: Failed to create tmpfile - exit -1 + die Failed to create tmpfile fi if [ "$MHZ" = "" ]; then - echo ERROR: Failed to calculate CPU MHz - exit -1 + die Failed to calculate CPU MHz fi trap "rm $TMPFILE*; exit" INT @@ -122,8 +144,7 @@ oprofile_calc() fi if [[ ! -x $STREAM ]]; then - echo "Unable to locate stream." - exit 1 + die "Unable to locate stream." fi OPST=`which oprofile_start.sh` @@ -132,16 +153,13 @@ oprofile_calc() fi if [[ ! -x $OPST ]]; then - echo "Unable to locate oprofile_start.sh." - exit 1 + die "Unable to locate oprofile_start.sh." fi # First we run without hugepages to get a baseline $OPST --event dtlb_miss --event tablewalk_cycles >/dev/null 2>&1 if [ "$?" -ne "0" ]; then - echo "Error starting oprofile, check oprofile_map_event.pl" - echo "for appropriate dtlb_miss and tablewalk_cycles events." - exit 1 + die "Error starting oprofile, check oprofile_map_event.pl for appropriate dtlb_miss and tablewalk_cycles events." fi $STREAM >/dev/null 2>&1 opcontrol --stop >/dev/null 2>&1 @@ -173,7 +191,7 @@ oprofile_calc() LAST_LATENCY_CYCLES=$(($TABLE_WALK/$TLB_MISS)) } -ARGS=`getopt -o c:s: --long calibrator:,stream: -n 'tlbmiss_cost.sh' -- "$@"` +ARGS=`getopt -o c:s:vq --long calibrator:,stream:,verbose,quiet -n 'tlbmiss_cost.sh' -- "$@"` eval set -- "$ARGS" @@ -181,9 +199,11 @@ while true ; do case "$1" in -c|--calibrator) CALIBRATOR="$2" ; shift 2 ;; -s|--stream) STREAM="$2" ; shift 2 ;; + -v|--verbose) VERBOSE=$(($VERBOSE+1)); shift;; + -q|--quiet) VERBOSE=$(($VERBOSE-1)); shift;; "") shift ; break ;; "--") shift ; break ;; - *) echo "Unrecognized option $1" ; exit 1 ;; + *) die "Unrecognized option $1" ;; esac done -- 1.6.3.3 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel