diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 18:49:47 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-07 18:49:47 +0000 |
commit | 7e52297125e0d5ddcc59ffb435d84b61278d51c8 (patch) | |
tree | b107732fddb8066823c7b8ae917ea8ade8dc74a7 /tools | |
parent | 6fd9b4cdd4a8d9fa2f0e7f63689b6d4c5a2f3f71 (diff) | |
download | chromium_src-7e52297125e0d5ddcc59ffb435d84b61278d51c8.zip chromium_src-7e52297125e0d5ddcc59ffb435d84b61278d51c8.tar.gz chromium_src-7e52297125e0d5ddcc59ffb435d84b61278d51c8.tar.bz2 |
Remove references to trace_child_process.py by generating it on the fly instead.
This removes any dependency from trace_inputs.py on any other script. This also
fixes the fact that 'trace_child_process.py' was a confusing script in itself.
Fix trace_inputs_smoke_tests.py on Windows.
R=csharp@chromium.org
NOTRY=true
BUG=
Review URL: https://chromiumcodereview.appspot.com/10914144
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155437 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/isolate/README.py | 2 | ||||
-rwxr-xr-x | tools/isolate/tests/trace_inputs_smoke_test.py | 4 | ||||
-rwxr-xr-x | tools/isolate/trace_child_process.py | 40 | ||||
-rwxr-xr-x | tools/isolate/trace_inputs.py | 47 |
4 files changed, 34 insertions, 59 deletions
diff --git a/tools/isolate/README.py b/tools/isolate/README.py index 863e0fe..2cd4cca 100755 --- a/tools/isolate/README.py +++ b/tools/isolate/README.py @@ -33,7 +33,7 @@ import sys def main(): for i in sorted(os.listdir(os.path.dirname(os.path.abspath(__file__)))): - if not i.endswith('.py') or i in ('PRESUBMIT.py', 'trace_child_process.py'): + if not i.endswith('.py') or i == 'PRESUBMIT.py': continue module = __import__(i[:-3]) if hasattr(module, '__doc__'): diff --git a/tools/isolate/tests/trace_inputs_smoke_test.py b/tools/isolate/tests/trace_inputs_smoke_test.py index db46036..da56971 100755 --- a/tools/isolate/tests/trace_inputs_smoke_test.py +++ b/tools/isolate/tests/trace_inputs_smoke_test.py @@ -140,7 +140,7 @@ class TraceInputs(TraceInputsBase): ' tests/trace_inputs/child2.py'.replace('/', os.path.sep), ' tests/trace_inputs/files1/'.replace('/', os.path.sep), ' tests/trace_inputs/test_file.txt'.replace('/', os.path.sep), - ' tests/%s' % FILENAME, + (' tests/%s' % FILENAME).replace('/', os.path.sep), ' trace_inputs.py', )) + '\n' trace_expected = '\n'.join(( @@ -414,7 +414,7 @@ class TraceInputsImport(TraceInputsBase): u'tests/trace_inputs/child2.py'.replace('/', os.path.sep), u'tests/trace_inputs/files1/'.replace('/', os.path.sep), u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep), - u'tests/trace_inputs_smoke_test.py', + u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep), u'trace_inputs.py', ] def blacklist(f): diff --git a/tools/isolate/trace_child_process.py b/tools/isolate/trace_child_process.py deleted file mode 100755 index d3071be..0000000 --- a/tools/isolate/trace_child_process.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Executes with the command to be run. - -Not meant to be used directly, only meant to be used by trace_inputs.py. - -This script is used by the tracer as a signal for the log parser that the child -process is the process we care about. It is especially important on kernel based -tracer because we want it to trace the relevant process tree. -""" - -import subprocess -import sys - - -def fix_python_path(cmd): - """Returns the fixed command line to call the right python executable.""" - out = cmd[:] - if out[0] == 'python': - out[0] = sys.executable - elif out[0].endswith('.py'): - out.insert(0, sys.executable) - return out - - -def main(): - cmd = fix_python_path(sys.argv[2:]) - - # The reason os.execve() is not used is that we don't want the modules - # imported here to influence the executable being traced, so we need a fresh - # pid and need to fork. - # TODO(maruel): Use CreateProcess() on Windows and fork manually on OSX. - return subprocess.call(cmd) - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tools/isolate/trace_inputs.py b/tools/isolate/trace_inputs.py index 92da755..c315d10 100755 --- a/tools/isolate/trace_inputs.py +++ b/tools/isolate/trace_inputs.py @@ -429,6 +429,19 @@ def fix_python_path(cmd): return out +def create_thunk(): + handle, name = tempfile.mkstemp(prefix='trace_inputs_thunk', suffix='.py') + os.write( + handle, + ( + 'import subprocess\n' + 'import sys\n' + 'sys.exit(subprocess.call(sys.argv[2:]))\n' + )) + os.close(handle) + return name + + def strace_process_quoted_arguments(text): """Extracts quoted arguments on a string and return the arguments as a list. @@ -1526,7 +1539,7 @@ class Dtrace(ApiBase): logging.info( '%s(%d, %s)' % (self.__class__.__name__, tracer_pid, initial_cwd)) super(Dtrace.Context, self).__init__(blacklist) - # Process ID of the trace_child_process.py wrapper script instance. + # Process ID of the temporary script created by create_thunk(). self._tracer_pid = tracer_pid self._initial_cwd = initial_cwd self._line_number = 0 @@ -1784,8 +1797,8 @@ class Dtrace(ApiBase): # 0 is for untracked processes and is the default value for items not # in the associative array. # 1 is for tracked processes. - # 2 is for trace_child_process.py only. It is not tracked itself but - # all its decendants are. + # 2 is for the script created by create_thunk() only. It is not tracked + # itself but all its decendants are. # # The script will kill itself only once waiting_to_die == 1 and # current_processes == 0, so that both getlogin() was called and that @@ -2078,7 +2091,7 @@ class Dtrace(ApiBase): this needs to wait for dtrace to be "warmed up". """ super(Dtrace.Tracer, self).__init__(logname) - self._script = os.path.join(BASE_DIR, 'trace_child_process.py') + self._script = create_thunk() # This unique dummy temp file is used to signal the dtrace script that it # should stop as soon as all the child processes are done. A bit hackish # but works fine enough. @@ -2119,8 +2132,8 @@ class Dtrace(ApiBase): Injects the cookie in the script so it knows when to stop. - The script will detect any trace_child_process.py instance and will start - tracing it. + The script will detect any instance of the script created with + create_thunk() and will start tracing it. """ return ( 'inline int PID = %d;\n' @@ -2138,8 +2151,7 @@ class Dtrace(ApiBase): This dtruss is broken when it starts the process itself or when tracing child processes, this code starts a wrapper process - trace_child_process.py, which waits for dtrace to start, then - trace_child_process.py starts the executable to trace. + generated with create_thunk() which starts the executable to trace. """ logging.info('trace(%s, %s, %s, %s)' % (cmd, cwd, tracename, output)) assert os.path.isabs(cmd[0]), cmd[0] @@ -2167,7 +2179,7 @@ class Dtrace(ApiBase): # that needs to be traced. # Yummy. child = subprocess.Popen( - child_cmd + cmd, + child_cmd + fix_python_path(cmd), stdin=subprocess.PIPE, stdout=stdout, stderr=stderr, @@ -2222,6 +2234,7 @@ class Dtrace(ApiBase): finally: os.close(self._dummy_file_id) os.remove(self._dummy_file_name) + os.remove(self._script) def post_process_log(self): """Sorts the log back in order when each call occured. @@ -2627,7 +2640,7 @@ class LogmanTrace(ApiBase): "logman query providers | findstr /i file" """ super(LogmanTrace.Tracer, self).__init__(logname) - self._script = os.path.join(BASE_DIR, 'trace_child_process.py') + self._script = create_thunk() cmd_start = [ 'logman.exe', 'start', @@ -2679,18 +2692,19 @@ class LogmanTrace(ApiBase): # Run the child process. logging.debug('Running: %s' % cmd) - # Use trace_child_process.py so we have a clear pid owner. Since - # trace_inputs.py can be used as a library and could trace mulitple - # processes simultaneously, it makes it more complex if the executable to - # be traced is executed directly here. It also solves issues related to - # logman.exe that needs to be executed to control the kernel trace. + # Use the temporary script generated with create_thunk() so we have a + # clear pid owner. Since trace_inputs.py can be used as a library and + # could trace multiple processes simultaneously, it makes it more complex + # if the executable to be traced is executed directly here. It also solves + # issues related to logman.exe that needs to be executed to control the + # kernel trace. child_cmd = [ sys.executable, self._script, tracename, ] child = subprocess.Popen( - child_cmd + cmd, + child_cmd + fix_python_path(cmd), cwd=cwd, stdin=subprocess.PIPE, stdout=stdout, @@ -2721,6 +2735,7 @@ class LogmanTrace(ApiBase): raise TracingFailure( 'Called Tracer.close() on an unitialized object', None, None, None) + os.remove(self._script) # Save metadata, add 'format' key.. data = { 'format': 'csv', |