From b1b1c9ec6deb6cb879c683f7ddaebb98d2f016ac Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Wed, 3 May 2017 12:45:43 +0100 Subject: ftrace: Improve error messages when failing to parse trace --- tests/test_ftrace.py | 9 +++++++++ trappy/ftrace.py | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/test_ftrace.py b/tests/test_ftrace.py index a912ff7..389d31f 100644 --- a/tests/test_ftrace.py +++ b/tests/test_ftrace.py @@ -420,6 +420,15 @@ class TestFTraceSched(utils_tests.SetupDirectory): self.assertEqual(trace.basetime, 0) + def test_ftrace_unique_but_no_fields(self): + """Test with a matching unique but no special fields""" + version_parser = trappy.register_dynamic_ftrace("Version", "version") + + with self.assertRaises(ValueError): + trappy.FTrace(scope="custom") + + trappy.unregister_dynamic_ftrace(version_parser) + def test_ftrace_normalize_some_tracepoints(self): """Test that normalizing time works if not all the tracepoints are in the trace""" diff --git a/trappy/ftrace.py b/trappy/ftrace.py index 6a5fce0..dd0a2fc 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -25,6 +25,9 @@ import pandas as pd from trappy.bare_trace import BareTrace from trappy.utils import listify +class FTraceParseError(Exception): + pass + def _plot_freq_hists(allfreqs, what, axis, title): """Helper function for plot_freq_hists @@ -181,11 +184,13 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" trace_class = cls break else: - raise ValueError("No unique in {}".format(line)) + raise FTraceParseError("No unique word in '{}'".format(line)) line = line[:-1] special_fields_match = special_fields_regexp.match(line) + if not special_fields_match: + raise FTraceParseError("Couldn't match special fields in '{}'".format(line)) comm = special_fields_match.group('comm') pid = int(special_fields_match.group('pid')) cpu = int(special_fields_match.group('cpu')) @@ -262,8 +267,13 @@ is part of the trace. if len(cls_for_unique_word) == 0: return - with open(trace_file) as fin: - self.__populate_data(fin, cls_for_unique_word, window, abs_window) + try: + with open(trace_file) as fin: + self.__populate_data( + fin, cls_for_unique_word, window, abs_window) + except FTraceParseError as e: + raise ValueError('Failed to parse ftrace file {}:\n{}'.format( + trace_file, str(e))) # TODO: Move thermal specific functionality -- cgit v1.2.3