Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Runs strace or dtrace on a test and processes the logs to extract the | 7 """Runs strace or dtrace on a test and processes the logs to extract the |
| 8 dependencies from the source tree. | 8 dependencies from the source tree. |
| 9 | 9 |
| 10 Automatically extracts directories where all the files are used to make the | 10 Automatically extracts directories where all the files are used to make the |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 logging.debug( | 382 logging.debug( |
| 383 '_handle_file(%d, %s) -> %s' % (pid, old_filepath, filepath)) | 383 '_handle_file(%d, %s) -> %s' % (pid, old_filepath, filepath)) |
| 384 else: | 384 else: |
| 385 logging.debug('_handle_file(%d, %s)' % (pid, filepath)) | 385 logging.debug('_handle_file(%d, %s)' % (pid, filepath)) |
| 386 if filepath not in self.files and filepath not in self.non_existent: | 386 if filepath not in self.files and filepath not in self.non_existent: |
| 387 if os.path.isfile(filepath): | 387 if os.path.isfile(filepath): |
| 388 self.files.add(filepath) | 388 self.files.add(filepath) |
| 389 else: | 389 else: |
| 390 self.non_existent.add(filepath) | 390 self.non_existent.add(filepath) |
| 391 | 391 |
| 392 @staticmethod | |
| 393 def clean_trace(logname): | |
| 394 """Deletes the old log.""" | |
| 395 if os.path.isfile(logname): | |
| 396 os.remove(logname) | |
|
MAD
2012/05/11 18:51:38
Shouldn't we try to catch these?
"On Windows, att
M-A Ruel
2012/05/11 18:57:25
I prefer the script to crash if the files can't be
| |
| 397 | |
| 392 @classmethod | 398 @classmethod |
| 393 def gen_trace(cls, cmd, cwd, logname, output): | 399 def gen_trace(cls, cmd, cwd, logname, output): |
| 394 """Runs strace on an executable.""" | 400 """Runs strace on an executable.""" |
| 395 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) | 401 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) |
| 396 stdout = stderr = None | 402 stdout = stderr = None |
| 397 if output: | 403 if output: |
| 398 stdout = subprocess.PIPE | 404 stdout = subprocess.PIPE |
| 399 stderr = subprocess.STDOUT | 405 stderr = subprocess.STDOUT |
| 400 traces = ','.join(cls.Context.traces()) | 406 traces = ','.join(cls.Context.traces()) |
| 401 trace_cmd = ['strace', '-f', '-e', 'trace=%s' % traces, '-o', logname] | 407 trace_cmd = ['strace', '-f', '-e', 'trace=%s' % traces, '-o', logname] |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 logging.debug('_handle_file(%d, %s)' % (pid, filepath)) | 698 logging.debug('_handle_file(%d, %s)' % (pid, filepath)) |
| 693 if os.path.isfile(filepath): | 699 if os.path.isfile(filepath): |
| 694 self.files.add(filepath) | 700 self.files.add(filepath) |
| 695 else: | 701 else: |
| 696 self.non_existent.add(filepath) | 702 self.non_existent.add(filepath) |
| 697 | 703 |
| 698 @staticmethod | 704 @staticmethod |
| 699 def _handle_ignored(_ppid, pid, function, args, result): | 705 def _handle_ignored(_ppid, pid, function, args, result): |
| 700 logging.debug('%d %s(%s) = %s' % (pid, function, args, result)) | 706 logging.debug('%d %s(%s) = %s' % (pid, function, args, result)) |
| 701 | 707 |
| 708 @staticmethod | |
| 709 def clean_trace(logname): | |
| 710 """Deletes the old log.""" | |
| 711 if os.path.isfile(logname): | |
| 712 os.remove(logname) | |
| 713 | |
| 702 @classmethod | 714 @classmethod |
| 703 def gen_trace(cls, cmd, cwd, logname, output): | 715 def gen_trace(cls, cmd, cwd, logname, output): |
| 704 """Runs dtrace on an executable.""" | 716 """Runs dtrace on an executable.""" |
| 705 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) | 717 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) |
| 706 logging.info('Running: %s' % cmd) | 718 logging.info('Running: %s' % cmd) |
| 707 signal = 'Go!' | 719 signal = 'Go!' |
| 708 logging.debug('Our pid: %d' % os.getpid()) | 720 logging.debug('Our pid: %d' % os.getpid()) |
| 709 | 721 |
| 710 # Part 1: start the child process. | 722 # Part 1: start the child process. |
| 711 stdout = stderr = None | 723 stdout = stderr = None |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 self.IGNORED.add(os.environ[i]) | 1018 self.IGNORED.add(os.environ[i]) |
| 1007 | 1019 |
| 1008 # Also add their short path name equivalents. | 1020 # Also add their short path name equivalents. |
| 1009 for i in list(self.IGNORED): | 1021 for i in list(self.IGNORED): |
| 1010 self.IGNORED.add(GetShortPathName(i)) | 1022 self.IGNORED.add(GetShortPathName(i)) |
| 1011 | 1023 |
| 1012 # Add this one last since it has no short path name equivalent. | 1024 # Add this one last since it has no short path name equivalent. |
| 1013 self.IGNORED.add('\\systemroot') | 1025 self.IGNORED.add('\\systemroot') |
| 1014 self.IGNORED = tuple(sorted(self.IGNORED)) | 1026 self.IGNORED = tuple(sorted(self.IGNORED)) |
| 1015 | 1027 |
| 1028 @staticmethod | |
| 1029 def clean_trace(logname): | |
| 1030 """Deletes the old log.""" | |
| 1031 if os.path.isfile(logname): | |
| 1032 os.remove(logname) | |
| 1033 if os.path.isfile(logname + '.etl'): | |
| 1034 os.remove(logname + '.etl') | |
| 1035 | |
| 1016 @classmethod | 1036 @classmethod |
| 1017 def gen_trace(cls, cmd, cwd, logname, output): | 1037 def gen_trace(cls, cmd, cwd, logname, output): |
| 1018 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) | 1038 logging.info('gen_trace(%s, %s, %s, %s)' % (cmd, cwd, logname, output)) |
| 1019 # Use "logman -?" for help. | 1039 # Use "logman -?" for help. |
| 1020 | 1040 |
| 1021 etl = logname + '.etl' | 1041 etl = logname + '.etl' |
| 1022 | 1042 |
| 1023 stdout = stderr = None | 1043 stdout = stderr = None |
| 1024 if output: | 1044 if output: |
| 1025 stdout = subprocess.PIPE | 1045 stdout = subprocess.PIPE |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1331 | 1351 |
| 1332 Arguments: | 1352 Arguments: |
| 1333 - logfile: file to write to. | 1353 - logfile: file to write to. |
| 1334 - cmd: command to run. | 1354 - cmd: command to run. |
| 1335 - cwd: current directory to start the process in. | 1355 - cwd: current directory to start the process in. |
| 1336 - api: a tracing api instance. | 1356 - api: a tracing api instance. |
| 1337 - output: if True, returns output, otherwise prints it at the console. | 1357 - output: if True, returns output, otherwise prints it at the console. |
| 1338 """ | 1358 """ |
| 1339 cmd = fix_python_path(cmd) | 1359 cmd = fix_python_path(cmd) |
| 1340 assert os.path.isabs(cmd[0]), cmd[0] | 1360 assert os.path.isabs(cmd[0]), cmd[0] |
| 1341 if os.path.isfile(logfile): | 1361 api.clean_trace(logfile) |
| 1342 os.remove(logfile) | |
| 1343 return api.gen_trace(cmd, cwd, logfile, output) | 1362 return api.gen_trace(cmd, cwd, logfile, output) |
| 1344 | 1363 |
| 1345 | 1364 |
| 1346 def load_trace(logfile, root_dir, api): | 1365 def load_trace(logfile, root_dir, api): |
| 1347 """Loads a trace file and returns the processed file lists. | 1366 """Loads a trace file and returns the processed file lists. |
| 1348 | 1367 |
| 1349 Arguments: | 1368 Arguments: |
| 1350 - logfile: file to load. | 1369 - logfile: file to load. |
| 1351 - root_dir: root directory to use to determine if a file is relevant to the | 1370 - root_dir: root directory to use to determine if a file is relevant to the |
| 1352 trace or not. | 1371 trace or not. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1478 os.path.abspath(options.log), | 1497 os.path.abspath(options.log), |
| 1479 args, | 1498 args, |
| 1480 options.root_dir, | 1499 options.root_dir, |
| 1481 options.cwd, | 1500 options.cwd, |
| 1482 options.product_dir, | 1501 options.product_dir, |
| 1483 options.force) | 1502 options.force) |
| 1484 | 1503 |
| 1485 | 1504 |
| 1486 if __name__ == '__main__': | 1505 if __name__ == '__main__': |
| 1487 sys.exit(main()) | 1506 sys.exit(main()) |
| OLD | NEW |