From: Magnus Carlsson <magnus@galois.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] Fix that makes xend tracing thread safe
Date: Thu, 29 Mar 2007 14:52:52 -0700 [thread overview]
Message-ID: <460C3534.8020002@galois.com> (raw)
[-- 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
next reply other threads:[~2007-03-29 21:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-29 21:52 Magnus Carlsson [this message]
2007-03-29 22:33 ` [PATCH] Fix that makes xend tracing thread safe Ewan Mellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=460C3534.8020002@galois.com \
--to=magnus@galois.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.