/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: Andrew Bennetts
  • Date: 2007-04-11 06:40:05 UTC
  • mfrom: (2404 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070411064005-zylli6el5cz7kwnb
Merge from bzr.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
20
21
import os
21
22
import signal
22
23
import subprocess
33
34
    :return: a tuple: function-result, a StraceResult.
34
35
    """
35
36
    # capture strace output to a file
36
 
    log_file = tempfile.TemporaryFile()
 
37
    log_file = tempfile.NamedTemporaryFile()
37
38
    log_file_fd = log_file.fileno()
38
39
    pid = os.getpid()
39
40
    # start strace
40
41
    proc = subprocess.Popen(['strace',
41
 
        '-f', '-r', '-tt', '-p', str(pid),
 
42
        '-f', '-r', '-tt', '-p', str(pid), '-o', log_file.name
42
43
        ],
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.)
 
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
47
49
    result = function(*args, **kwargs)
48
50
    # stop strace
49
51
    os.kill(proc.pid, signal.SIGQUIT)