diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-25 07:41:50 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-06-25 07:41:50 +0000 |
commit | e4b15714f58d993df6ec6bba7d805045f7476ca7 (patch) | |
tree | 9bd3033fa628e15bfb8c3d99575f2bccfcedc2ce | |
parent | de7adc30891ed9139fa686135c2a56f2bff60057 (diff) | |
parent | 0681f9403826ae685aec5ed6d16926146aea7049 (diff) | |
download | trappy-e4b15714f58d993df6ec6bba7d805045f7476ca7.tar.gz |
release-request-7bfcab52-d1c0-4256-9d6b-5b5092bc78ca-for-git_oc-mr1-release-4133428 snap-temp-L95800000077479875
Change-Id: Ib491fcdb8abe19e83e5f629fbd44a33c04a4f552
-rw-r--r-- | tests/test_base.py | 12 | ||||
-rw-r--r-- | tests/test_systrace.py | 41 | ||||
-rw-r--r-- | trappy/ftrace.py | 9 | ||||
-rw-r--r-- | trappy/systrace.py | 12 |
4 files changed, 62 insertions, 12 deletions
diff --git a/tests/test_base.py b/tests/test_base.py index 96b8d96..a0a4920 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -101,6 +101,7 @@ class TestBase(utils_tests.SetupDirectory): """TestBase: Task name, PID, CPU and timestamp are properly paresed """ events = { + # Trace events using [global] clock format ([us] resolution) 1001.456789 : { 'task': 'rcu_preempt', 'pid': 1123, 'cpu': 001 }, 1002.456789 : { 'task': 'rs:main', 'pid': 2123, 'cpu': 002 }, 1003.456789 : { 'task': 'AsyncTask #1', 'pid': 3123, 'cpu': 003 }, @@ -109,6 +110,15 @@ class TestBase(utils_tests.SetupDirectory): 1006.456789 : { 'task': 'IntentService[', 'pid': 6123, 'cpu': 005 }, 1006.456789 : { 'task': r'/system/bin/.s$_?.u- \a]}c\./ef[.12]*[[l]in]ger', 'pid': 1234, 'cpu': 666 }, + # Trace events using [boot] clock format ([ns] resolution) + 1011456789000: { 'task': 'rcu_preempt', 'pid': 1123, 'cpu': 001 }, + 1012456789000: { 'task': 'rs:main', 'pid': 2123, 'cpu': 002 }, + 1013456789000: { 'task': 'AsyncTask #1', 'pid': 3123, 'cpu': 003 }, + 1014456789000: { 'task': 'kworker/1:1H', 'pid': 4123, 'cpu': 004 }, + 1015456789000: { 'task': 'jbd2/sda2-8', 'pid': 5123, 'cpu': 005 }, + 1016456789000: { 'task': 'IntentService[', 'pid': 6123, 'cpu': 005 }, + 1016456789000: { 'task': r'/system/bin/.s$_?.u- \a]}c\./ef[.12]*[[l]in]ger', + 'pid': 1234, 'cpu': 666 }, } in_data = """""" @@ -133,6 +143,8 @@ class TestBase(utils_tests.SetupDirectory): self.assertEquals(set(dfr.columns), expected_columns) for timestamp, event in events.iteritems(): + if type(timestamp) == int: + timestamp = float(timestamp) / 1e9 self.assertEquals(dfr["__comm"].loc[timestamp], event['task']) self.assertEquals(dfr["__pid"].loc[timestamp], event['pid']) self.assertEquals(dfr["__cpu"].loc[timestamp], event['cpu']) diff --git a/tests/test_systrace.py b/tests/test_systrace.py index 0442458..667bf2c 100644 --- a/tests/test_systrace.py +++ b/tests/test_systrace.py @@ -17,6 +17,8 @@ import utils_tests import trappy +import numpy as np + class TestSystrace(utils_tests.SetupDirectory): def __init__(self, *args, **kwargs): @@ -55,14 +57,41 @@ class TestSystrace(utils_tests.SetupDirectory): def test_systrace_userspace(self): """Test parsing of userspace events""" + # Test a 'B' event (begin) trace = trappy.SysTrace("trace_sf.html") dfr = trace.tracing_mark_write.data_frame - self.assertTrue(dfr['__pid'].iloc[2], 7459) - self.assertTrue(dfr['__comm'].iloc[2], 'RenderThread') - self.assertTrue(dfr['pid'].iloc[2], 7459) - self.assertTrue(dfr['event'].iloc[2], 'B') - self.assertTrue(dfr['func'].iloc[2], 'notifyFramePending') - self.assertTrue(dfr['data'].iloc[-2], 'HW_VSYNC_0') + self.assertEquals(dfr['__pid'].iloc[2], 7591) + self.assertEquals(dfr['__comm'].iloc[2], 'RenderThread') + self.assertEquals(dfr['pid'].iloc[2], 7459) + self.assertEquals(dfr['event'].iloc[2], 'B') + self.assertEquals(dfr['func'].iloc[2], 'notifyFramePending') + self.assertEquals(dfr['data'].iloc[2], None) + + # Test a 'C' event (count) + self.assertEquals(dfr['__pid'].iloc[-2], 612) + self.assertEquals(dfr['__comm'].iloc[-2], 'HwBinder:594_1') + self.assertEquals(dfr['pid'].iloc[-2], 594) + self.assertEquals(dfr['func'].iloc[-2], 'HW_VSYNC_0') + self.assertEquals(dfr['event'].iloc[-2], 'C') + self.assertEquals(dfr['data'].iloc[-2], '0') + + # Test an 'E' event (end) + edfr = dfr[dfr['event'] == 'E'] + self.assertEquals(edfr['__pid'].iloc[0], 7591) + self.assertEquals(edfr['__comm'].iloc[0], 'RenderThread') + self.assertTrue(np.isnan(edfr['pid'].iloc[0])) + self.assertEquals(edfr['func'].iloc[0], None) + self.assertEquals(edfr['event'].iloc[0], 'E') + self.assertEquals(edfr['data'].iloc[0], None) + + def test_systrace_line_num(self): + """Test for line numbers in a systrace""" + trace = trappy.SysTrace("trace_sf.html") + dfr = trace.sched_switch.data_frame + self.assertEquals(trace.lines, 2506) + self.assertEquals(dfr['__line'].iloc[0], 0) + self.assertEquals(dfr['__line'].iloc[1], 6) + self.assertEquals(dfr['__line'].iloc[-1], 2505) class TestLegacySystrace(utils_tests.SetupDirectory): diff --git a/trappy/ftrace.py b/trappy/ftrace.py index cd4d8e2..6a31ec3 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -49,7 +49,7 @@ def _plot_freq_hists(allfreqs, what, axis, title): SPECIAL_FIELDS_RE = re.compile( r"^\s*(?P<comm>.*)-(?P<pid>\d+)(?:\s+\(.*\))"\ r"?\s+\[(?P<cpu>\d+)\](?:\s+....)?\s+"\ - r"(?P<timestamp>[0-9]+\.[0-9]+): (\w+:\s+)+(?P<data>.+)" + r"(?P<timestamp>[0-9]+(?P<us>\.[0-9]+)?): (\w+:\s+)+(?P<data>.+)" ) class GenericFTrace(BareTrace): @@ -199,7 +199,14 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" comm = fields_match.group('comm') pid = int(fields_match.group('pid')) cpu = int(fields_match.group('cpu')) + + # The timestamp, depending on the trace_clock configuration, can be + # reported either in [s].[us] or [ns] format. Let's ensure that we + # always generate DF which have the index expressed in: + # [s].[decimals] timestamp = float(fields_match.group('timestamp')) + if not fields_match.group('us'): + timestamp /= 1e9 data_str = fields_match.group('data') if not self.basetime: diff --git a/trappy/systrace.py b/trappy/systrace.py index 0a7f42b..2404f92 100644 --- a/trappy/systrace.py +++ b/trappy/systrace.py @@ -17,7 +17,7 @@ from trappy.ftrace import GenericFTrace import re SYSTRACE_EVENT = re.compile( - r'^(?P<event>[A-Z])(\|(?P<pid>\d+)\|(?P<func>.*)(\|(?P<data>\d+))?)?') + r'^(?P<event>[A-Z])(\|(?P<pid>\d+)\|(?P<func>[^|]*)(\|(?P<data>.*))?)?') class drop_before_trace(object): """Object that, when called, returns True if the line is not part of @@ -88,9 +88,11 @@ class SysTrace(GenericFTrace): match = SYSTRACE_EVENT.match(data_str) if match: - data_dict = { 'event': match.group('event'), - 'pid' : match.group('pid'), - 'func' : match.group('func'), - 'data' : match.group('data') } + data_dict = { + 'event': match.group('event'), + 'pid' : int(match.group('pid')) if match.group('pid') else None, + 'func' : match.group('func' ), + 'data' : match.group('data' ) + } return data_dict |