~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/strace.py

  • Committer: Andrew Bennetts
  • Date: 2007-04-04 01:42:41 UTC
  • mto: This revision was merged to the branch mainline in revision 2396.
  • Revision ID: andrew.bennetts@canonical.com-20070404014241-swk0f9ec602dnezm
Wait for strace to attach before running the function we want to trace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    :return: a tuple: function-result, a StraceResult.
34
34
    """
35
35
    # capture strace output to a file
36
 
    log_file = tempfile.TemporaryFile()
 
36
    log_file = tempfile.NamedTemporaryFile()
37
37
    log_file_fd = log_file.fileno()
38
38
    pid = os.getpid()
39
39
    # start strace
40
40
    proc = subprocess.Popen(['strace',
41
 
        '-f', '-r', '-tt', '-p', str(pid),
 
41
        '-f', '-r', '-tt', '-p', str(pid), '-o', log_file.name
42
42
        ],
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.)
 
43
        stdout=subprocess.PIPE,
 
44
        stderr=subprocess.STDOUT)
 
45
    # Wait for strace to attach
 
46
    attached_notice = proc.stdout.readline()
 
47
    # Run the function to strace
47
48
    result = function(*args, **kwargs)
48
49
    # stop strace
49
50
    os.kill(proc.pid, signal.SIGQUIT)