- Revision
- 111291
- Author
- [email protected]
- Date
- 2012-03-19 18:28:48 -0700 (Mon, 19 Mar 2012)
Log Message
webkitpy: crashlog parsing is broken
https://bugs.webkit.org/show_bug.cgi?id=81586
Reviewed by Adam Barth.
Seeking on a file opened through codecs() appears to not work
correctly (at least on SL).
The code was more complicated than it needed to be, so I have
revamped it to just read a full crashlog at once and then look
for matches.
I have also added the ability to optionally propagate
errors back (which can be helpful to debug races when ReportCrash is
still running and you need to see that you couldn't open some
files, rather than just ignoring them).
* Scripts/webkitpy/common/system/crashlogs.py:
(CrashLogs.find_newest_log):
(CrashLogs._find_newest_log_darwin):
* Scripts/webkitpy/common/system/crashlogs_unittest.py:
(CrashLogsTest.test_find_log_darwin):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (111290 => 111291)
--- trunk/Tools/ChangeLog 2012-03-20 01:28:28 UTC (rev 111290)
+++ trunk/Tools/ChangeLog 2012-03-20 01:28:48 UTC (rev 111291)
@@ -1,5 +1,30 @@
2012-03-19 Dirk Pranke <[email protected]>
+ webkitpy: crashlog parsing is broken
+ https://bugs.webkit.org/show_bug.cgi?id=81586
+
+ Reviewed by Adam Barth.
+
+ Seeking on a file opened through codecs() appears to not work
+ correctly (at least on SL).
+
+ The code was more complicated than it needed to be, so I have
+ revamped it to just read a full crashlog at once and then look
+ for matches.
+
+ I have also added the ability to optionally propagate
+ errors back (which can be helpful to debug races when ReportCrash is
+ still running and you need to see that you couldn't open some
+ files, rather than just ignoring them).
+
+ * Scripts/webkitpy/common/system/crashlogs.py:
+ (CrashLogs.find_newest_log):
+ (CrashLogs._find_newest_log_darwin):
+ * Scripts/webkitpy/common/system/crashlogs_unittest.py:
+ (CrashLogsTest.test_find_log_darwin):
+
+2012-03-19 Dirk Pranke <[email protected]>
+
webkitpy: clean up some port._filesystem references to not reference private members
https://bugs.webkit.org/show_bug.cgi?id=81595
Modified: trunk/Tools/Scripts/webkitpy/common/system/crashlogs.py (111290 => 111291)
--- trunk/Tools/Scripts/webkitpy/common/system/crashlogs.py 2012-03-20 01:28:28 UTC (rev 111290)
+++ trunk/Tools/Scripts/webkitpy/common/system/crashlogs.py 2012-03-20 01:28:48 UTC (rev 111291)
@@ -35,9 +35,10 @@
def __init__(self, filesystem):
self._filesystem = filesystem
- def find_newest_log(self, process_name, pid=None):
+ def find_newest_log(self, process_name, pid=None, include_errors=False):
if sys.platform == "darwin":
- return self._find_newest_log_darwin(process_name, pid)
+ return self._find_newest_log_darwin(process_name, pid, include_errors)
+ return None
def _log_directory_darwin(self):
log_directory = self._filesystem.expanduser("~")
@@ -48,29 +49,24 @@
log_directory = self._filesystem.join(log_directory, "CrashReporter")
return log_directory
- def _find_newest_log_darwin(self, process_name, pid):
+ def _find_newest_log_darwin(self, process_name, pid, include_errors):
def is_crash_log(fs, dirpath, basename):
return basename.startswith(process_name + "_") and basename.endswith(".crash")
log_directory = self._log_directory_darwin()
logs = self._filesystem.files_under(log_directory, file_filter=is_crash_log)
- if not logs:
- return None
first_line_regex = re.compile(r'^Process:\s+(?P<process_name>.*) \[(?P<pid>\d+)\]$')
+ errors = ''
for path in reversed(sorted(logs)):
try:
- with self._filesystem.open_text_file_for_reading(path) as f:
- first_line = f.readline()
+ f = self._filesystem.read_text_file(path)
+ match = first_line_regex.match(f[0:f.find('\n')])
+ if match and match.group('process_name') == process_name and (pid is None or int(match.group('pid')) == pid):
+ return errors + f
+ except IOError, e:
+ if include_errors:
+ errors += "ERROR: Failed to read '%s': %s\n" % (path, str(e))
- match = first_line_regex.match(first_line)
- if not match:
- continue
- if match.group('process_name') != process_name:
- continue
- if pid is not None and int(match.group('pid')) != pid:
- continue
-
- f.seek(0, os.SEEK_SET)
- return f.read()
- except IOError:
- continue
+ if include_errors and errors:
+ return errors
+ return None
Modified: trunk/Tools/Scripts/webkitpy/common/system/crashlogs_unittest.py (111290 => 111291)
--- trunk/Tools/Scripts/webkitpy/common/system/crashlogs_unittest.py 2012-03-20 01:28:28 UTC (rev 111290)
+++ trunk/Tools/Scripts/webkitpy/common/system/crashlogs_unittest.py 2012-03-20 01:28:48 UTC (rev 111291)
@@ -100,3 +100,9 @@
self.assertLinesEqual(log, mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28531)
self.assertEqual(log, None)
+
+ errors = "ERROR: Failed to read '/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash': [Errno 2] /Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash: 'No such file or directory'\n"
+ log = crash_logs.find_newest_log("DumpRenderTree", 28530, include_errors=True)
+ self.assertLinesEqual(log, errors + mock_crash_report)
+ log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
+ self.assertEqual(log, errors)
Modified: trunk/Tools/Scripts/webkitpy/common/system/filesystem.py (111290 => 111291)
--- trunk/Tools/Scripts/webkitpy/common/system/filesystem.py 2012-03-20 01:28:28 UTC (rev 111290)
+++ trunk/Tools/Scripts/webkitpy/common/system/filesystem.py 2012-03-20 01:28:48 UTC (rev 111291)
@@ -201,6 +201,8 @@
f.write(contents)
def open_text_file_for_reading(self, path):
+ # Note: There appears to be an issue with the returned file objects
+ # not being seekable. See http://stackoverflow.com/questions/1510188/can-seek-and-tell-work-with-utf-8-encoded-documents-in-python .
return codecs.open(path, 'r', 'utf8')
def open_text_file_for_writing(self, path):