summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/common/system/crashlogs.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system/crashlogs.py')
-rw-r--r--Tools/Scripts/webkitpy/common/system/crashlogs.py57
1 files changed, 26 insertions, 31 deletions
diff --git a/Tools/Scripts/webkitpy/common/system/crashlogs.py b/Tools/Scripts/webkitpy/common/system/crashlogs.py
index a6b6575f6..0dd37d255 100644
--- a/Tools/Scripts/webkitpy/common/system/crashlogs.py
+++ b/Tools/Scripts/webkitpy/common/system/crashlogs.py
@@ -26,51 +26,46 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import os
import re
-import sys
class CrashLogs(object):
- def __init__(self, filesystem):
- self._filesystem = filesystem
+ def __init__(self, host):
+ self._host = host
- def find_newest_log(self, process_name, pid=None):
- if sys.platform == "darwin":
- return self._find_newest_log_darwin(process_name, pid)
+ def find_newest_log(self, process_name, pid=None, include_errors=False, newer_than=None):
+ if self._host.platform.is_mac():
+ return self._find_newest_log_darwin(process_name, pid, include_errors, newer_than)
+ return None
def _log_directory_darwin(self):
- log_directory = self._filesystem.expanduser("~")
- log_directory = self._filesystem.join(log_directory, "Library", "Logs")
- if self._filesystem.exists(self._filesystem.join(log_directory, "DiagnosticReports")):
- log_directory = self._filesystem.join(log_directory, "DiagnosticReports")
+ log_directory = self._host.filesystem.expanduser("~")
+ log_directory = self._host.filesystem.join(log_directory, "Library", "Logs")
+ if self._host.filesystem.exists(self._host.filesystem.join(log_directory, "DiagnosticReports")):
+ log_directory = self._host.filesystem.join(log_directory, "DiagnosticReports")
else:
- log_directory = self._filesystem.join(log_directory, "CrashReporter")
+ log_directory = self._host.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, newer_than):
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
+ logs = self._host.filesystem.files_under(log_directory, file_filter=is_crash_log)
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()
+ if not newer_than or self._host.filesystem.mtime(path) > newer_than:
+ try:
+ f = self._host.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