~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/strace.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

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
 
from __future__ import absolute_import
21
 
 
 
20
import errno
22
21
import os
23
22
import signal
24
23
import subprocess
27
26
from bzrlib import errors
28
27
 
29
28
 
 
29
# this is currently test-focused, so importing bzrlib.tests is ok. We might
 
30
# want to move feature to its own module though.
 
31
from bzrlib.tests import Feature
 
32
 
 
33
 
30
34
def strace(function, *args, **kwargs):
31
35
    """Invoke strace on function.
32
36
 
50
54
    # start strace
51
55
    strace_cmd = ['strace', '-r', '-tt', '-p', str(pid), '-o', log_file.name]
52
56
    if follow_children:
53
 
        strace_cmd.append('-f')
 
57
        strace_args.append('-f')
54
58
    # need to catch both stdout and stderr to work around
55
59
    # bug 627208
56
60
    proc = subprocess.Popen(strace_cmd,
94
98
        self.err_messages = err_messages
95
99
 
96
100
 
 
101
class _StraceFeature(Feature):
 
102
 
 
103
    def _probe(self):
 
104
        try:
 
105
            proc = subprocess.Popen(['strace'],
 
106
                stderr=subprocess.PIPE,
 
107
                stdout=subprocess.PIPE)
 
108
            proc.communicate()
 
109
            return True
 
110
        except OSError, e:
 
111
            if e.errno == errno.ENOENT:
 
112
                # strace is not installed
 
113
                return False
 
114
            else:
 
115
                raise
 
116
 
 
117
    def feature_name(self):
 
118
        return 'strace'
 
119
 
 
120
StraceFeature = _StraceFeature()