ia64/xen-unstable

changeset 1573:85e28c751a9e

bitkeeper revision 1.1011.1.5 (40db0dbbPeQLwub6SrW6h5ORlAC4SA)

Add trace support to new xend.
author kaf24@scramble.cl.cam.ac.uk
date Thu Jun 24 17:22:03 2004 +0000 (2004-06-24)
parents 9078dae95f8b
children 463ef0310fbe fc877db2ee49
files tools/xenmgr/lib/server/SrvConsoleServer.py tools/xenmgr/xend
line diff
     1.1 --- a/tools/xenmgr/lib/server/SrvConsoleServer.py	Thu Jun 24 17:21:49 2004 +0000
     1.2 +++ b/tools/xenmgr/lib/server/SrvConsoleServer.py	Thu Jun 24 17:22:03 2004 +0000
     1.3 @@ -8,6 +8,8 @@ import os
     1.4  import os.path
     1.5  import signal
     1.6  import sys
     1.7 +import threading
     1.8 +import linecache
     1.9  import socket
    1.10  import pwd
    1.11  import re
    1.12 @@ -482,7 +484,7 @@ class Daemon:
    1.13          while code > 0:
    1.14              code = os.waitpid(-1, os.WNOHANG)
    1.15  
    1.16 -    def start(self):
    1.17 +    def start(self,trace=0):
    1.18          if self.cleanup(kill=False):
    1.19              return 1
    1.20  
    1.21 @@ -506,9 +508,54 @@ class Daemon:
    1.22          # Child
    1.23          logfile = self.open_logfile()
    1.24          self.redirect_output(logfile)
    1.25 +        if trace:
    1.26 +            self.tracefile = open('/var/log/xend.trace', 'w+', 1)
    1.27 +            self.traceindent = 0
    1.28 +            sys.settrace(self.trace)
    1.29 +            try:
    1.30 +                threading.settrace(self.trace) # Only in Python >= 2.3
    1.31 +            except:
    1.32 +                pass
    1.33          self.run()
    1.34          return 0
    1.35  
    1.36 +    def print_trace(self,str):
    1.37 +        for i in range(self.traceindent):
    1.38 +            self.tracefile.write("    ")
    1.39 +        self.tracefile.write(str)
    1.40 +            
    1.41 +    def trace(self, frame, event, arg):
    1.42 +        if event == 'call':
    1.43 +            code = frame.f_code
    1.44 +            filename = code.co_filename
    1.45 +            m = re.search('.*xenmgr/(.*)', code.co_filename)
    1.46 +            if not m:
    1.47 +                return None
    1.48 +            modulename = m.group(1)
    1.49 +            if re.search('sxp.py', modulename):
    1.50 +                return None
    1.51 +            self.traceindent += 1
    1.52 +            self.print_trace("++++ %s:%s\n"
    1.53 +                             % (modulename, code.co_name))
    1.54 +        elif event == 'line':
    1.55 +            filename = frame.f_code.co_filename
    1.56 +            lineno = frame.f_lineno
    1.57 +            self.print_trace("%4d %s" %
    1.58 +                             (lineno, linecache.getline(filename, lineno)))
    1.59 +        elif event == 'return':
    1.60 +            code = frame.f_code
    1.61 +            filename = code.co_filename
    1.62 +            m = re.search('.*xenmgr/(.*)', code.co_filename)
    1.63 +            if not m:
    1.64 +                return None
    1.65 +            modulename = m.group(1)
    1.66 +            self.print_trace("---- %s:%s\n"
    1.67 +                             % (modulename, code.co_name))
    1.68 +            self.traceindent -= 1
    1.69 +        elif event == 'exception':
    1.70 +            pass
    1.71 +        return self.trace
    1.72 +
    1.73      def open_logfile(self):
    1.74          if not os.path.exists(CONTROL_DIR):
    1.75              os.makedirs(CONTROL_DIR)
     2.1 --- a/tools/xenmgr/xend	Thu Jun 24 17:21:49 2004 +0000
     2.2 +++ b/tools/xenmgr/xend	Thu Jun 24 17:22:03 2004 +0000
     2.3 @@ -29,6 +29,8 @@ def main():
     2.4          return status >> 8
     2.5      elif sys.argv[1] == 'start':
     2.6          return daemon.start()
     2.7 +    elif sys.argv[1] == 'trace_start':
     2.8 +        return daemon.start(trace=1)
     2.9      elif sys.argv[1] == 'stop':
    2.10          return daemon.stop()
    2.11      elif sys.argv[1] == 'restart':