| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # memcheck_analyze.py | 6 # memcheck_analyze.py |
| 7 | 7 |
| 8 ''' Given a valgrind XML file, parses errors and uniques them.''' | 8 ''' Given a valgrind XML file, parses errors and uniques them.''' |
| 9 | 9 |
| 10 import gdb_helper | 10 import gdb_helper |
| 11 | 11 |
| 12 import logging | 12 import logging |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import re |
| 15 import subprocess | 16 import subprocess |
| 16 import sys | 17 import sys |
| 17 import time | 18 import time |
| 18 from xml.dom.minidom import parse | 19 from xml.dom.minidom import parse |
| 19 from xml.parsers.expat import ExpatError | 20 from xml.parsers.expat import ExpatError |
| 20 | 21 |
| 21 # Global symbol table (yuck) | 22 # Global symbol table (yuck) |
| 22 TheAddressTable = None | 23 TheAddressTable = None |
| 23 | 24 |
| 24 | 25 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 TheAddressTable = gdb_helper.AddressTable() | 362 TheAddressTable = gdb_helper.AddressTable() |
| 362 self._errors = set() | 363 self._errors = set() |
| 363 self._suppcounts = {} | 364 self._suppcounts = {} |
| 364 badfiles = set() | 365 badfiles = set() |
| 365 start = time.time() | 366 start = time.time() |
| 366 self._parse_failed = False | 367 self._parse_failed = False |
| 367 for file in files: | 368 for file in files: |
| 368 # Wait up to three minutes for valgrind to finish writing all files, | 369 # Wait up to three minutes for valgrind to finish writing all files, |
| 369 # but after that, just skip incomplete files and warn. | 370 # but after that, just skip incomplete files and warn. |
| 370 f = open(file, "r+") | 371 f = open(file, "r+") |
| 372 pid = re.match(".*\.([0-9]+)$", file) |
| 373 if pid: |
| 374 pid = pid.groups()[0] |
| 371 found = False | 375 found = False |
| 376 running = True |
| 372 firstrun = True | 377 firstrun = True |
| 373 origsize = os.path.getsize(file) | 378 origsize = os.path.getsize(file) |
| 374 while (not found and (firstrun or ((time.time() - start) < 180.0))): | 379 while (running and not found and |
| 380 (firstrun or ((time.time() - start) < 180.0))): |
| 375 firstrun = False | 381 firstrun = False |
| 376 f.seek(0) | 382 f.seek(0) |
| 383 if pid: |
| 384 # Make sure the process is still running so we don't wait for |
| 385 # 3 minutes if it was killed. See http://crbug.com/17453 |
| 386 ps_out = subprocess.Popen("ps p %s" % pid, shell=True, |
| 387 stdout=subprocess.PIPE).stdout |
| 388 if ps_out.readlines() < 2: |
| 389 running = False |
| 377 found = find_and_truncate(f) | 390 found = find_and_truncate(f) |
| 378 if not found: | 391 if not running and not found: |
| 392 logging.warn("Valgrind process PID = %s is not running but " |
| 393 "its XML log has not been finished correctly" % pid) |
| 394 if running and not found: |
| 379 time.sleep(1) | 395 time.sleep(1) |
| 380 f.close() | 396 f.close() |
| 381 if not found: | 397 if not found: |
| 382 badfiles.add(file) | 398 badfiles.add(file) |
| 383 else: | 399 else: |
| 384 newsize = os.path.getsize(file) | 400 newsize = os.path.getsize(file) |
| 385 if origsize > newsize+1: | 401 if origsize > newsize+1: |
| 386 logging.warn(str(origsize - newsize) + " bytes of junk were after </va
lgrindoutput> in %s!" % file) | 402 logging.warn(str(origsize - newsize) + " bytes of junk were after </va
lgrindoutput> in %s!" % file) |
| 387 try: | 403 try: |
| 388 parsed_file = parse(file); | 404 parsed_file = parse(file); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 parser.error("no filename specified") | 520 parser.error("no filename specified") |
| 505 filenames = args | 521 filenames = args |
| 506 | 522 |
| 507 analyzer = MemcheckAnalyze(options.source_dir, filenames, use_gdb=True) | 523 analyzer = MemcheckAnalyze(options.source_dir, filenames, use_gdb=True) |
| 508 retcode = analyzer.Report() | 524 retcode = analyzer.Report() |
| 509 | 525 |
| 510 sys.exit(retcode) | 526 sys.exit(retcode) |
| 511 | 527 |
| 512 if __name__ == "__main__": | 528 if __name__ == "__main__": |
| 513 _main() | 529 _main() |
| OLD | NEW |