Index: tools/perf/process_halts.sh
===================================================================
--- tools/perf/process_halts.sh	(revision f2b18d0157ce83fe51957b1e7247726c471d9b76)
+++ tools/perf/process_halts.sh	(revision 359d12d8de8e5a1d618c5d15fe31a879bb8bb624)
@@ -1,15 +1,34 @@
 #!/bin/bash -e
 
-DIR=$( dirname "${BASH_SOURCE[0]}")
-echo $DIR
-tmpfile=$(mktemp)
-function finish {
-  rm -rf "$tmpfile"
-}
-trap finish EXIT
+SAVE_TEMPS=false
+while (( "$#" )); do
+	case "$1" in
+	-s|--save-temps)
+		SAVE_TEMPS=true
+		shift
+		;;
+	*) # preserve positional arguments
+		PARAMS="$PARAMS $1"
+		shift
+		;;
+	esac
+done
+# set positional arguments in their proper place
+eval set -- "$PARAMS"
 
+if $SAVE_TEMPS; then
+	tmpfile=$(mktemp --tmpdir=$(pwd))
+	echo "Saving to $tmpfile"
+else
+	tmpfile=$(mktemp)
+	function finish {
+		rm -rf "$tmpfile"
+	}
+	trap finish EXIT
+fi
 # split the wanted and unwanted output
 awk "/^Processor|^PH:[0-9]+ - [0-9]+ [0-9]+/ {print \$0 > \"$tmpfile\"; next}{print \$0; fflush()}"
 
 # pass the data to the python scirpt
-$DIR/view_halts.py $tmpfile
+DIR=$( dirname "${BASH_SOURCE[0]}")
+cat $tmpfile | $DIR/view_halts.py ${PARAMS}
Index: tools/perf/view_halts.py
===================================================================
--- tools/perf/view_halts.py	(revision f2b18d0157ce83fe51957b1e7247726c471d9b76)
+++ tools/perf/view_halts.py	(revision 359d12d8de8e5a1d618c5d15fe31a879bb8bb624)
@@ -3,6 +3,16 @@
 import re
 import sys, getopt
+import fileinput
 import argparse
 
+#--------------------------------------------------------------------------------
+# Parse arguments
+parser = argparse.ArgumentParser(description='Produce a graph representing CPU activity over time.')
+parser.add_argument('-i', '--input' , dest='infile' , type=argparse.FileType('r'), default=sys.stdin, help='input file containing processor activity; if none specified then will use stdin.')
+parser.add_argument('-o', '--output', dest='outfile', type=argparse.FileType('w'), default=None, help='output file with any image format extension such as .png or .svg; if none specified then plt.show() will be used')
+args = parser.parse_args()
+
+#--------------------------------------------------------------------------------
+# Process data
 class Proc:
 	def __init__(self, id, name, address):
@@ -21,24 +31,26 @@
 #--------------------------------------------------------------------------------
 # Parse data
-with open(sys.argv[1], "r") as f:
-	for line in f:
-		match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line)
-		if match :
-			id = int(match.group(1))
-			processors[id] = Proc(id, match.group(2), match.group(3))
-			continue
+for line in args.infile:
+	match = re.match("Processor : ([0-9]+) - (.*) \((0x[0-9a-f]+)\)", line)
+	if match :
+		id = int(match.group(1))
+		processors[id] = Proc(id, match.group(2), match.group(3))
+		continue
 
-		match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line)
-		if match :
-			id = int(match.group(1))
-			if not id in data:
-				data[id] = []
-			data[id].append(Point(int(match.group(2)), int(match.group(3))))
-			continue
+	match = re.match("PH:([0-9]+) - ([0-9]+) ([0-9]+)", line)
+	if match :
+		id = int(match.group(1))
+		if not id in data:
+			data[id] = []
+		data[id].append(Point(int(match.group(2)), int(match.group(3))))
+		continue
 
-		print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
+	print("WARNING : line '%s' filterred not matched" % line, file=sys.stderr)
 
 #--------------------------------------------------------------------------------
 # Check data
+if not data:
+	print("ERROR : no data extracted from '%s'" % args.infile, file=sys.stderr)
+
 for d in data:
 	if not d in processors:
@@ -61,7 +73,5 @@
 # Convert data to series
 offset = min(data)
-print(offset)
-
-series=dict() ## dict of pairs of arrays
+series = dict()
 for d in data:
 	series[d] = ([], [], [])
@@ -87,5 +97,9 @@
 print('number of series={}'.format(len(series)))
 for s, xy in series.items():
-	print('    plotting series {} with {} points'.format(s, len(xy[0])))
+	if s in processors:
+		name = '"{}" ({})'.format(processors[s].name, processors[s].address)
+	else:
+		name = s
+	print( '    plotting series {} with {} points'.format(name, len(xy[0])) )
 	plt.fill_between(xy[0], xy[1], xy[2], step="post", alpha=0.4)
 	plt.step(xy[0], xy[1], where='post')
@@ -107,4 +121,7 @@
 # do the plot
 plt.tight_layout()
-print("saving figure image %s\n" % "out.svg")
-plt.savefig("out.svg")
+if not args.outfile:
+	plt.show()
+else:
+	print("saving figure image %s\n" % args.outfile.name)
+	plt.savefig(args.outfile.name)
