Patchwork [v4,11/11] trace: [tracetool] Add error-reporting functions

login
register
mail settings
Submitter Lluís Vilanova
Date Feb. 10, 2012, 11:55 a.m.
Message ID <20120210115530.9787.18557.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/140639/
State New
Headers show

Comments

Lluís Vilanova - Feb. 10, 2012, 11:55 a.m.
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 scripts/tracetool.py |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)

Patch

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 1134544..7053a74 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -12,6 +12,13 @@  import sys
 import getopt
 
 
+def error_write(*lines):
+    sys.stderr.writelines(lines)
+
+def error(*lines):
+    error_write(*lines)
+    sys.exit(1)
+
 
 ######################################################################
 # format auto-registration
@@ -443,14 +450,11 @@  def dtrace_nop_d(events):
 def trace_stap_begin(events):
     global probeprefix
     if binary == "":
-        print '--binary is required for SystemTAP tapset generator'
-        sys.exit(1)
+        error("--binary is required for SystemTAP tapset generator\n")
     if ((probeprefix == "") and (targettype == "")):
-        print '--target-type is required for SystemTAP tapset generator'
-        sys.exit(1)
+        error("--target-type is required for SystemTAP tapset generator\n")
     if ((probeprefix == "") and (targetarch == "")):
-        print '--target-arch is required for SystemTAP tapset generator'
-        sys.exit(1)
+        error("--target-arch is required for SystemTAP tapset generator\n")
     if probeprefix == "":
         probeprefix = 'qemu.' + targettype + '.' + targetarch
     print '/* This file is autogenerated by tracetool, do not edit. */'
@@ -601,8 +605,9 @@  def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "", long_options)
     except getopt.GetoptError, err:
-        # print help information and exit:
-        print str(err) # will print something like "option -a not recognized"
+        # print help information and exit
+        # will print something like "option -a not recognized"
+        error_write(str(err)+"\n")
         usage()
         sys.exit(2)
     for opt, arg in opts:
@@ -631,12 +636,10 @@  def main():
             usage()
 
     if format_ not in _formats:
-        print "Unknown format: %s" % format_
-        print
+        error_write("Unknown format: %s\n\n" % format_)
         usage()
     if backend not in _backends:
-        print "Unknown backend: %s" % backend
-        print
+        error_write("Unknown backend: %s\n\n" % backend)
         usage()
 
     events = read_events(sys.stdin)