/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/strace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-01 06:48:38 UTC
  • mfrom: (2389.1.1 0.15-to-trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20070401064838-34903c7b0d0c8007
merge 0.15 back to dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Support for running strace against the current process."""
19
19
 
20
 
import errno
21
20
import os
22
21
import signal
23
22
import subprocess
34
33
    :return: a tuple: function-result, a StraceResult.
35
34
    """
36
35
    # capture strace output to a file
37
 
    log_file = tempfile.NamedTemporaryFile()
 
36
    log_file = tempfile.TemporaryFile()
38
37
    log_file_fd = log_file.fileno()
39
38
    pid = os.getpid()
40
39
    # start strace
41
40
    proc = subprocess.Popen(['strace',
42
 
        '-f', '-r', '-tt', '-p', str(pid), '-o', log_file.name
 
41
        '-f', '-r', '-tt', '-p', str(pid),
43
42
        ],
44
 
        stdout=subprocess.PIPE,
45
 
        stderr=subprocess.STDOUT)
46
 
    # Wait for strace to attach
47
 
    attached_notice = proc.stdout.readline()
48
 
    # Run the function to strace
 
43
        stderr=log_file_fd,
 
44
        stdout=log_file_fd)
 
45
    # TODO? confirm its started (test suite should be sufficient)
 
46
    # (can loop on proc.pid, but that may not indicate started and attached.)
49
47
    result = function(*args, **kwargs)
50
48
    # stop strace
51
49
    os.kill(proc.pid, signal.SIGQUIT)