From 6da0550b988b5a6050e3c3e19b5e7ba48b749e39 Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Mon, 24 Jul 2017 09:31:31 +0100
Subject: [PATCH] utils/trace_cmd: expect ': ' in task name

': ' is used as the delimiter for the different parts of of the event
line; unfortunately, it is also a valid character sequence to appear in
a task name.

This change attempts to perform the event line split correctly by
ensuring that the cpu id is present in the first part.
---
 wlauto/utils/trace_cmd.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/wlauto/utils/trace_cmd.py b/wlauto/utils/trace_cmd.py
index f3301b77..2a628884 100644
--- a/wlauto/utils/trace_cmd.py
+++ b/wlauto/utils/trace_cmd.py
@@ -239,6 +239,28 @@ DROPPED_EVENTS_REGEX = re.compile(r'CPU:(?P<cpu_id>\d+) \[\d*\s*EVENTS DROPPED\]
 EMPTY_CPU_REGEX = re.compile(r'CPU \d+ is empty')
 
 
+def split_trace_event_line(line):
+    """
+    Split a trace-cmd event line into the preamble (containing the task, cpu id
+    and timestamp), the event name, and the event body. Each of these is
+    delimited by a ': ' (optionally followed by more whitespace), however ': '
+    may also appear in the body of the event and in the thread name. This
+    attempts to identify the correct split by ensureing the there is a '['
+    (used to mark the cpu id and not a valid character for a task name) in the
+    peramble.
+
+    """
+    parts = line.split(': ')
+    if len(parts) <= 3:
+        return parts
+
+    preamble = parts.pop(0)
+    while '[' not in preamble:
+        preamble += ': ' + parts.pop(0)
+    event_name = parts.pop(0)
+    return (preamble, event_name, ': '.join(parts))
+
+
 class TraceCmdTrace(object):
 
     @property
@@ -293,7 +315,7 @@ class TraceCmdTrace(object):
                         continue
 
                 # <thread/cpu/timestamp>: <event name>: <event body>
-                parts = line.split(': ', 2)
+                parts = split_trace_event_line(line)
                 if len(parts) != 3:
                     continue