aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fernandes <joelaf@google.com>2017-06-23 18:35:15 -0700
committerJoel Fernandes <joelaf@google.com>2017-06-23 18:35:15 -0700
commit0681f9403826ae685aec5ed6d16926146aea7049 (patch)
tree9bd3033fa628e15bfb8c3d99575f2bccfcedc2ce
parent2b9b25c74416328a0f68af5b60b73534e4ccbd02 (diff)
parent3b9f139fdcdb086e7ac8314a4beb3441a0b1418c (diff)
downloadtrappy-0681f9403826ae685aec5ed6d16926146aea7049.tar.gz
Merge remote-tracking branch 'origin/master' into HEAD
-rw-r--r--tests/test_base.py12
-rw-r--r--tests/test_systrace.py41
-rw-r--r--trappy/ftrace.py9
-rw-r--r--trappy/systrace.py12
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