/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: Martin Pool
  • Date: 2007-04-01 06:19:16 UTC
  • mfrom: (2323.5.20 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: mbp@sourcefrog.net-20070401061916-plpgsxdf8g7gll9o
Merge 0.15 final release back to trunk, including: recommend upgrades of old workingtrees, handle multiple http redirections, some dirstate fixes, 

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)