All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix that makes xend tracing thread safe
@ 2007-03-29 21:52 Magnus Carlsson
  2007-03-29 22:33 ` Ewan Mellor
  0 siblings, 1 reply; 2+ messages in thread
From: Magnus Carlsson @ 2007-03-29 21:52 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

Currently, the output in xend.trace is sometimes garbled since multiple
threads write to it simultaneously.  The following patch fixes that.

It also adds an initial field with the thread name on each traced line,
which makes it easier to follow the trace.  (If this is considered a new
feature which shouldn't be included due to the feature freeze, it can be
disabled by removing the first line in print_trace.)

Cheers,
Magnus

[-- Attachment #2: SrvDaemon.py-tracing-thread-safe.patch --]
[-- Type: text/x-patch, Size: 5006 bytes --]

# HG changeset patch
# User Magnus Carlsson <magnus@galois.com>
# Date 1175203666 25200
# Node ID c51f65166e062eee00bc99424bbe56f547f3dcfa
# Parent  ffb9dda429461442b0e727775a810b352ec74c9c
Made tracing thread safe, and also print thread name.

diff -r ffb9dda42946 -r c51f65166e06 tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py	Wed Mar 28 16:52:05 2007 +0100
+++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 29 14:27:46 2007 -0700
@@ -38,7 +38,8 @@ class Daemon:
         self.traceon = False
         self.tracefile = None
         self.traceindent = 0
-        self.child = 0 
+        self.child = 0
+        self.traceLock = threading.Lock()
 
 
     def cleanup_xend(self, kill):
@@ -253,6 +254,7 @@ class Daemon:
                 pass
 
     def print_trace(self, string):
+        self.tracefile.write("%s: "% threading.currentThread().getName())
         for i in range(self.traceindent):
             ch = " "
             if (i % 5):
@@ -263,50 +265,54 @@ class Daemon:
         self.tracefile.write(string)
             
     def trace(self, frame, event, arg):
-        if not self.traceon:
-            print >>self.tracefile
-            print >>self.tracefile, '-' * 20, 'TRACE OFF', '-' * 20
-            self.tracefile.close()
-            self.tracefile = None
-            return None
-        if event == 'call':
-            code = frame.f_code
-            filename = code.co_filename
-            m = re.search('.*xend/(.*)', filename)
-            if not m:
+        self.traceLock.acquire()
+        try:
+            if not self.traceon:
+                print >>self.tracefile
+                print >>self.tracefile, '-' * 20, 'TRACE OFF', '-' * 20
+                self.tracefile.close()
+                self.tracefile = None
                 return None
-            modulename = m.group(1)
-            if modulename.endswith('.pyc'):
-                modulename = modulename[:-1]
-            if modulename == 'sxp.py' or \
-               modulename == 'XendLogging.py' or \
-               modulename == 'XendMonitor.py' or \
-               modulename == 'server/SrvServer.py':
-                return None
-            self.traceindent += 1
-            self.print_trace("> %s:%s\n"
-                             % (modulename, code.co_name))
-        elif event == 'line':
-            filename = frame.f_code.co_filename
-            lineno = frame.f_lineno
-            self.print_trace("%4d %s" %
-                             (lineno, linecache.getline(filename, lineno)))
-        elif event == 'return':
-            code = frame.f_code
-            filename = code.co_filename
-            m = re.search('.*xend/(.*)', filename)
-            if not m:
-                return None
-            modulename = m.group(1)
-            self.print_trace("< %s:%s\n"
-                             % (modulename, code.co_name))
-            self.traceindent -= 1
-        elif event == 'exception':
-            self.print_trace("! Exception:\n")
-            (ex, val, tb) = arg
-            traceback.print_exception(ex, val, tb, 10, self.tracefile)
-            #del tb
-        return self.trace
+            if event == 'call':
+                code = frame.f_code
+                filename = code.co_filename
+                m = re.search('.*xend/(.*)', filename)
+                if not m:
+                    return None
+                modulename = m.group(1)
+                if modulename.endswith('.pyc'):
+                    modulename = modulename[:-1]
+                if modulename == 'sxp.py' or \
+                   modulename == 'XendLogging.py' or \
+                   modulename == 'XendMonitor.py' or \
+                   modulename == 'server/SrvServer.py':
+                    return None
+                self.traceindent += 1
+                self.print_trace("> %s:%s\n"
+                                 % (modulename, code.co_name))
+            elif event == 'line':
+                filename = frame.f_code.co_filename
+                lineno = frame.f_lineno
+                self.print_trace("%4d %s" %
+                                 (lineno, linecache.getline(filename, lineno)))
+            elif event == 'return':
+                code = frame.f_code
+                filename = code.co_filename
+                m = re.search('.*xend/(.*)', filename)
+                if not m:
+                    return None
+                modulename = m.group(1)
+                self.print_trace("< %s:%s\n"
+                                 % (modulename, code.co_name))
+                self.traceindent -= 1
+            elif event == 'exception':
+                self.print_trace("! Exception:\n")
+                (ex, val, tb) = arg
+                traceback.print_exception(ex, val, tb, 10, self.tracefile)
+                #del tb
+            return self.trace
+        finally:
+            self.traceLock.release()
 
     def set_user(self):
         # Set the UID.

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix that makes xend tracing thread safe
  2007-03-29 21:52 [PATCH] Fix that makes xend tracing thread safe Magnus Carlsson
@ 2007-03-29 22:33 ` Ewan Mellor
  0 siblings, 0 replies; 2+ messages in thread
From: Ewan Mellor @ 2007-03-29 22:33 UTC (permalink / raw)
  To: Magnus Carlsson; +Cc: xen-devel

On Thu, Mar 29, 2007 at 02:52:52PM -0700, Magnus Carlsson wrote:

> Currently, the output in xend.trace is sometimes garbled since multiple
> threads write to it simultaneously.  The following patch fixes that.
> 
> It also adds an initial field with the thread name on each traced line,
> which makes it easier to follow the trace.  (If this is considered a new
> feature which shouldn't be included due to the feature freeze, it can be
> disabled by removing the first line in print_trace.)

Applied, thanks Magnus.

Ewan.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-29 22:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-29 21:52 [PATCH] Fix that makes xend tracing thread safe Magnus Carlsson
2007-03-29 22:33 ` Ewan Mellor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.