summaryrefslogtreecommitdiffstats
path: root/tools/valgrind/common.py
diff options
context:
space:
mode:
authortimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-27 14:24:12 +0000
committertimurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-27 14:24:12 +0000
commit9b9edbc58e8324b85f7560c2d3c6ec1fe001981a (patch)
tree6eff838cb28810ed41ef4a361f1183e3929e1733 /tools/valgrind/common.py
parent33bf0981ce52768d500ff0f27fbfa4b7d48348ea (diff)
downloadchromium_src-9b9edbc58e8324b85f7560c2d3c6ec1fe001981a.zip
chromium_src-9b9edbc58e8324b85f7560c2d3c6ec1fe001981a.tar.gz
chromium_src-9b9edbc58e8324b85f7560c2d3c6ec1fe001981a.tar.bz2
Remove some dead code from tools/valgrind/common.py
Also, hopefully improve the buffering behaviour, see BUG=163314 NOTRY=true R=glider@chromium.org Review URL: https://chromiumcodereview.appspot.com/16103005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/valgrind/common.py')
-rw-r--r--tools/valgrind/common.py71
1 files changed, 21 insertions, 50 deletions
diff --git a/tools/valgrind/common.py b/tools/valgrind/common.py
index a333fde..12f9881 100644
--- a/tools/valgrind/common.py
+++ b/tools/valgrind/common.py
@@ -19,47 +19,32 @@ class TimeoutError(Exception):
pass
-def _print_line(line, flush=True):
- # Printing to a text file (including stdout) on Windows always winds up
- # using \r\n automatically. On buildbot, this winds up being read by a master
- # running on Linux, so we manually convert crlf to '\n'
- print line.rstrip() + '\n',
- if flush:
- sys.stdout.flush()
-
-
def RunSubprocessInBackground(proc):
"""Runs a subprocess in the background. Returns a handle to the process."""
logging.info("running %s in the background" % " ".join(proc))
return subprocess.Popen(proc)
-def RunSubprocess(proc, timeout=0, detach=False, background=False):
+def RunSubprocess(proc, timeout=0):
""" Runs a subprocess, until it finishes or |timeout| is exceeded and the
process is killed with taskkill. A |timeout| <= 0 means no timeout.
Args:
proc: list of process components (exe + args)
timeout: how long to wait before killing, <= 0 means wait forever
- detach: Whether to pass the DETACHED_PROCESS argument to CreateProcess
- on Windows. This is used by Purify subprocesses on buildbot which
- seem to get confused by the parent console that buildbot sets up.
"""
logging.info("running %s, timeout %d sec" % (" ".join(proc), timeout))
- if detach:
- # see MSDN docs for "Process Creation Flags"
- DETACHED_PROCESS = 0x8
- p = subprocess.Popen(proc, creationflags=DETACHED_PROCESS)
- else:
- # For non-detached processes, manually read and print out stdout and stderr.
- # By default, the subprocess is supposed to inherit these from its parent,
- # however when run under buildbot, it seems unable to read data from a
- # grandchild process, so we have to read the child and print the data as if
- # it came from us for buildbot to read it. We're not sure why this is
- # necessary.
- # TODO(erikkay): should we buffer stderr and stdout separately?
- p = subprocess.Popen(proc, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ # Manually read and print out stdout and stderr.
+ # By default, the subprocess is supposed to inherit these from its parent,
+ # however when run under buildbot, it seems unable to read data from a
+ # grandchild process, so we have to read the child and print the data as if
+ # it came from us for buildbot to read it. We're not sure why this is
+ # necessary.
+ # TODO(erikkay): should we buffer stderr and stdout separately?
+ p = subprocess.Popen(proc, universal_newlines=True,
+ bufsize=1, # line buffered
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
logging.info("started subprocess")
@@ -70,27 +55,13 @@ def RunSubprocess(proc, timeout=0, detach=False, background=False):
if timeout > 0:
wait_until = time.time() + timeout
while p.poll() is None and not did_timeout:
- if not detach:
- line = p.stdout.readline()
- while line and not did_timeout:
- _print_line(line)
- line = p.stdout.readline()
- if timeout > 0:
- did_timeout = time.time() > wait_until
- else:
- # When we detach, blocking on reading stdout doesn't work, so we sleep
- # a short time and poll.
- time.sleep(0.5)
- if time.time() >= progress_delay_time:
- # Force output on a periodic basis to avoid getting killed off by the
- # buildbot.
- # TODO(erikkay): I'd prefer a less obtrusive 'print ".",' with a flush
- # but because of how we're doing subprocesses, this doesn't appear to
- # work reliably.
- logging.info("%s still running..." % os.path.basename(proc[0]))
- progress_delay_time = time.time() + progress_delay
- if timeout > 0:
- did_timeout = time.time() > wait_until
+ for line in p.stdout:
+ sys.stdout.write(line)
+ sys.stdout.flush()
+ if timeout > 0:
+ did_timeout = time.time() > wait_until
+ if did_timeout:
+ break
if did_timeout:
logging.info("process timed out")
@@ -109,9 +80,9 @@ def RunSubprocess(proc, timeout=0, detach=False, background=False):
time.sleep(1.0)
logging.error("TIMEOUT waiting for %s" % proc[0])
raise TimeoutError(proc[0])
- elif not detach:
- for line in p.stdout.readlines():
- _print_line(line, False)
+ else:
+ for line in p.stdout:
+ sys.stdout.write(line)
if not IsMac(): # stdout flush fails on Mac
logging.info("flushing stdout")
p.stdout.flush()